-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduinosloartracker.ino
58 lines (36 loc) · 1.04 KB
/
arduinosloartracker.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define I1 5 // Control pin 1 for motor 1
#define I2 6 // Control pin 2 for motor 1
void setup() {
//set the pin mode for the motor to be an output
pinMode(I1, OUTPUT);
pinMode(I2, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor
int sensorValue1 = analogRead(A3);
int sensorValue2 = analogRead(A2);
// Convert the analog value into voltage
int volt1=sensorValue1;
int volt2=sensorValue2;
if ((volt1 > (volt2+40)) && (volt1 > 550)){
analogWrite(I1, 0);
analogWrite(I2, 120);
}
if (((volt2+20) > volt1) && (volt2 > 550)){
analogWrite(I1, 120);
analogWrite(I2, 0);
}
// if ( ((volt1-volt2) > 600) || ((volt2-volt1) > 600) ) {
// analogWrite(I1, 0);
// analogWrite(I2, 0);
// }
//print voltages
Serial.print("sensorValue1: ");
Serial.print(volt1);
Serial.print(" sensorValue2: ");
Serial.println(volt2);
delay (100);
analogWrite(I1, 0);
analogWrite(I2, 0);
}