Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int PIRpin = 3;
- const int LDRpin = 0;
- const int LEDpin1 = 5;
- const int LEDpin2 = 6;
- const int LEDpin3 = 7;
- const int LEDpin4 = 8;
- const int LEDpin5 = 9;
- const int LEDpin6 = 10;
- void setup() {
- pinMode(PIRpin, INPUT_PULLUP); // I'm assuming PIRpin is active low, it might not be.
- pinMode(LEDpin1, OUTPUT); // Add more LED pins for each of them
- pinMode(LEDpin2, OUTPUT); // Add more LED pins for each of them
- pinMode(LEDpin3, OUTPUT); // Add more LED pins for each of them
- pinMode(LEDpin4, OUTPUT); // Add more LED pins for each of them
- pinMode(LEDpin5, OUTPUT); // Add more LED pins for each of them
- pinMode(LEDpin6, OUTPUT); // Add more LED pins for each of them
- }
- void loop() {
- int LDR;
- int LEDs;
- if(digitalRead(PIRpin) == LOW) // Is the PIR low?
- {
- LDR = analogRead(LDRpin);
- LEDs = int(map(LDR,0,1023,6,1)); // Maps the 0-1023 reading from the LDR to between 6 (if the room is dark) and 1 (if the room is light) LEDs
- switch(LEDs)
- {
- case 6:
- digitalWrite(LEDpin6,HIGH);
- case 5:
- digitalWrite(LEDpin5,HIGH);
- case 4:
- digitalWrite(LEDpin4,HIGH);
- case 3:
- digitalWrite(LEDpin3,HIGH);
- case 2:
- digitalWrite(LEDpin2,HIGH);
- case 1:
- digitalWrite(LEDpin1,HIGH);
- }
- }
- else
- {
- digitalWrite(LEDpin6,LOW);
- digitalWrite(LEDpin5,LOW);
- digitalWrite(LEDpin4,LOW);
- digitalWrite(LEDpin3,LOW);
- digitalWrite(LEDpin2,LOW);
- digitalWrite(LEDpin1,LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement