Open KidsBlock and connect the board to your computer. Click File –> Load from your computer.
Choose D:\Code\1.Code_kidsuno to open 4.2Fire alarm.sb3 file.
Click to connect to port and then .
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).
Code structure:
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.
Loop.
Print the analog value and voltage of the flame sensor.
Determine whether the voltage is lower than 4 (Herein, we set 4 as the threshold, which is adjustable according to needs).
voltage < 4: buzzer alarms.
voltage ≥ 4: buzzer does not emit sounds.