Arduino-based Automatic Light Switching System

The


Introduction *
Electric energy is the main energy and power widely used in modern industrial and agricultural production, scientific and technological research, daily life and other fields, and plays a pivotal role in all aspects of human society.But many people do not have a clear concept of saving energy or have difficulty to do so in some circumstances, leading to a lot of wasting electricity in daily life.
According to the formula 'power consumption = power × time "shows that a 40 watts fluorescent tube ignoring the power consumption of the ballast, working for 10 hours a day will also consume 0.4 kilowatt hours of electricity [1] , indicating the power consumption of the lamp.Many people have not developed the good habit of turning off the lights before going out in their daily lives, especially in public spcaces, which can cause a certain amount of waste of electrical energy.
The traditional solution to this problem is to develop new materials and produce energy-saving lamps to reduce the energy consumption of electric lamps.But this is one way to solve the problem.The use of energy-saving lamps cannot reduce the working time of the lamp, and if the working time of the lamp cannot be reduced, it cannot effectively reduce the energy consumption of the lamp, and thus cannot fundamentally solve this problem.Some people also want to reduce energy consumption by reducing the lighting time, but arbitrarily controlling the lighting time may cause some inconvenience to use.
At present, research on energy-saving intelligent switches mainly focuses on sound control with delay and pyroelectric infrared detection of the human body.The application scenarios of sound control and delay *limomax@126.comtechnology are limited, and the delay time is usually very short and may be triggered by unrelated sounds.The pyroelectric infrared detection of human bodies requires the installation of pyroelectric infrared detection modules in the workplace.The accuracy of switches is related to the number of detection modules, and the cost of a large number of detection modules is not economical.
Few people think of using microcontroller control technology to solve this problem.But using Arduino microcontroller technology, we can combine number detection with automatic light on/off.When the number of people in the room is zero, mechanical devices are used to turn off the lights.When there are people in the room, the same mechanical device is used to turn on the lights, reducing the working time of the lights and reducing energy consumption.
This project is based on Arduino control technology to design an automatic light on/off system according to the number of people in certain space.The system is straightforward and efficient, which does not require a large number of detection modules, and does not need to produce unnecessary sound.It is particularly suitable for public places, such as meeting rooms, canteens, activity rooms.This system can not only be applied to lighting, but also to air conditioning, background music control, etc.It can greatly save unnecessary energy consumption and equipment wear and tear.

Control System Design
The control system is based on Arduino, using 3 ultrasonic sensors for input and 2 servos for output.(See Figure 1)

Selecting Hardware
This project is based on the Arduino platform and the Arduino Nano development board [2] (See Figure 2-left).This development board has a small size, low energy consumption, and the ability to drive and process other components, making it a very suitable development board for beginners.Its small size makes it very suitable for compact projects, and it is relatively cheap and costeffective.

Figure 2. Selected Hardware
This project uses the ultrasonic sensor HC-SR04 to measure distance [3] (See Figure 2-middle).Ultrasonic sensors have the advantages of fast response speed, antiinterference, and long distance.Compared to the applicable distance of infrared sensors within 30cm, the applicable distance of ultrasonic sensors is 2-300cm, which can better meet the requirements of distance measurement at the entrance.
This project uses the MG90S servo (See Figure 2-right) to press the switch of the light to achieve the effect of automatic light on and off [4] .The rotation angle of the MG90S steering gear is within the range of 90 ° to 180 °, which can achieve the operation of turning on and off the lights.The working voltage is 4.8V to 6V, which is suitable for the Arduino Nano board and can well meet the requirements of this project.

Circuit Design
Connect input and output terminals of the 3 ultrasonic sensors to digital pin 3,4,5,6,7,8 of Arduino Nano development board respectively [5] .Connect the control wire of the servo to pin 9,10.Connect the positive and negative terminals of the ultrasonic sensor and the servo to the corresponding pins on the development board.After testing on a breadboard, all parts are welded on to a PCB board.(See Figure 3)

Programming
This project uses Arduino software to write the program [6] .
This project uses three ultrasonic sensors to achieve the function of number detection, and uses a while and for loop structure to write the program.
The program flowchart is as follows(See Figure 4): Define the number of people as the variable c=0.When the ultrasonic sensor located in the middle detects a distance of less than 30 centimeters, the ultrasonic sensors on both sides begin to detect.When the ultrasonic sensor located on the inner side of the door detects a distance of less than 30 centimeters, it causes the number of people to be c1.At this time, if c=1, the steering gear will rotate and the light will be turned on; When the ultrasonic sensor located on the outside of the door detects a distance of less than 30 centimeters, the number of people is c-1.At this time, if c=0, the steering gear rotates and the lights will be turned off.

Structure Design
Considering that most lights and their switches have already been built upon completion of the building, the control method has been determined to be manual switching, and embedding intelligent control components requires renovation, which is too costly and timeconsuming.We decided to use existing manual switches and use external mechanical attachment to press the switches to achieve intelligent control.
To meet the needs of existing switches and provide a platform for intelligent control hardware, we have come up with a solution as shown in the following figure and designed the following device.

Figure 5. Mechanical part design drawing
This device is a mechanical attachment installed on an existing manual switch, consisting of a frame that plays a fixed role around the manual switch, a vertical rod that plays a fixation role in the steering gear, and two horizontal rods that are responsible for pressing the manual switch to achieve automatic light switch function.(See Figure 5) This device can be fixed around the switch by relying on tight adhesive, with minimal damage to the wall.Fix the two servo motors on the left vertical pole and connect them to the horizontal rod.When the program runs, the servo motor drives the horizontal rod to rotate, causing the horizontal rod to press the manual switch (86 type switch), achieving the effect of intelligent automatic light switch.Under its support structure, there is a bearing frame for the Arduino Nano microcontroller, which can accommodate the Arduino Nano microcontroller as a control part and its wiring with the sensing part.This device will cover most of the original switch, but still leave enough space for people to manually operate the switch directly.
The scheme for the induction part is as follows: This device is a sensor holding device, placed at the entrance and connected to the control part through a flexible wire.This component can hold three HC-SR04 ultrasonic modules to meet the requirements of the testing program.(See Figure 6)

3d modeling
This project uses SOLIDWORKS software for modeling, which has the characteristics of rich functionality, relatively simple operation, and easy 3D printing.(See Figure 7)

3D printing, processing and assembly
The mechanical attachment installed on the existing manual switch in this project is made using 3D printing method, while the sensor clamping device has a relatively simple structure and is processed from wooden boards.The finished product diagram is as follows(See Figure 8):

Summary and Outlook
This project utilizes Arduino control technology to successfully achieve automatic control of on/off lights based on the number of people in the room, in order to achieve energy-saving effects.However, the measurement conditions of this system are relatively harsh, and the measurement accuracy needs to be improved.In future work, we expect to improve the hardware design of the sensing section to improve performance in crowdy situations to avoid turning light on or off incorrectly.We also strive to avoid situations where the switch is not pressed correctly by enhancing the motor power, as well as improving modular design of the control part to adapt to different types of switches and enhance the versatility of the product.

Figure 1 .
Figure 1.Control System Design

Figure 3 .
Figure 3. Circuit connection diagram based on Breadboard

Figure 4 .
Figure 4. Programming Process Flow Chart

Figure 6 .
Figure 6.Design diagram of sensor clamping device