Arduino eksperiment id

Ovaj forum je napravljen na osnovu tutoriala na Youtube kanalu Elektro024. Ovde možete postaviti vaše pitanje, odrađene domeće zadatke i sve što je vezano za Arduino tutorial.
Pravila foruma
Ovaj forum je napravljen na osnovu tutoriala na Youtube kanalu Elektro024. Ovde možete postaviti vaše pitanje, odrađene domeće zadatke i sve što je vezano za Arduino tutorial.
Molim sve članove foruma da u ovu temu Vaše pitanje u ovom forumu postavite samo onda ako ima veze sa tutorialom Arduino Projects
Odgovori
Message
Autoru
tajmer
Početnik
Postovi: 3
Pridružio se: Pon Nov 13, 2017 7:50 pm

Arduino eksperiment id

#1 Post od tajmer » Sub Nov 25, 2017 6:42 pm

Imam napisan kod za arduino uno ali nesto nedostaje kako da na sensorima A 0 A 1 stvorim to jest napisem rutinu da umesto nula napona ulazni bude 2,5v u ovom slucaju cim stavim izlaze na A0 i A1 sensore LCD dobija previsok napon i nema nule vec odmah skace quarter na 90 i vco ton je konstantan ? Zamolio bih Elektra 024 da barem pogleda o cemu se radi !



#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // assign liquid crystal pins
int backLight = 13; // pin 13 will control the backlight
// Sensors
int sensorPinx = A0; // Intialize analog pin A0 and name it "sensorPinx" for the all metal channel
int sensorPinr = A1; // Intialize analog pin A1 and name it "sensorPinr" for the all disc channel
//Variables
float sensorValuex = 0; // assign a floating point value of "0" to a variable called "sensorValuex"
float sensorValuer = 0; // assign a floating point value of "0" to a variable called "sensorValuer"
float slope; // assign a floating point value of "0" to a variable called "slope"
float slopeNeg; // assign a floating point value of "0" to a variable called "slope"
int n = 0; // assign an integer value of "0" to a variable called "n"
int cursorClmn = 0; // assign an integer value of "0" to a variable called "cursorClmn"
int numSamples = 0; // assign an integer value of "0" to a variable called "numsamples"
float slopeTotals; // assign an integer value of "0" to a variabel called "slopeTotals"
float slopeNegTotals; // assign an integer value of "0" to a variabel called "slopeTotals"
float slopeAve = 0; // assign an integer value of "0" to a variable called "slopeAve"
float slopeNegAve = 0; // assign an integer value of "0" to a variable called "slopeAve"
int VDI = 0; // assign an integer value of "0" to a variable called "VDI"
int VDIneg = 0; // assign an integer value of "0" to a variable called "VDI"


// program setup follows
void setup()
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print( "VDI_Experiment_3"); // print whatever you want
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print( " Geotech" ); // print whatever you want
delay (2000); // wait 1 second
lcd.clear(); // Clear the LCD
}


