-
Notifications
You must be signed in to change notification settings - Fork 5
/
colour sensor
59 lines (45 loc) · 1.19 KB
/
colour sensor
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
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
int red,green= 0;
void setup() {
//Setting up LED
lcd.begin(16, 2);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
Serial.begin(9600);
}
void loop() {
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
red= pulseIn(sensorOut, LOW);
delay(100);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
green = pulseIn(sensorOut, LOW);
delay(100);
//adjust the values accordingly
if (red > 12 && red < 30 && grn > 40 && grn < 70 && blu > 33 && blu < 70)
{ color = "RED";
lcd.print("Stop");
//enter function to stop the bot
}
else if (red > 50 && red < 95 && grn > 35 && grn < 70 && blu > 45 && blu < 85)
{ color = "GREEN";
lcd.print("GO");
//enter function to move the bot
}
}