Smartfirealarmsystem
Smartfirealarmsystem
1. Introduction
1.1 What am I learning here and why?
In this tutorial, you will learn how to create a smart fire alarm system utilizing electronics
and sensors, namely a flame sensor, a 5V passive buzzer, and a servo motor. This smart
fire alarm system will notify the user if there is a fire inside the SmartHome. If the flame
sensor detects fire, the buzzer will go off and the servo motors will be enabled, opening
the entrance and garage doors.
Software
So that you can carry out the installations shown in this tutorial you should have
downloaded the Thonny programming environment on your device. Also, you need to
have installed the firmware of MicroPython on your Raspberry Pi Pico. The extended
modifications (see p 42 in manual) including the extra components and their connectivity
must also be made on the breadboard.
Electrical Hardware
• 1 x Raspberry Pi Pico
• 2 x Servo motor
• 1 x Full-size breadboard
• 1 x Buzzer
• 1 x Micro-USB cable
• 6 x male-to-male jumper cables (20cm)
• 2 x male-to-female jumper cables (20 cm)
This project has been funded with support from the European Commission. This publication [communication] 1
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
• 1 x M2 metal bolt
• 1 x M2 metal nut
• 4 x M2 metal wood screw
• 2 x Plywood pieces (doors)
• 4 x metal screws that come together with the servo motors
• Phillips head screwdriver
• Pliers (optionally to tighten the flame sensor to the wooden wall
Ability
As regards physical skills you should be able to count off holes on the breadbord and
insert components to it.
2. Learning content
2.1 Theoretical background
To understand the content of this tutorial well, you will now get an introduction to the
most important terms and contexts.
The KY-026 flame sensor is a module or component used for detecting the presence of
flames or fire. It's commonly used in various applications, including fire detection and
safety systems.
This project has been funded with support from the European Commission. This publication [communication] 2
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
S
S
R1
R3
R2
11
102
104
103
104 13
141
1M
M3 3
R1
2 1
0
102
104
R6
R
Figure 1 Flame sensor
Here are some key features and information about the KY-026 flame sensor:
1. Detection Method: The KY-026 flame sensor typically uses an infrared (IR)
sensor to detect the presence of flames. It can detect the infrared radiation emitted
by flames.
3. Adjustable Sensitivity: Some KY-026 flame sensor modules allow you to adjust
the sensitivity, allowing you to fine-tune the sensor's response to flames of different
intensities.
4. Compatibility: The KY-026 flame sensor is often used with microcontrollers like
Arduino and Raspberry Pi to create fire detection and monitoring systems.
5. LED Indicator: Many KY-026 modules come equipped with an LED indicator that
lights up when a flame is detected, providing a visual indication of the sensor's
status.
6. Use Cases: Common applications for the KY-026 flame sensor include fire alarm
systems, flame monitoring in industrial processes, fire-fighting robots, and safety
systems that need to respond to the presence of flames.
7. Caution: While the KY-026 flame sensor can be a valuable component in fire
safety systems, it's essential to remember that it may have limitations in terms of
the range and type of flames it can detect. It's not a replacement for professional-
grade fire detection systems used in critical applications.
When using a KY-026 flame sensor, you'll typically need to connect it to a microcontroller
and write code to interpret its output and trigger appropriate actions based on the presence
of flames. The specific wiring and code will depend on your project and the microcontroller
This project has been funded with support from the European Commission. This publication [communication] 3
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
platform you're using. Be sure to consult the sensor's datasheet or documentation for
detailed information on its usage and integration.
These buzzers are commonly used in various electronic projects and devices to provide
audio feedback, alerts, or alarms. They are often found in applications such as electronic
games, alarms, timers, and other situations where a simple audible signal is needed.
When the 5V voltage is applied, the buzzer's internal piezoelectric element or magnetic
coil vibrates, creating the sound or tone.
Users can control the duration and frequency of the sound produced by controlling the
duration and timing of the voltage applied to the buzzer. It's important to note that while a
5V power supply is common for these buzzers, the specific voltage requirements may vary
depending on the manufacturer and model, so it's advisable to check the datasheet or
specifications provided by the buzzer's manufacturer for precise operating details.
The SG90 servo motor is a widely used micro-sized servo motor that is popular in the
hobbyist and robotics communities. It's a small, lightweight, and inexpensive motor that
provides precise control of angular or rotational movement.
Here are some key features and information about the SG90 servo motor:
This project has been funded with support from the European Commission. This publication [communication] 4
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
1. Size: The SG90 servo motor is a micro-sized servo, often referred to as a "9g
servo" due to its weight of approximately 9 grams. Its compact size makes it
suitable for various applications where space is limited.
2. Operating Principle: Servo motors like the SG90 work based on the principle of
feedback control. They have an internal potentiometer that allows them to
accurately determine their position. By sending control signals in the form of
pulses, you can command the servo to move to a specific angle within its range,
typically 0 to 180 degrees.
3. Rotation Range: The SG90 servo motor has a rotation range of approximately
180 degrees, making it suitable for a wide range of applications requiring precise
angular control.
6. Control Signal: It typically uses a PWM (Pulse Width Modulation) signal for
control. The width of the pulse determines the desired position of the servo, with
different pulse widths corresponding to different angles.
8. Ease of Use: These servo motors are relatively easy to use and can be controlled
with various microcontrollers like Arduino, Raspberry Pi, and other embedded
systems. Libraries and code examples are readily available to help control them.
Keep in mind that while SG90 servo motors are versatile and widely used, they do have
limitations, including limited torque compared to larger servos and slower response times
in some cases. When selecting a servo motor for your project, it's essential to consider
your specific requirements in terms of torque, speed, and precision.
Now let's move on to the implementation of the before mentioned scenario. To do this,
take the SmartHome4Seniors house model or just look at the instructions.
This project has been funded with support from the European Commission. This publication [communication] 5
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
1. The flame sensor needs to be mounted on the back-side wall. For this you need 1 x
bolt and 1 x nut. Mount it through the middle section of the sensor and make sure the
sensor (black part) looks up.
Flame sensor
2. The servo motors need to be mounted in the front-side of the house model. You need
4 screws. Place the motors from the inside of the house towards the outside and mount
them using the screws included in the package.
This project has been funded with support from the European Commission. This publication [communication] 6
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
3. The buzzer needs to be inserted on the right-side piece of the house model. Insert
the buzzer to the upper-right corner slot (make sure its pins are on the inside of the
house model) and friction will keep it in place.
Buzzer 5V
Now we have to connect the sensors with cables with our Raspberry Pi.
This project has been funded with support from the European Commission. This publication [communication] 7
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
This project has been funded with support from the European Commission. This publication [communication] 8
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
Finally, we have to tell our Raspberry Pi, how to transform the information from the
sensors into action. For this, open Thonny from your device. Then go to File -> Save
as…, choose Raspberry Pi Pico, and save your file under the firealarm.py.
The following code creates a fire alarm system, that notifies you in case of fire, while also
opening the doors. Since the servo motors operate using the PWM principles, this tutorial
makes it easy for you to calculate the correct angle the door and garage door should open.
To do that, first you will need to add a library to your Raspberry Pi Pico.
Open Thonny Python and create a new file by clicking File → New or by hitting Ctrl+N on
your keyboard.
Then make sure the Raspberry Pi Pico is connected. You should see on the right corner
of Thonny’s window the message “MicroPython (Raspberry Pi Pico)”. If this is not the case,
please jump back to the Kit’s manual and follow the instructions on how to properly install
the firmware.
After making sure the Pico is connected, you should click on Tools → Manage packages.
On the search bar write “micropython servo” and click Search.
This project has been funded with support from the European Commission. This publication [communication] 9
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
This project has been funded with support from the European Commission. This publication [communication] 10
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
Click on micropython-servo and then click on Install. Wait for installation to complete and
then click Close.
You are now ready to create the fire alarm program. Save the file as firealarm.py and
choose Raspberry Pi Pico as the saving destination. Copy the program below, or simply
write it yourself to practice. There is also a step-by-step video tutorial of the program
creation. Make sure to check that out as well.
firealarm.py
PIN_DOOR = 0
PIN_GARAGE = 1
This project has been funded with support from the European Commission. This publication [communication] 11
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
PIN_BUZZER = 6
PIN_FLAME_SENSOR = 2
door = Pin(DOOR)
garage = Pin(GARAGE)
entrance_door = Servo(pin_id=door)
garage_door = Servo(pin_id=garage)
buzzer_pin.value(0)
while True:
buzzer.value(1)
This project has been funded with support from the European Commission. This publication [communication] 12
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
else:
buzzer.value(0)
The code contains information that if the flame sensor detects a fire (when its value is 1),
it activates the buzzer, adjusts the servo motor positions for the door and garage door
(doors open automatically), and waits for 0.5 seconds.
If the flame sensor does not detect a fire (when its value is not 1), it deactivates the buzzer,
adjusts the servo motor positions for the door and garage door (doors stay closed), and
waits for 0.5 seconds.
Now it is time to test your code and circuit on your SmartHome4Seniors house model.
Click the Play button in Thonny and then turn on a lighter or a flashlight close to the flame
sensor. If your code and circuit are correct, then you should hear the buzzer ringing and
you should see the doors opening automatically. In case the doors don’t open, or open at
the wrong angle, make sure to change that part of your code as instructed before. “Play”
with the degrees, so the doors completely open and close.
This project has been funded with support from the European Commission. This publication [communication] 13
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.
2021-1-DE02-KA220-ADU-000033587
Check out the video tutorial on how you can implement the smart fire alarm system on
your SmartHome4Seniors house model.
3. Summary
In this tutorial you have learned how you can connect and program a fire alarm system on
your SmartHome4Seniors house model, so it notifies you when fire is detected. You also
learned how to program the entrance and garage doors to open automatically in case of
a fire. This simple system can be connected to other sensors and electronics of your smart
home, such as the OLED display and the fan, to offer a more interactive experience. The
setup of this scenario included the installation of three components:
This project has been funded with support from the European Commission. This publication [communication] 14
reflects the views only of the author, and the Commission cannot be held responsible for any use which may be
made of the information contained therein.