Motion Sensor with Arduino Controlling AC Lamp

Motion Sensor with Arduino Controlling AC Lamp © CC BY-NC-SA

A useful and easy way to control AC Lamp using a motion sensor and Arduino board.

  • 4,065 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

This is a short tutorial to see how we can control an AC voltage application (an AC Lamp in our case) that depends on a motion sensor. The biggest problem we face in controlling any AC voltage application is:

  • Safety
  • Easy and reliable method for everyone

The relay is a common way to control AC voltage with many disadvantages:

  • Unprotected pins may cause an electrical shock hazard.
  • Needs someone with full understand of how to connect the wires and where, any mistake is unforgivable, so it's not for everyone to do.
  • Cut many wires, prepare AC plug in and AC socket to connect everything together which make the connection more complicated and dangerous.

Instead of a relay, we will use a unique device called (Sugar). This device is designed to control an AC voltage application using any development platform (Arduino, Raspberry Pi, IOT boards, etc.) and no naked wire required to connect the AC load or even the data cable.

Sugar is revolutionary device and if you like the idea of it and support it, you can today become a backer for Sugar device team at Indiegogo, all information you can find it in the campaign and also in Sugar website and see Sugar features and more tutorials.

Returning to our tutorial, all that we need is a just a few components:

  • Arduino Board (Uno, Mega, mini, etc).
  • PIR Motion sensor.
  • Sugar device.
  • RJ12 Cable.
  • RJ12 breakout.
  • AC Lamp+AC lamp socket
  • AC C14 Power cord.
  • Breadboard
  • Jumpers (Male-Male).

As a step-by-step procedure, this is a schematic connection for Arduino and motion sensor. The RJ12 breakout comes with the Sugar device, and it's an easy way to connect RJ Cable between Sugar and Arduino "No need to cut wires and check schematics many times so no need to worry about a short circuit".

We connect Arduino D9 pin to RJ12 breakout, to control Sugar you need to send PWM signal, this is an advantage to allow all development platforms to control sugar easily and useful for more advance application (Sugar also can control AC output voltage for applications like AC dimmer lamp, AC induction motor speed control).

Some pictures to show you the connections:

Just to illustrate some parts of the code:

If we want to turn on AC lamp connected to Sugar we write:

Brightness=64;  
 analogWrite(Sugarpin,Brightness);   

If we want to turn off AC lamp connected to Sugar we write:

Brightness=12;  
 analogWrite(Sugarpin,Brightness);  

And this video shows hows the circuit works:

Finally, if you like Sugar device, please support us on Indiegogo now.

Thanks!

Code

Motion sensor and AC lamp codeArduino
const int PIRpin=2;
const int Sugarpin=9;
const int LEDpin=13;
int Brightness = 12;
void setup()
{
pinMode(PIRpin,INPUT);
pinMode(Sugarpin,OUTPUT);
pinMode(LEDpin,OUTPUT);
analogWrite(Sugarpin,Brightness);
}

void loop() 
{
  boolean PIR=digitalRead(PIRpin);
  delay(50);
  if(PIR==true)
  {
   Brightness=64; 
   analogWrite(Sugarpin,Brightness);
   digitalWrite(LEDpin,HIGH);
   delay(1000);
   while(PIR==true)
   {
     PIR=digitalRead(PIRpin);
     delay(50);
   }
   Brightness=12; 
   analogWrite(Sugarpin,Brightness);   
   digitalWrite(LEDpin,LOW);   
  }
}

Schematics

Motion arduino schematic File
motion_schematic_9J4Kh5W1xw.fzz
Motion sensor and AC lamp
motion_schematic_vTMsMYErRt.fzz

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,699 views
  • 42 comments
  • 237 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,487 views
  • 95 comments
  • 671 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,393 views
  • 38 comments
  • 236 respects

OpenCat

Project in progress by Team Petoi

  • 195,888 views
  • 154 comments
  • 1,360 respects
Add projectSign up / Login