Zhao Ruimin
(University of Liverpool, Liverpool L69 3BX, England)
Design and establishment of a sensor-controlled mood lamp with a buzzer that can play music
Zhao Ruimin
(University of Liverpool, Liverpool L69 3BX, England)
The aim of this project was to construct a sensor-controlled mood lamp composed of 16 LEDs which can display different patterns of lighting and can play songs using a buzzer. The microprocessor used was an Arduino board and the two sensors implemented onto the circuit were a light sensor and a distance sensor.
Arduino; Pulse Width Modulation (PWM); mood lamp; LED
Lighting systems, electrical systems which can be controlled to provide light by users, has long been an essential part of life in the modern world[1]. The lamps used in different lighting systems have a variety of types such as low voltage lamp, electro luminescent, and neon,which all have their different function features.Lamps may also have the potential to conduct more complex lighting behavior. Typical examples of such multi-function lamps are mood lamp. They do not only aim at providing light but also contain some unique functions such as producing different lighting patterns controlled by sensors or even imitating various types of light to simulate a complex lighting system[2].
The usual lamps used in daily life might not be able to meet some special requirements apart from being turned on and off, while mood lamp using LEDs can achieve more functions which may even possesses entertainment purpose. This project is to make a LED mood lamp which can conduct complex lighting patterns and interact to different environment situations with the aid of sensors and other components such as buzzer.
The main part of mood lamp in this project has similar layout with the “starting point”. It is a 4×4 square board with 16 LEDs on it. The colors of these 16 LEDs are different and the brightness of light can be controlled by the processor. The microprocessor of this mood lamp is Arduino board. This board is very common so it is easy to use it and find relative information. The code in this kind of board is similar to C and C++ language.
The code makes the mood lamp show its light in different patterns such as wave, snake, fireworks and so on. An important feature of the blinking LEDs is that the brightness is various, which is achieved by Pulse Width Modulation (PWM) theory in code[3]. Sensors and buzzer can be added to this board with specific circuit. Each sensor has its code to run and the code can be found online.
The diffculty is how to make a good combination with all codes.
The complete circuit of the mood lamp with sensor is presented in Figure 1.
Figure 1 Circuit Diagram of Overall Hardware
The mood lamp consists of 16 LEDs which are controlled by the Arduino processor by editing codes into the board. Light sensor, ultrasonic sensor and a buzzer were added in to the circuit. Moreover, for the wiring, different colors of wires represent different meanings or functions. Red lines are connected to the VCC and black lines are connected to the GND. Pink wires are only connected to LEDs. Grey lines represent that the current flow into the Arduino board, while green lines stand for that the current fow out from the Arduino board. Each electrical component with part of circuit will be explained respectively.
The Arduino board is the core of the mood lamp. It provides a 5 volts voltage to the 16 LEDs and the GND pin should be connected to the bread board. To connect to the 16 LEDs, PWM pins which could get analogue result with digital means were taken advantages of entirely. The serial numbers are from 2 to 13 and from A0 to A3, in total 16 pins. Also, the clock counter of it is 16MHz, which enables output pins to display various brightness using PWM theory[4].
The voltage of lighter sensor is the output signals when the lighter sensor receives lightness outside. One pin of lighter sensor was connected to the analogue input pin on the Arduino board because lightness can be seen as analogue signals. The ultrasonic sensor was taken as a distance sensor. The ultrasonic sensor receives ultrasonic and transform it to voltage signal to the processor. The trig pin controls the sensor to distinguish different level of ultrasonic, so it was connected to the digital input pin. The echo pin was connected to the analogue output pin on the board.
2.1Code Design
The main coding principle which enables the LEDs to generate various lightness than simply being turned on and off is the PWM (pulse-width modulation) theory[5]. Each time when the LED blinks, several duty cycles will be executed in succession in a very fast speed. The pulse width of each clock period is where the voltage is high. The portion of the pulse width over the period is duty cycle which can be expressed using eq.(1), where W represents pulse width, T represents period and D represents duty cycle.
Concretely, in this code, 256 steps were used for each duty-cycle which is repeated very fast (the clock frequency of this Arduino board is 16MHz[5]) for each time of blink. The LED is turned on at the beginning of one duty-cycle can then turned off at certain step, so the earlier it is turned off during the cycle, the dimmer it will be. The 256 step cycle is executed n times as specifed by the input parameter n. For each LED, the lightness value that is associated with the LED is computed frst, then for any LEDs that are not off will be turned on at the beginning of each duty cycle, and at each step, any LEDs that need to be turned off at that step will be checked out and turned off.
The four patterns of lighting display can be run in set order. This fluent change of the patterns, is achieved by function pointers. A function pointer is pointer which can point to different functions. The function pointer is used to direct the performance to different functions with all the pattern functions listed in an array.
For the triggered buzzer to play songs, we defined an array containing integers representing different tones at the beginning. These integers will be used as frequency which influence the buzzer sound. Then for a specific song, we create another array containing its own tones expressed using those defned integers in the previous array to drive the buzzer to play certain song.The arduino function tone()and noTone() were used to start and stop the generation of square wave based on the frequencies sets defned in array as explained above. This wave is the signal that controls thebuzzer to be turned on and off in a certain rhythm.
The code flow chart which illustrates how the sensors and buzzer are controlled is presented in Figure 2.
Figure 2 Sensors and Buzzer Flow Chart
2.2Procedure
Step One - LED socket soldering: The sockets were soldering with a 330 resistor and a wire on the worktable one by one. After soldering, isolated tape was used to fix two pins to prevent short circuit. This was to simplify the circuit connection and make the circuit more stable.
Step Two: Lamp main body assembling: The layout of the 16 LEDs were designed to be a 4 × 4 square. Therefore,16 marks were made on the lamp base - a plastic board based on the designed allocation of LEDs.
Step Three: Add sensors and test them: For the light sensor, some experiments were done on breadboard to fgure out how it reacted to the lightness change. After reading the material descriptions, we knew that the working principle of this sensor was that its resistance changes with the lightness change. The darker the environment is, the smaller the resistance is.
Step Four: Connect the circuit: First, 16 I/O pins including both PWM pins and digital pin of the Arduino board were chosen, and then each pin was connected to each LED socket across transistor arrays (ULN2803A). Then the sensors were added.
(1)When the light sensor was triggered either in darkness or under strong light, the buzzer would be triggered to play two different songs respectively. And in the same time, the LEDs would blink according to the rhythms.
(2)When the distance sensor was triggered, the LEDs would display different lighting patterns depending on which range of the distance the object is to the sensor. There were four ranges of the detectable distance from 0 to 40 with a step of 10. When the distance lied in one of these ranges, the LEDs to frst displayed 1/2/3/4 lines of LED to show which distance range it was and then displayed some specifc patterns.
(3)When none of the two sensors were triggered, the lamp would randomly display different lighting patterns.
There results were achieved by the circuit design mainly concerning the sensor connection. The changing voltage of the sensor was sent to Arduino board via PWM pin and was detected using function analogRead()in code which divided the VCC(5V)into 1024 parts so that an integer from 0 to 1024 represented the changing input voltage divided by the light sensor. The buzzer sensor was connected to Arduino board via digital pin. The distance sensor was connected to Arduino board with its sound receiving and sound sending pins both connected to board via PWM pins.
To sum up, the mood lamp built in this project has met most of the objectives since it could react to environment with the aid of a distance sensor and a light sensor by playing songs using the buzzer or display lighting patterns using the LEDs as expected. However, there are also some slight nonperfect performance which are the time delay of the reactions of the sensors and the noise produced by the buzzer when lamp is frst connected to power.
[Reference]
[1]N RODRIGUEZ. Lighting control system[EB/OL].(2016-09-10)[2013-02-10].http://casaplex.com/ what-is-a-lighting-controlsystem/, 2013.
[2]K C LIN, C S LIN. The study of a novel control method of the mood lighting emulator[J]. Optics Communications, 2015(35): 75-76.
[3]MICHAEL.Arduino-controlled mood lamp made with leds and glass vials[EB/OL].(2016-09-10)[2010-03-14].http:// nootropicdesign.com/projectlab/2010/03/14/mood-lamp/.
[4]MICHAEL B, Pulse width modulation[EB/OL].(2016-09-10)[2001-11-02].http://homepage.cem.itesm.mx/carbajal/ Microcontrollers/ASSIGNMENTS/readings/ARTICLES/ barr01 pwm.pdf, University of Maryland, 2001.
[5]ARDUINO UNO. Microcontrollers, Readings and Assignments[EB/OL].(2016-09-10)[2010-07-03].http://www.rapidonline.com/ pdf/73-4440.pdf.
帶有傳感器與奏樂蜂鳴器的LED燈的設計與裝配
趙睿敏
(英國利物浦大學,英國利物浦L69 3BX)
這個項目的目的是搭建一個帶有傳感器,能夠通過蜂鳴器奏樂的,由16個發(fā)光二極管(Light-Emitting Diode,LED)組成的情緒燈。項目中使用的微處理器是Arduino板,使用的兩個傳感器是光敏傳感器和超聲波傳感器。完成這個項目的步驟包括硬件和軟件兩部分。16個LED燈以一個塑料板為支撐物被焊接在一起構成一個正方形圖案。一個在面包版之上搭建的主要包含傳感器和蜂鳴器的電路和這16個LED燈相連接。至于軟件部分,主要的編程技巧是基于對脈沖寬度調制原理的運用,以此來實現使燈的亮度能夠平緩變化和調節(jié)的目的。不同的亮燈模式則由不同的基于Arduino編程軟件的代碼控制。最終完成的燈能夠在環(huán)境亮度低到一定程度時演奏《歡樂頌》,在環(huán)境亮度高到一定程度時演奏《一閃一閃亮晶晶》。并且在演奏音樂的時候,燈會隨著音樂節(jié)奏的快慢開和閉。而當超聲波傳感器被觸發(fā)時,將手放在距離該距離傳感器不同距離時,燈群會以不同的模式亮出不同的動態(tài)圖形。
Arduino;脈沖寬度調制(PWM);情緒燈;LED
introduction:Zhao Ruimin(1995— ), female, Shandong Jinan, undergraduate; Research direction:telecommunication.
The approaches to complete this project included both hardware and software aspects. The 16 LEDs were arranged into a 4 × 4 square shape soldered onto a plastic board and connected to a circuit containing the Arduino board and a breadboard with the two sensors and a buzzer on it. While in terms of software, the core coding principle used was pulse width modulation(PWM) which enabled the LEDs to display various levels of lightness, and all the lighting patterns were designed using coding in Arduino coding software.The fnished mood lamp was able to play