Automatic Motion Sensor for Light
by song111045 in Outside > Backyard
82 Views, 1 Favorites, 0 Comments
Automatic Motion Sensor for Light

This project is a concept of how a motion sensors activates a light source. I built a convenient simple energy saving motion sensor that allows light to turn on only when it detects when people are near. I built this project with the purpose of creating a concept where the LED represents the actual light bulb.
Supplies
Components
Arduino Uno R3 - microcontroller platform for easy prototyping - (1)
Ultrasonic Distance Sensor - 5V (HC-SR04) - detects movement through UV rays - (1)
10mm LED (preferably white for more accurate concept) - (1)
100 Ω resister(may need more higher if using different color) - (1)
Power
Battery - 9V - (1)
Connections
Male-Female Jumper - (4 )
female-female jumper - (1)
9V Battery Connector to DC Jack Arduino - (1)
USB 2.0 Cable Type A/B(may need another type for your own device, but has to have a USB type B) - (1)
Applications
Arduino Ide
Autodesk Fusion
Creating the Base Circuit
 (2).png)
The image above is the layout of the circuit, excluding the 9V battery and jack connector
Using these supplies:
- Arduino Uno R3 - microcontroller platform for easy prototyping
- Ultrasonic Distance Sensor
- Male-Female Jumper
First create the base of the motion detecting circuit.
with 4 pins needed to connect on the HC-SR04, connect them to the Arduino Uno platform this way using the female-male jumpers:
HC-SR04 {} Arduino Uno
Vcc → 5V
Trig → Digital Pin no. 7
Echo → Digital Pin no. 6
GND → GND
After the motion detecting circuit, the LED that represents the Light source needs to be setup.
With the LED, connect the positive charge and negative charge to its respective places:
Using male-female jumper to connect:
Positive(+) → Digital Pin no. 10
Using a Female-Female Jumper:
Negative(-) → Resister → GND
This is the finished Arduino Circuit needed for the conceptual function.
If the jumpers feel too short or the components feel too clumped up together, feel free to increase the length by just using more through connecting them
***** The 3 pins for Trigger(Trig), Echo, and LED positive(+) pin can be connected to any number digital pin, as long as the same number is inputted in for the code
Setting Up Arduino Ide

With the finished circuit, the platform needed to code the function of the circuit is the Arduino Ide platform
Refer to the Main Arduino Page on a guide to downloading Arduino Ide:
https://support.arduino.cc/hc/en-us/articles/360019833020-Download-and-install-Arduino-IDE
Establishing the Code
After downloading the Arduino Ide, create a new sketch or using a blank coding page, insert this short simple code:
const int TRIG_PIN = 6;// this sets up the Trigger as the digital pin 6 on the arduino
const int ECHO_PIN = 7;// this sets up the echo pin as the digital pin 7 on the arduino
const int LED_PIN = 10;// this sets up the LED Pin as the digital pin 10 on the arduino
const int DISTANCE_THRESHOLD = 50;// this sets up the Trigger as the digital pin on the arduino
float duration_us, distance_cm;
void setup() {// Set up the inputs and outputs of the Pins
pinMode(TRIG_PIN, OUTPUT);// sets the Trig pin as the output
pinMode(ECHO_PIN, INPUT);// sets the echo pin as the input
pinMode(LED_PIN, OUTPUT);//sets the LED pin as the output
}
void loop() {//continuously runs this code
digitalWrite(TRIG_PIN, HIGH);//sends out the voltage
delayMicroseconds(10);//pauses code for 10 microseconds
digitalWrite(TRIG_PIN, LOW);//regains voltage
//measuress the amount of time the voltage was away from the Echo pin
duration_us = pulseIn(ECHO_PIN, HIGH);
//variable duration_us stores the calculated distance(variable can change)
distance_cm = duration_us * 0.017;
//calculate the distance in centimeters based on the ultrasensor's voltage time
if (distance_cm <DISTANCE_THRESHOLD) {//when the distance is lower than the threshold(70)
digitalWrite(LED_PIN, HIGH);//turns on LED(Light)
delay(3000);//keep it on for 5 seconds
} else // when the distance is bigger than the threshold
digitalWrite(LED_PIN, LOW); // turn off LED(light)
}
Uploading Code to Arduino
Using the device you used to write the code, connect the used device to the Arduino Board using the USB type B(for Arduino) to your preferred cable (for your device).
I use a Apple MacBook, therefore I will be using a USB 2.0 Cable Type A/B with a USB adapter.
After connecting the Arduino to your device, upload the code to the Arduino
Creating the Casing and Assembly



After finishing the code and the function of the device, create a casing that will enclose the electronic parts, so that it cannot be seen from outside, in order to have a more realistic concept. I used fusion to create this enclosure, where the dimensions were 70mm x 127mm x 62mm. With fusion I create 3 holes, where 2 are for the motion sensor device, and the last one for the function of light.
After 3D printing the enclosure, I kept everything inside the casing, finishing this project.
Everything inside of the enclosure is hidden from sight, creating a nice clean look.
There is a video on the function of this concept below.
I hope this step by step instruction is clear and helpful. Thanks for reading my page!