Let's learn about the new sensor——"Buzzer", and make a door bell with it.
Suitable kits: mCookie102, mCookie202, mCookie302, IBC
- USB cable*1
- Sensor cable*1
- Sensor shell*1
- Lego or other fixation structure
- Assemble the modules and sensors together:
- Stick the red core module, USB upload module and green extension module together;
- Connect the buzzer to pin 6/7 of Hub;
- Connect the crash sensor to pin 4/5 of Hub;
- Insert one end of USB cable into USB upload module, and connect the other to computer;
Required Program Blocks
If it has detected that the switch was pressed, the buzzer will emit "dingdong" sound.
1. Wait for the crash to be pressed.
2. The buzzer emits "Ding".
Set the frequency of "buzzer on-frequency" program block to 1300; delay 500ms.
3. The buzzer emits "ding".
Set the frequency of "buzzer on-frequency" program block to 1000; delay 500ms.
4. Turn the buzzer off, and it will stop emitting sound.
5. Link the program blocks together, and upload the programs.
Test the result
After upload the program, press the switch, and you can hear the "dingdong" sound produced by the buzzer. At this time, you door bell is completed.
Q: To prevent someone pressing the bell, how can we modify the program to make the bell won't ring again during several seconds after ringing once?
A: You can extend the delay time of the buzzer off, and during this time the bell won't ring.
Add a "delay"
In the last line of the program, add a "delay" program block at the back of "buzzer off", and set the time to 3000ms.
Test the result
After upload the program, press the switch, and you can hear the "dingdong" sound produced by the buzzer. Each time you press the door bell, only after 3s can you press again.
- The product number of buzzer:
- The buzzer is a type of passive buzzer.
- For details, please refer to Sensor-Buzzer
- Q: Why can't the buzzer ring, directly connected to the power supply?
- A: Because the buzzer belongs to passive buzzer, only changed voltage signal can make it ring. It is the active buzzer that can ring after added voltage.
- Q: Can the buzzer sing?
- A: It can emit do, re, mi, fa, sol, la, si of different frequencies, and can make up music, please refer to Music Painting. If you want to play music, audio decoder chip and horn are required.