// The main loop follows
void loop()
{
first: //This is a label called "first" so a goto statement can find the beginning of the loop when called
sensorValuex = analogRead (sensorPinx); //Read the analog pin A0 and store it's value as sensorValuex (it will be between 0 and 1023)
sensorValuer = analogRead (sensorPinr); //Read the analog pin A1 and store it's value as sensorValuer (it will be between 0 and 1023)
//Change SensorValues below to adjust VDI sensitivity
if (sensorValuex > 5) { //If this sensorvalue becomes > 5 it executes the next line. If not, it drops to the "else" statement and goes to the beginning again ("first")
if (sensorValuer > 5) { //If this sensorvalue becomes > 5 it executes the next line. If not, it drops to the "else" statement and goes to the beginning again ("first")
for (int n = 0 ; n < 85 ; n ++) //Starts a counter to read the sensors again in a loop 85 times
reread: //A label called reread will check sensors again if a floating point calulation is bad {0 value)
{
sensorValuex = analogRead(sensorPinx); //Read the analog pin A0 and store it's value as sensorValuex (it will be between 0 and 1023)
sensorValuer = analogRead (sensorPinr); //Read the analog pin A1 and store it's value as sensorValuer (it will be between 0 and 1023)

slope = sensorValuer / sensorValuex; // calculate X/R ratio and call it "slope"
if (slope ==0) {
goto reread;
}
slopeNeg = sensorValuex / sensorValuer; // calculate R/X ratio and call it "slopeNeg Ferrous"

slopeTotals = slopeTotals + slope;
slopeNegTotals = slopeNegTotals + slopeNeg;
}
}
}
else {
goto first; // runs a loop until the sensors become low again
}

slopeAve = slopeTotals/85; // take all the slope values and average them.
slopeNegAve = slopeNegTotals/85; // take all the slope values and average them.

VDI = ((10 - slopeAve) * 10);
VDIneg = ((10 - slopeNegAve) * 10);
// you can manipulate the range of how your VDI numbers are calulated by changing the line below

cursorClmn = (10 - slopeAve); // slopeAve will typically be between .1 and 9. It just converts it to an integer number between 1 and 10.. used to position the "*" character
tone (8 , (cursorClmn * 200), 100); // produces a tone of 200 Hz X the mumber above for 100 mS
lcd.clear(); //clear LCD

if (VDI > 98 ) {
lcd.clear();
goto finish;
}

lcd.setCursor(0,0); //Set cursor on line 0, column 0
lcd.print("VDI = "); // print "VDI ="
lcd.print (VDI) ; // prints the calculated number following "VDI ="
lcd.setCursor(9,0);

// if (VDI = 100 ); {
// lcd.clear();
// goto finish;
// }

if ( VDI > 89 ) {
lcd.print("Dollar");
goto DonePrinting;
}
if ( VDI > 85 ) {
// 00,29 =
lcd.print("Quarter");
goto DonePrinting;
}
if ( VDI > 80 ) {
// 01,29 =
lcd.print ("Dime");
goto DonePrinting;
}
if ( VDI > 71) {
lcd.print ("Penny");
goto DonePrinting;
}
if (VDI > 70) {
lcd.print ("Zinc");
goto DonePrinting;
}
if (VDI > 65) {
goto DonePrinting;
}
if (VDI >= 57 && VDI <= 62) {
lcd.print ("Brittisk Lb");
goto DonePrinting;
}
if (VDI > 40 && VDI <= 49) {
lcd.print ("Aluminum");
goto DonePrinting;
}
if (VDI >= 50 && VDI <= 50) {
lcd.print ("Midevl Fr Coin");
goto DonePrinting;
}
if (VDI >= 48 && VDI <= 56) {
lcd.print ("Euro 1 Coin");
goto DonePrinting;
}
if (VDI > 47) {
goto DonePrinting;
}
if (VDI >= 45 && VDI <= 46) {
lcd.print ("British 20p");
goto DonePrinting;
}
if (VDI >= 43 && VDI <= 47) {
lcd.print ("Euro 2 Coin");
goto DonePrinting;
}
if (VDI > 39) {
// 10,06 =
lcd.print ("Nickel");
goto DonePrinting;
}
if (VDI > 30) {
goto DonePrinting;
}
if (VDI > 10) {
// 10,06 =
// lcd.print ("Salt");
lcd.print ("Foil");
goto DonePrinting;
}
if (VDI > 0) {
lcd.setCursor (10,0);
// 11,02 =
// lcd.print ("Foil");
lcd.print ("Salt");
goto DonePrinting;
}

/*
-0 :Iron
20-29 :Foil
21 Merovingian Triens (gold, France)
27 Celtic Potin (Copper+Lead)
30-39 :Nickel
34-36 Russian Scale Peter I, 1705, Silver, 0.25 gr.
34-36 US Nickel
40-55 :Aluminum Pulltab
40 Roman Nummus (bronze)
43-47 2 Euro Coi
45-46 British 20p
46 USSR, 5 kopeek, 1961, Bronze, D 25 mm
47-49 Bulgarian 1 lev
48-56 1 Euro Coin
50-59 :Zinc
50 Medieval double sol coin (France)
57-62 British 1Lb
52 2-1/2 Gold
56 3c Silver
58 5$ Gold
60-69 :Dime
60-69 Aluminum Screw Cap
63-68 Soda Can
61 Half Dime
62 $10 Gold
63 2c Shield
64-66 US Dime
68 Canadian 1c
70-79 :Quarter
75-76 Polish Zloty (Pre-WWII) 2zl (1933 silver)
74-77 US Quarter
80-89 :Half Dollar
81-85 Silver Quarter
86-89 Silver Half Dollar
90-99 :Silver Doller
90 Old US Dollar
90-92 US Silver Dollar
97-98 Russian, 1 ruble Nikolay II,1896, Silver, D 34 mm
99 Hot Rocks
*/

if (VDIneg > 40) {
lcd.print ("Nail");
goto DonePrinting;
}

if (VDIneg > 89) {
lcd.print ("GndBal/NormSoil");
goto DonePrinting;
}


DonePrinting:
lcd.setCursor(cursorClmn,1); // Positions the cursor on a particular column on row 1
lcd.print ("*"); // prints the "*" character in that partular column
finish:
delay (100); // display the VDI numbers for 100 mS before going to the beginning of the code again
numSamples = 0; // reset all numbers back to "0"
slopeTotals = 0;
slopeAve = 0;
slope = 0;
slopeNegTotals = 0;
slopeNegAve = 0;
slopeNeg = 0;
}

tajmer
Početnik
Postovi: 3
Pridružio se: Pon Nov 13, 2017 7:50 pm

Re: Arduino eksperiment id

#2 Post od tajmer » Ned Nov 26, 2017 1:56 pm

HVALA ! :o :D

Odgovori

Ko je OnLine

Korisnika u ovom forumu: Nema registrovanih korisnika i 1 gost