Project tutorial
Motion Activated Night Light

Motion Activated Night Light

Lights from LEDs will light up as soon as the PIR motion sensor detects a motion.

  • 4,070 views
  • 0 comments
  • 4 respects

Components and supplies

Apps and online services

About this project

Purpose

This is my latest project at university. I am really new to this. So I decided to make a Motion Activated Night Light and put it in my bathroom or in my closet. This way I don't have to find the switch button to turn on the light in the middle of night or go back and forth to the switch light and closet.

Build Process

These are the steps I took.

I tested the Arduino with PIR Motion Sensor to see how it works. So I connected the black wire from GND to Arduino GND, the white wire from out to Arduino Pin 2 and the grey wire from VCC to Arduino 5V.

After that I made a DIY box. This is just a mock-up to represent a 'toilet' or 'closet' - a place for me to put my LED strip, so this is very optional.

The LED strip has 4 pins which are: 12V (black), R (red), G (green) and B (blue).

So I connected the black one to breadboard on '+', blue to A0, red to A1 and green to A2.

I used this 12V Power Supply as the source for this project. I connected the '+' (white) to the breadboard's '+' and (black) wire to Arduino GND.

Then I used another male to male wire and connected the breadboard's '+' to Arduino Vin as shown in diagram (the red wire connected from breadboard to Arduino).

Lastly, again, this is just optional as I just made my own mock-up. I put everything together in the box and turned it on. That's it!

Code

Simple code that worksC/C++
/*#define Bpin 8;
#define Rpin 9;
#define Gpin 10;*/
/*int Bpin = analogRead(A0);
int Rpin = analogRead(A1);
int Gpin = analogRead(A2);*/
int Bpin = A0;
int Rpin = A1;
int Gpin = A2;
int Motion = 2; //PIR sensor
int state = LOW;
int val = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(Motion, INPUT);
  pinMode(Bpin, OUTPUT);
  pinMode(Rpin, OUTPUT);
  pinMode(Gpin, OUTPUT);

  //Serial.begin(9600);
}

void loop() 
{
  val = digitalRead(Motion);

if(val == HIGH)
{
  Serial.println("Menyala");
  if (state == LOW)
  {
    state = HIGH;
  }
  
// put your main code here, to run repeatedly:
for(int fade = 0; fade <=255; fade +=5)
{
analogWrite(Bpin,fade);
}
for(int fade = 255; fade >= 0; fade -=5)
{
analogWrite(Bpin,fade);
delay(10);
}
for(int fade = 0; fade <=255; fade +=5)
{
analogWrite(Rpin,fade);
delay(1000);
}
for(int fade = 255; fade >= 0; fade -=5)
{
analogWrite(Rpin,fade);
delay(1000);
}
for(int fade = 0; fade <=255; fade +=5)
{
analogWrite(Gpin,fade);
delay(1000);
}
for(int fade = 255; fade >= 0; fade -=5)
{
analogWrite(Gpin,fade);
delay(1000);
}

}

else
{
Serial.println("Tidak Menyala");
if (state == HIGH)
  {
    state = LOW;
  }
int dim = LOW;
analogWrite(Bpin,dim);
analogWrite(Rpin,dim);
analogWrite(Gpin,dim);
}

}
  
  

  

Schematics

Real life diagram
really simple but might look complicated with the wiring.
Img 6618 eod8stgm6h

Comments

Similar projects you might like

Neopixel Motion Activated Night Light

Project tutorial by Becky Ellis

  • 2,492 views
  • 4 comments
  • 9 respects

Night Light Assistant

Project showcase by Gabriele Fugazzi

  • 3,830 views
  • 9 comments
  • 21 respects

RobotGeek PIR Motion Sensor Night Light

Project tutorial by Team RobotGeek Projects Team

  • 1,502 views
  • 1 comment
  • 6 respects

My Motion Activated Security Cam project

Project tutorial by Christiaan Neil Burger

  • 9,231 views
  • 9 comments
  • 12 respects

Motion activated SMS Shield- Tutorial

Project tutorial by Burger

  • 4,228 views
  • 2 comments
  • 5 respects

Motion Detection Lamp

Project tutorial by Izzati Azryna

  • 3,063 views
  • 0 comments
  • 8 respects
Add projectSign up / Login