-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPHOTORESISTORS.ino
More file actions
102 lines (82 loc) · 1.98 KB
/
Copy pathPHOTORESISTORS.ino
File metadata and controls
102 lines (82 loc) · 1.98 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//PHOTORESISTORS
const int ldrpin = A0;
//LED
const int LED = 13;
//MOTOR
const int ENA = 7;
const int In1 = 8;
const int In2 = 9;
int SPEED = 100; // scale is 0 to 255
void setup() {
Serial.begin(9600); //Begin serial communcation
//initialize LDRs and LED
pinMode(ldrpin, INPUT);
pinMode(LED,OUTPUT);
//initialize MOTOR
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
Serial.print("HELLO");
Serial.print('\n');
float ldrstat= analogRead(ldrpin);
delay(10);
Serial.print(ldrstat, DEC);
Serial.print('\n');
if (ldrstat > 2.3) {
//move right
digitalWrite(LED,HIGH);
}
else if (ldrstat > 2.7 || ldrstat < 5){
//move to the left
digitalWrite(LED,HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
else {
digitalWrite(LED, LOW);
}
delay(500);
}
On Thu, Dec 6, 2018 at 2:02 PM Irene Duran <iduran@mail.csuchico.edu> wrote:
//PHOTORESISTORS
const int ldrpin = A0;
//LED
const int LED = 13;
//MOTOR
const int ENA = 7;
const int In1 = 8;
const int In2 = 9;
int SPEED = 100; // scale is 0 to 255
void setup() {
Serial.begin(9600); //Begin serial communcation
//initialize LDRs and LED
pinMode(ldrpin, INPUT);
pinMode(LED,OUTPUT);
//initialize MOTOR
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
float ldrstat= analogRead(ldrpin);
delay(10);
Serial.print(ldrstat, DEC);
if (ldrstat > 2.3) {
//move right
digitalWrite(LED,HIGH);
}
else if (ldrstat > 2.7 || ldrstat < 5){
//move to the left
digitalWrite(LED,HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
}
else {
digitalWrite(LED, LOW);
}
delay(500);
}