Hello everyone!! Welcome to this post on Arduino LED Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE
So in this project the Green Led is on if lights in the room are on and red LED turns on if the room lights are off.
Demo:
This is what my project looks like:
Things Required:
- Arduino UNO
- LEDs (1 of green and red each)
- Breadboard
- 220 ohm resistor (x2)
- Jumper Wires
- Photoresistor
- 5k ohm resistor
- Arduino IDE on computer
Functions used:
- digitalWrite()
- Serial.println()
- analogRead()
- pinMode()
Reference Material:
I used this (LINK) video as a reference.
Code:
View on/ Download from Github: (LINK)
int redled=9;
int greenled=8;
int lightpin=A2;
int lightval;
void setup() {
// put your setup code here, to run once:
pinMode(lightpin, INPUT);
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
lightval= analogRead(lightpin);
Serial.println(lightval);
if(lightval<100){
digitalWrite(redled, HIGH);
digitalWrite(greenled, LOW);
} else {
digitalWrite(redled, LOW);
digitalWrite(greenled, HIGH);
}
}
Stay Tuned for upcoming posts on Arduino Projects! We’re on the basic newbie projects right now and slowly, gradually move on to those cool, ultra techy projects!! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!
Happy Learning!!
