X
Home > Blog > STEM for Arduino > HOW to Simulate a Fire Alarm with Kidspico

HOW to Simulate a Fire Alarm with Kidspico

By r November 20th, 2024 91 views
The fire alarm system of the station can effectively prevent and deal with forest fires.
In this experiment, we build a fire alarm with a flame sensor and a passive buzzer. When flame is detected, the buzzer will emit sounds for alarming.

Flow

4201

Assembly

line1

Required Parts

42_00

line1

Step 1

42_01

line1

Step 2

42_02

line1

Step 3

42_03

line1

Step 4

42_04

line1

Step 5

42_05

line1

Step 6

42_06

line1

Step 7

42_07

line1

Step 8

42_08

line1

Completed

42_09

line1

Wiring Diagram

4202

Test Code

Open 4.2Fire alarm.py and click 1407.

'''
 * Filename    : Fire alarm
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin,PWM,ADC  # Import ADC module
import time

# configure ADC, range of 0-3.3V
# define io26,io27,io28,io29 to ADC channel 0,1,2,3
Flame = ADC(28)  #Photores = ADC(2)
conversion_fator = 3.3 / 65535  #Voltage value of a single scale

buzzer = PWM(Pin(3))
buzzer.freq(800)

# read the analog value every 0.1s, convert the analog value into voltage output.
while True:
    Flame_value = Flame.read_u16()
    voltage = Flame_value * conversion_fator
    print('ADC Value:',Flame_value,'   Voltage:',voltage,'V')
    if voltage < 2:
        buzzer.duty_u16(5000)
    else:
        buzzer.duty_u16(0)
    time.sleep(0.1)

Code Explanation

5top

Conceive:

Set a threshold of voltage to determine whether there is flame. When the sensor detects flame, the voltage is lower than the threshold, and the buzzer alarms. The buzzer will stop alarming when the voltage exceeds the threshold (the sensor detects no flame).

line2

Code structure:

  1. Initialization. Set the pins of the flame sensor and the passive buzzer, set the voltage value of a single scale, and set the frequency of the passive buzzer.

  2. Loop.

    Print the analog value and voltage of the flame sensor.

    Determine whether the voltage is lower than 2 (Herein, we set 2 as the threshold, which is adjustable according to needs).

    • voltage < 2: buzzer alarms.

    • voltage ≥ 1: buzzer does not emit sounds.

5bottom

Test Result
4top
Upload the code. When the flame sensor detects flame, the voltage will lower than 2, and the buzzer will alarm. If not, the buzzer will not emit sounds.
4203
4bottom
HOW to Simulate Rainwater Detection with Kidspico
Previous
HOW to Simulate Rainwater Detection 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