-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreet_light_using_sensor.ino
114 lines (97 loc) · 2.21 KB
/
street_light_using_sensor.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
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
103
104
105
106
107
108
109
110
111
112
113
114
/***** SMART STREET LIGHT USING SENSOR WITH AUTO INTENSITY LIGHT CONTROL *******/
#include <LiquidCrystal.h>
LiquidCrystallcd(8, 9, 10, 11, 12, 13);
int inPin = 7; //irsensor
int ldr = A0;
int led=3;
int value1 =0; //ldr sensor value
int count=0;
//int sensorValue = 0;
int reading;
void setup()
// put your setup code here, to run once:
{
pinMode(inPin, INPUT);
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
lcd.begin(16,2); lcd.clear();
lcd.setCursor(0,0);lcd.print(" SMART STREET ");
lcd.setCursor(0,1);lcd.print(" AUTO INTENSITY ");
delay(2000);
Serial.begin(9600);
Serial.println("******** SMART STREET LIGHT USING SENSOR WITH AUTO INTENSITY LIGHT CONTROL *********");
delay(2000);
}
void loop()
// put your main code here, to run repeatedly:
{
lcd.clear();
lcd.setCursor(0,0);lcd.print(" SMART STREET ");
lcd.setCursor(0,1);lcd.print(" AUTO INTENSITY ");
delay(2000);
Checkldrcondition();
Checkircondition();
}
void Checkldrcondition()
{
value1 = analogRead(ldr);
value1= constrain(value1,400,500);
value1 = map(value1,400,500,255,0);
Serial.print(" LIGHT VALUE: ");
Serial.println(value1);
Serial.println(analogRead(ldr));
analogWrite(led, value1);
delay(1000);
if (value1==0)
{
}
else if (value1>0 && value1<100)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LIGHT IS DIM");
lcd.setCursor(0,1);
lcd.print(" MEDIUM ");
delay(2000);
Serial.println("LIGHT IS DIM (MEDIUM)");
}
else if (value1>100 && value1<200)
{
lcd.clear();
digitalWrite(led,LOW);
lcd.setCursor(0,1);
lcd.print("LIGHT IS OFF ");
delay(2000);
Serial.println("INTENSITY IS HIGH");
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" LIGHT IS ON ");
lcd.setCursor(0,1);
lcd.print(" LOW LIGHT ");
delay(2000);
Serial.println("LIGHT IS EXTREME");
}
}
void Checkircondition()
{
reading = digitalRead(inPin);
{
if(reading == LOW)
{
digitalWrite(led,HIGH);
count+=1;
lcd.clear();
lcd.setCursor(0,0);lcd.print("LIGHT ON");
lcd.setCursor(0,1);lcd.print("VEHICLE IN");
Serial.print(" TOTAL NUMBER OF VEHICLES PASSED THROUGH THE ROAD: ");
Serial.println(count);
delay(3000);
}
else
{
}
}
}