Why
Anything that can help you save time is welcome. As humans, we have improved our lives mainly by saving time on unnecessary/repetitive tasks, so that we can do more productive work instead.
It is Eco Friendly. Connecting the lights to a motion sensor is a good way of saving energy. Forget about having to switch off the lights. They will remain on only when there is someone in that area. Furthermore, it saves you money.

what
The Hands-Free Light has an Infrared Sensor , an Arduino Uno, a Relay and a Lamp Base. Also I use jumper wires and a breadboard to make it easier.
When the sensor detects a person entering the room, it will "tell" the relay to light up the bulb. Later on, after a certain period of time, it will switch off automatically if there isn’t any movement nearby.
how
The Infrared Sensor is a motion sensor. When it detects a motion, it
will send a signal to the Arduino Uno. The Arduino is a
microcontroller which has a
custom code
assigned beforehand by the computer and
then transferred by a USB cable.
When the Arduino receives the signal from the
sensor, it processes that logic through the
custom code
, and does the expected
action, in this case,
"tell" the relay to switch on. When the
relay switches on, the bulb gets electricity.
the code
const int SENSOR_PIN = 2;
//Pin Digital-2 connected to output (middle) wire of
sensor(OUT)
const int RELAY_PIN = 4;
//Pin Digital-4 which is connected to control relay
void
setup() {
Serial.begin(9600);
//setup Serial Monitor to display information
Serial.println("HC-SR501 sensor with 5V relay");
pinMode(SENSOR_PIN, INPUT);
//Define SENSOR_PIN as Input from sensor
pinMode(RELAY_PIN, OUTPUT);
//Define RELAY_PIN as OUTPUT for relay
}
void
loop() {
int
motion =
digitalRead(SENSOR_PIN);
// read the sensor pin and stores it in "motion" variable
if(motion){
// if motion is detected
Serial.println("Motion detected");
digitalWrite(RELAY_PIN, LOW);
// Turn the relay ON
}
else{
Serial.println("No Motion");
digitalWrite(RELAY_PIN,HIGH);
// Turn the relay OFF
}
delay(300);
}