Open KidsBlock and connect the board to your computer. Click File –> Load from your computer.
Choose D:\Code\1.Code_kidsuno to open 4.4Sound detection.sb3 file.
Click to connect to port and then .
Conceive:
Set a threshold of analog value to determine the thunder volume. When thunder is detected, the analog value exceeds the threshold, and the white LED lights up as an alarm. The LED will go off when the value is lower than the threshold.
Code structure:
Initialization. Set the pins of the sound sensor and the white LED module.
Loop.
Print the analog value of sound volume detected by the sound sensor.
Determine whether the analog value is greater than 100 (Herein, we set 100 as the standard threshold of thunder volume, which is adjustable according to needs).
analog value > 100, the white LED lights up.
analog value ≤ 100, the white LED goes off.