APP下载

Design and establishment of a sensor-controlled mood lamp with a buzzer that can play music

2016-10-19ZhaoRuimin

无线互联科技 2016年17期
关键词:蜂鸣器利物浦亮度

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

1 Introduction

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.

2 Method

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.

3 Results and Discussion

(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.

4 Conclusion and remarks

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个发光二极管(Light-Emitting Diode,LED)组成的情绪灯。项目中使用的微处理器是Arduino板,使用的两个传感器是光敏传感器和超声波传感器。完成这个项目的步骤包括硬件和软件两部分。16个LED灯以一个塑料板为支撑物被焊接在一起构成一个正方形图案。一个在面包版之上搭建的主要包含传感器和蜂鸣器的电路和这16个LED灯相连接。至于软件部分,主要的编程技巧是基于对脉冲宽度调制原理的运用,以此来实现使灯的亮度能够平缓变化和调节的目的。不同的亮灯模式则由不同的基于Arduino编程软件的代码控制。最终完成的灯能够在环境亮度低到一定程度时演奏《欢乐颂》,在环境亮度高到一定程度时演奏《一闪一闪亮晶晶》。并且在演奏音乐的时候,灯会随着音乐节奏的快慢开和闭。而当超声波传感器被触发时,将手放在距离该距离传感器不同距离时,灯群会以不同的模式亮出不同的动态图形。

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 when the lightness of environment detected by the light sensor is weak enough and play when the lightness is strong enough. At the same time when the buzzer was playing songs, the LEDs would light in a consistence pace with the rhythms The lamp could also display different sets of lighting patterns depending on the detected distance of an object to the distance sensor.

猜你喜欢

蜂鸣器利物浦亮度
电动自行车产品车速提示音检测现状和整改技术研究(2)
掌控板制作简易钢琴
单片机驱动蜂鸣器的程序设计
亮度调色多面手
丰田凯美瑞240V车间隙警告蜂鸣器异常鸣响
基于斩波调制的LED亮度控制
人生的亮度