Mohannad Rawashdeh
Published © CC BY-NC-SA

Motion Sensor with Arduino Controlling AC Lamp

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

BeginnerProtip1 hour8,992
Motion Sensor with Arduino Controlling AC Lamp

Things used in this project

Hardware components

PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Sugar device
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Motion arduino schematic File

Motion sensor and AC lamp

Code

Motion sensor and AC lamp code

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

Credits

Mohannad Rawashdeh

Mohannad Rawashdeh

3 projects • 15 followers
Mohannad Rawashdeh is an Entrepreneur,and electrical Engineer from Jordan. Founder of Sugar device. http://www.sugarworld.net/

Comments