Automatic Light

by 707580 in Circuits > Arduino

269 Views, 1 Favorites, 0 Comments

Automatic Light

PIR Sensor Final Project.png

This project is to make a light automatically turn on under certain conditions. These conditions are if the PIR Sensor detects motion, and the LDR detects that it's dark so that the light doesn't turn on during daytime. There's also a switch that turns the whole system on and off.

Components Used in This Project

engineering-components.png

The parts used in this project are:

  • Arduino
  • Bread board
  • PIR Sensor
  • LDR
  • Slide switch
  • Light bulb
  • 1 10k Ohms resistor

Wiring

PIR Sensor Final Project.png

This is how the wiring is supposed to look. The sensor, light and slide switch use the pins, and the LDR uses analog pin A0. The wire colours are very simple, it's red for power, black for ground, and green for anything connected to the Arduino pins. The PIR sensor has a power and ground pin and a pin for the signal that's meant to be wired to the Arduino. The LDR is connected to power through a wire, ground through the resistor, and to the Arduino by the green wire on top of the resistor. The light is connected to ground and the Arduino, and the slide switch is connected to power, ground, and the Arduino.

Upload the Code

computer_engineering.png

Variables for the code:

The code involves the PIR Sensor, LDR, light, and slide switch.

In the variables, there's a variable for the value of PIR sensor to store the sensor status, whether there's motion detected or not.

The void setup is simply the pin modes for the components in the circuit, and serial begin to start the serial monitor.

The void loop consists of the most important part of the code that involves the PIR sensor and the LDR. The code is an if statement. If the PIR sensor detects motion and the LDR senses that it's dark, the light turns on and it prints in the serial monitor "It's dark and Motion Detected". If else, the light turns off. The last part of the loop is the slide switch, and turning everything off if it's switched.