2D - SDG 15 - Sensors for Forest Fire (Difficulty: 3)
CreatiCode last edited by info-creaticode
- Paint Costumes
- Using variables
- Set or Change Sprite Size
- Switch Costumes
- Graphic Effects
- When touching event
- Sending and receiving messages
The SDGs are 17 goals adopted by the United Nations in 2015. They are a to-do list for everyone to work on together.
This tutorial is about detecting wildfires in forests as soon as they occur, which is related to the 15th goal of “preserving life on land”.
Wildfires in forests bring significant damage to the ecosystem. They not only ruin the natural habitat of many animals and plants, but also generates a huge amount of toxic smoke into the air. If we can detect them and put them off at the early stage, the damage will be much smaller.
In this project, you will build a simple demonstration that shows how we can use a network of sensors to help us detect wildfires as soon as possible. Whenever there is a fire, the sensors will detect the change in temperature, and then relay that information to the signal tower. Using such sensors are often better than analyzing satellite images, since satellites can not cover all forests at all times, and they are often blocked by cloud or smoke.
First, please click this link to open the project template:
Click the “remix” button to make a remix project of your own. Note that you need to be signed in to do this.
This project uses a forest picture from Google Maps, and it contains 3 sprites:
- The “Fire” sprite contains some costumes for a fire;
- The “Sensor1” sprite is a green circle with a number 1, and it represents the location of sensor 1;
- The “Signal Tower” sprite contains some costumes for a signal tower. A signal tower can send alert messages through the satellite to firefighters.
First, let’s go to the “Fire” sprite, and make it display a burning fire when the program starts. It can simply show all the costumes one by one in a forever loop:
Now we get a nice fire animation:
Next, let’s make the fire grow from a tidy dot to a large wildfire. We will set the Fire sprite’s size to 1, and make its size grow up by 5 every second for 40 seconds:
Now the fire will grow bigger and bigger:
Now we start to work on the “Sensor1” sprite. We will first complete its code, then make many copies of it.
The 2 color effects will make the Sensor1 sprite look red and orange. Now let’s test it by putting the sensor next to the fire. When the fire grows large enough, it will start to touch the sensor.
When any sensor in the forest detects a fire nearby, it needs to let the firefighters know. These sensors do not have a direct way to communicate with firefighters. Instead, they can only send messages to their nearest neighbors, and these neighbors can relay these messages to other neighbors. After a few stops, the messages will be sent out by the signal tower.
Now let’s send a message “fire” from “Sensor1” to 3 neighbor sprites when the sensor detects a fire. We will use the “send message with parameter to sprite” block. It allows us to send the message to only one other sprite, and we can attach a parameter to this message. Note that for now we only have one sensor sprite, so the last input of the receiver sprite will need to be changed later.
When any sensor receives the “fire” message, it needs to go through the same steps as when it touches the fire, so we can simply duplicate the existing blocks.
We will need a new variable “number” to store the parameter of that message, which is the number of the sensor that has detected the fire.
Since all the blocks are duplicated, we can make a new block for these blocks. The new block will be called “handle fire”, and it takes one input as the number of the sensor that has detected the fire.
Now we are ready to make some copies of Sensor1. Please use the right-click menu to duplicate it into “Sensor2”, “Sensor3” and “Sensor4”.
Next, change their costumes to show “2”, “3” and “4” by double-clicking the text:
Lastly, move them to 3 different directions surrounding Sensor1.
Now we are ready to update the message receiver in Sensor1. We can change the receiving sprites to the 3 new sensor sprites.
For a test, now if we put the fire close to Sensor1, it will send this alert to the 3 new sensors:
Next, to cover the entire map, we need to make more copies of the sensor. Here is an example of 12 sensors:
Sensor1 is sending the “fire” alert to Sensor 2/3/4, but the other sensors are not sending the message correctly yet. Please go through each sensor sprite, and update the receiver sprite to the 3 sensors that are closest to it.
For example, Sensor2 can send to Sensor 1/6/8, and Sensor9 can send to Sensor 8/3/12.
Sensors that are close to the signal tower should relay the message to the signal tower, so that the signal tower can send this message to the firefighters.
In our example, Sensors 4/7/12 should send the alert message to the signal tower:
Here is the code change for Sensor4:
When the signal tower receives the “fire” alert, it should send it out through the satellite. To show that, we can make it animate through the 3 costumes. We will also need to reset its costume to “0” when the project starts.
To test the project, you can make the Fire sprite smaller, and then place it anywhere on the map close to a sensor.
Currently when the first sensor detects a fire, the alert message travels immediately to all other sensors and the signal tower. To illustrate how the alert message travels to the signal tower, we can add a 1-second delay in each of the 12 sensor sprites like this:
Now if you test again, you can clearly see how the alert message propagates across the sensor network.
There are many ways you can extend this project. Here are some examples:
Random Fire: You can make the “Fire” sprite go to a random starting point, and test whether the signal tower would always send out the alert.
Redundancy Test: You can try to disable some sensors (detach their code blocks), and see if the sensor network can still handle fires successfully. Which sensors are the most critical?
Using clones: Since most of the code blocks are the same among the 12 sensor sprites, you can try to simplify the program to use only 1 sensor sprite, but clone it 12 times. You can use a list or table to store the receiving sensor IDs for each sensor.