Turn on an AC lamp using Arduino, 5V relay and motion sensor

This is a simple motion sensor project using Arduino. A 220V AC lamp is connected to a 5V relay and the relay is activated once the motion sensor senses motion and sends a signal to the Arduino.

List of materials

  • Arduino Uno ( Rev 3 )
  • Sensor ( PIR )  HC-SR501
  • Keyes SRD-05VDC-SL-C Relay Module or any 5V relay module
  • Socket
  • Bulb ( Incandescent lamp )
  • Suitable wires and jumpers ( thicker wires for a lamp connection, such as 1.5mm FiOS 2 ).
  • A breadboard or a protoboard to solder.

If you have never used a relay, you are recommended to read this article: How to use a relay

The code

const int negativeRELE = 10; 
const int pinPIR = 4; 

void setup () { 
  pinMode (pinRELE, OUT); 
  pinMode (pinPIR, INPUT); 
} 

void loop () { 
  int valued = digitalRead (pinPIR); 
  if (value == HIGH) { 
    digitalWrite (pinRELE, HIGH); 
    delay (5000); 
    digitalWrite (pinRELE, DOWN); 
  } 
}

Running the Circuit

The project shown below has been added with an LDR/photoresistor. This gives the project an additional feature of responding to darkness and light. To test the circuit, simply move the front of the sensor to be triggered.


Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Motion sensor

Here’s a simple motion sensor. Sketch has been taken from Arduino site. The sensor’s output pin goes to HIGH if motion is present.  However, even if motion is present it goes to LOW from time to time, which might give the impression no motion is present. This program deals with this issue by ignoring LOW-phases shorter than a given time, assuming continuous motion is present during these phases. (more…)

Search for products

Back to Top
Product has been added to your cart