Created
May 8, 2024 03:07
-
-
Save Ajak58a/ffebb916de68c3435bd511660fee9bfa to your computer and use it in GitHub Desktop.
Smart LED streetlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ir_sensor_1 14 | |
#define ir_sensor_2 15 | |
#define ir_sensor_3 16 | |
#define ir_sensor_4 17 | |
#define ir_sensor_5 18 | |
#define ir_sensor_6 19 | |
#define led1 2 | |
#define led2 3 | |
#define led3 4 | |
#define led4 5 | |
#define led5 6 | |
#define led6 7 | |
#define led7 8 | |
#define led8 9 | |
#define led9 10 | |
#define led10 11 | |
#define led11 12 | |
#define led12 13 | |
#define ldr1 A6 | |
#define ldr2 A7 | |
#define ON 1 | |
#define OFF 0 | |
boolean day_flag=true; | |
void led_dim_light() | |
{ | |
digitalWrite(led1,ON); | |
digitalWrite(led2,ON); | |
digitalWrite(led3,ON); | |
digitalWrite(led4,ON); | |
digitalWrite(led5,ON); | |
digitalWrite(led6,ON); | |
digitalWrite(led7,ON); | |
digitalWrite(led8,ON); | |
digitalWrite(led9,ON); | |
digitalWrite(led10,ON); | |
digitalWrite(led11,ON); | |
digitalWrite(led12,ON); | |
delayMicroseconds(200); | |
digitalWrite(led1,OFF); | |
digitalWrite(led2,OFF); | |
digitalWrite(led3,OFF); | |
digitalWrite(led4,OFF); | |
digitalWrite(led5,OFF); | |
digitalWrite(led6,OFF); | |
digitalWrite(led7,OFF); | |
digitalWrite(led8,OFF); | |
digitalWrite(led9,OFF); | |
digitalWrite(led10,OFF); | |
digitalWrite(led11,OFF); | |
digitalWrite(led12,OFF); | |
delayMicroseconds(800); | |
} | |
void setup() | |
{ | |
// put your setup code here, to run once: | |
int ip,op; | |
for(ip=14;ip<=19;ip++) pinMode(ip,INPUT); | |
for(op=2;op<14;op++) pinMode(op,OUTPUT); | |
for(op=2;op<14;op++) | |
{ | |
digitalWrite(op,ON); | |
delay(200); | |
} | |
delay(2000); | |
for(op=14;op>1;op--) | |
{ | |
digitalWrite(op,OFF); | |
delay(200); | |
} | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
int ldr1_value,ldr2_value; | |
ldr1_value = analogRead(ldr1); | |
ldr2_value = analogRead(ldr2); | |
Serial.println(ldr1_value); | |
Serial.println(ldr2_value); | |
if((ldr1_value>600) && (ldr2_value>600)) day_flag=true; | |
else if((ldr1_value<100) && (ldr2_value<100)) day_flag = false; | |
if(day_flag) | |
{ | |
digitalWrite(led1,OFF); | |
digitalWrite(led2,OFF); | |
digitalWrite(led3,OFF); | |
digitalWrite(led4,OFF); | |
digitalWrite(led5,OFF); | |
digitalWrite(led6,OFF); | |
digitalWrite(led7,OFF); | |
digitalWrite(led8,OFF); | |
digitalWrite(led9,OFF); | |
digitalWrite(led10,OFF); | |
digitalWrite(led11,OFF); | |
digitalWrite(led12,OFF); | |
Serial.println("its a day"); | |
} | |
else | |
{ | |
led_dim_light(); | |
//Serial.println("its a dark night"); | |
if(digitalRead(ir_sensor_1)) | |
{ | |
digitalWrite(led1,ON); | |
digitalWrite(led2,ON); | |
delay(500); | |
} | |
if(digitalRead(ir_sensor_2)) | |
{ | |
digitalWrite(led3,ON); | |
digitalWrite(led4,ON); | |
delay(500); | |
} | |
if(digitalRead(ir_sensor_3)) | |
{ | |
digitalWrite(led5,ON); | |
digitalWrite(led6,ON); | |
delay(500); | |
} | |
if(digitalRead(ir_sensor_4)) | |
{ | |
digitalWrite(led7,ON); | |
digitalWrite(led8,ON); | |
delay(500); | |
} | |
if(digitalRead(ir_sensor_5)) | |
{ | |
digitalWrite(led9,ON); | |
digitalWrite(led10,ON); | |
delay(500); | |
} | |
if(digitalRead(ir_sensor_6)) | |
{ | |
digitalWrite(led11,ON); | |
digitalWrite(led12,ON); | |
delay(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment