Arduino Beginner Series: Project 10: Turn LED on if lights are off

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:

  1. Arduino UNO
  2. LEDs (1 of green and red each)
  3. Breadboard
  4. 220 ohm resistor (x2)
  5. Jumper Wires
  6. Photoresistor
  7. 5k ohm resistor
  8. Arduino IDE on computer

Functions used:

  1. digitalWrite()
  2. Serial.println()
  3. analogRead()
  4. 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!!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: