X
Home > Blog > STEM for Arduino > HOW to Simulate Thunder Detection with Kidspico

HOW to Simulate Thunder Detection with Kidspico

By r November 22nd, 2024 92 views
Thunder is the atmospheric sound produced by lightning. When thunder is detected, it sends an alert that rain may be coming.
In this experiment, we integrate a sound sensor and a white LED module to construct a thunder detector. When the thunder volume exceeds a set threshold, the white LED will lights up.

Flow

4401

Assembly

line1

Required Parts

44_00

line1

Step 1

44_01

line1

Step 2

44_02

line1

Step 3

44_03

line1

Step 4

44_04

line1

Step 5

44_05

line1

Step 6

44_06

line1

Step 7

44_07

line1

Completed

44_08

line1

Wiring Diagram

4402

Test Code

Open 4.4Sound detection.py and click 1407.

'''
 * Filename    : Sound detection
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import ADC,Pin
import time

# configure ADC, range of 0-3.3V
# define io26,io27,io28,io29 to ADC channel 0,1,2,3
MicroPhone = machine.ADC(27)  #MicroPhone = ADC(1)

led = Pin(11, Pin.OUT)
while True:
    Micro_value = MicroPhone.read_u16()
    print(Micro_value)
    time.sleep(0.1)
    if Micro_value > 10000:
        led.on()
    else:
        led.off()

Code Explanation

5top

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.

line2

Code structure:

  1. Initialization. Set the pins of the sound sensor and the white LED module.

  2. Loop.

    Print the analog value of sound volume detected by the sound sensor.

    Determine whether the analog value is greater than 10000 (Herein, we set 10000 as the standard threshold of thunder volume, which is adjustable according to needs).

    • analog value > 10000, the white LED lights up.

    • analog value ≤ 10000, the white LED goes off.

5bottom

Test Result
4top
After uploading the code, the sound sensor detects whether there is a thunder. When the analog value of the sound exceeds 10000, a thunder is detected and the white LED will light up.
Here we stimulate thunder by playing music. When the value is greater than 10000, LED lights up.
4403
4bottom
HOW to Detect Magnetic Field with Kidspico
Previous
HOW to Detect Magnetic Field with Kidspico
Read More
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Next
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Read More
Message Us