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.

  • 2,552 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!

Schematics

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

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);   
  }
}

Comments

Similar projects you might like

Development Board for AtTiny MCU

by Vincenzo G.

  • 197 views
  • 0 comments
  • 6 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 473 views
  • 0 comments
  • 6 respects

Version 2.0 Advanced Attendance System (Without Ethernet)

Project tutorial by GadgetProgrammers

  • 3,237 views
  • 5 comments
  • 46 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 291 views
  • 0 comments
  • 4 respects

Control LED Using Your Voice Command

by IoTBoys

  • 1,209 views
  • 1 comment
  • 12 respects
Add projectSign up / Login