Sound-Activated Light | MindPlus Coding Kit for Arduino Started Tutorial E09

0 5398 Easy
projectImage

Chapter 4 Smart Light

In the previous chapter, we learned how to control the brightness of LED lights. In this chapter, we will learn how to let the environment decide when to switch lights on and off. The corridor lights "listen" for footsteps and turns on; the street lights "see" the dusk fall and go on, and off when it is dawn. These are smart lights that turn on or off according to conditions without human actions.

projectImage

Project 1 Sound-Activated Light

To make a sound-activated light, we need “ears” first. We are using a new element here -- analog sound sensor.

Analog sound sensors can recognize sound and convert the decibels of sound into analog signals. Like analog angle sensor introduced previously, the input signal range of the analog sound sensor is also 0 ~ 1023.

projectImage

Task Navigation

1. Learn analog sound sensors

2. Learn the serial monitor

3. Make a sound-activated light

Key Points Analysis

Learn analog sound sensors

We learn on our physics class that sound is produced by vibrations and propagates in sound waves. A scream in snowy mountains can cause avalanches. This is the proof of the energy of sound.

projectImage

How does human hear sounds? First, the sound reaches eardrum through the ear canal, can causes eardrum to vibrate. The vibration is then transmitted to ossicles, which then vibrate and send the signals to the brain through cochlea. Now, we hear sounds.

projectImage
projectImage

The analog sound sensor is the "electronic ear" of the device and can determine the strength of the sound. How does it do it?

Look at the small metal cylindrical element on the analog sound sensor in the upper right picture. This is a MIC speaker that can output different voltage signals according to the strength of the sound. When external sound is transmitted to the MIC speaker through sound waves, the MIC speaker can receive the "energy" of the sound wave with high sensitivity and convert the sound wave energy into different voltage signals. Working together with other circuit elements, MIC speaker converts the voltage signals into analog signals, and outputs voltage value to express the detected sound strength. This is how analog sound sensor "hears".

projectImage

Tip: One of the features of analog sound sensors is that they can use air flow instead of sound, which can effectively avoid noise interference.

Command List

projectImage

The serial output here is on the bottom right of Mind+.

Arduino’s analog input pin reads the analog input, sends it to Arduino main control panel. Then “serial output” can display the data that is currently going through the serial. The displayed position is the above serial monitor area. Click the icon in the lower left to open the serial port, and you can see the data being uploaded.

USB cable must always be connected to the Arduino and the computer USB port when serial reading.

projectImage

Hands-On

Hardware connection

Connect the red LED to Digital Pin 10, and the analog sound sensor to Analog Pin A0.

projectImage

Hardware connection (LED-R-10, analog sound sensor-A0)

projectImage
projectImage

3) Use serial port to read sound strength

projectImage

Remember to click the icon on the lower left to open the serial port to see the data being uploaded!

2. Reference program

projectImage

3. Program effect

When the Mic is rubbed or there is sound input, the LED light goes on and the serial port reading is high; when it is quiet, the LED light is off and the serial port display reading is low.

4. Program analysis

After we understand reading the signal of the analog sound sensor using the serial port, we need to determine whether there is sound and turns on or off accordingly, so we need to introduce a conditional structure: if ... then ... else.

projectImage

Note that when somebody passes, the sound-activated light needs to be kept on for a while, so don’t forget to wait for a few seconds.

Further reading

What is a sensor?

The sensor is simply a measuring device. The input quantity can be physical value, chemical value, biological value, etc.; the output value is mainly electrophysical value, it can also be aerophysical or photophysical values.

The sensor consists of a sensitive element and a converting element. The sensitive element can directly sense the object being measured, and output other values of elements in a certain relationship with it. The converting element is also called a converter. Generally, it does not directly sense the value, but converts the output of the sensitive element into an electrical value output.

projectImage

The basic composition and working mechanism of the sensor

Further Exercise

Now that we have learned how to use sound-activated lights, can you now use an analog sound sensor to make an alarm light?

icon Program 4-1 E09.rar 165KB Download(3)
License
All Rights
Reserved
licensBg
0