Introduction: Fire Chasing Robot
In this project, we're going to create a firefighting robot that chases a flame and extinguishes it by blowing air at it from a fan.
After you're done with this project, you'll know how to use flame sensors with PICO, how to read their output value and how to act on it, and how to use Darlington sensors with DC motors and how to control them. That of course along with a very cool firefighting robot.
- Flame Sensor
- Small DC motor
- Small Propeller
- L298N H-bridge motor driver
- PCA9685 12-bit 16-channel PWM driver
- 2WD robot chassis kit
- Mini breadboard
- Jumper wires
- Screws and nuts
Step 1: Connecting the Flame Sensor to PICO
Let's start with the most important part of our fire fighting robot, which is the ability to detect fires when they happen. That is why we are going to start with the components that are responsible for detecting the fire, but before we do, let's assemble our 2WD robot chassis kit, as we'll build our robot based on it.
We'll be using 3 flame sensors in this project and we'll have the robot move independently using their readings, we'll place these sensors on the middle, left, and right side of the robot's chassis. And they'll be placed in such a way to have the ability to accurately pin point the flame source and put it out.
Before we start using the flame sensors, let's talk about how they work: flame sensor modules are mainly made of infrared receiver LEDs that can detect the infrared light that is emitted from flames, and send the data as either digital or analog input, in our case we'll be using a flame sensor that sends digital output.
Flame sensor module pin outs:
- VCC: positive 5 volts, connected with PICO's VCC pin.
- GND: negative pin, connected with PICO's GND pin.
- D0: the digital output pin, connected with the desired digital on PICO.
Let's now connect it to our PICO to test our wiring and code logic, to make sure that everything is working properly. Connecting the flame sensors is very easy, just connect the VCC, and GND of the sensors to the VCC, and GND of PICO respectively, then connect the output pins as follows:
- D0 (right flame sensor) → A0 (PICO)
- D0 (middle flame sensor) → A1 (PICO)
- D0 (left flame sensor) → A2 (PICO)
Step 2: Coding PICO With the Flame Sensors
Now that we have our flame sensors connected to PICO, let's start coding so that we know which flame sensor has a flame in front of, and which doesn't.
- Set PICO's A0, A2, and A3 pins as INPUT pins
- Read each sensor output value
- Print each sensor output value on the serial monitor, so that we can diagnose if everything is working properly or not.
Please note that our sensors, have a low reading "0" when they sense fire, and a high reading "1" when they don't sense fire.
To test your code, open your serial monitor and look at how it changes when you have fire in front of it, compared to when it does. The images attached have the readings for not having a flame at all, and the readings of a single flame in front of the middle sensor.
Step 3: Connecting the Fan
To make a fire fighting robot effective it must have the ability to fight fire, and for that we are going to create a fan that we aim at the fire and put it out with. And we're going to create this fan by using a small DC motor with a propeller installed on it.
So, let's start by connecting our DC motors. DC motors have a high current draw, thus we can't directly connect them to our PICO, as it only can offer 40 mA per GPIO pin, while the motor needs 100 mA. This is why we must use a transistor to connect it, and we'll be using the TIP122 Transistor, as we can use it to raise the current provided by our PICO to the amount needed by the motor.
We are going to add our DC motor and an external "PLACE HOLDER" battery, to provide the motor with the needed power without harming our PICO.
The DC motor should be connected as follows:
- Base pin (TIP122) → D0 (PICO)
- Collector pin (TIP122) → DC motor lead "DC motors do not have polarities, so it doesn't matter which lead"
- Emitter pin (TIP122) → GND
- The DC motor's empty lead → Positive (red wire) of the external battery
Don't forget to connect the GND of the battery with the GND of the PICO, as if it's not connected, the circuit will not work at all.
The fan's code logic: the code is very simple, we'll just modify the code we already have to turn on the fan when the reading of the middle sensor is high, and turn the fan off when the middle sensor's reading is low.
Step 4: Connecting the Robot Car Motors
Now that our robot can detect fires, and can put them out with a fan when the fire is directly in front of it. It is time to give the robot the ability to move and position it self directly in front of the fire, so it can put it out. We are already using our 2WD robot chassis kit, which comes with 2 geared DC that we are going to use.
To be able to control the DC motor's running speed and direction you need to use the L298N H-bridge motor driver, which is a motor driver module that has the ability to control the motor's running speed and direction, with the ability to feed the motors from an external power source.
The L298N motor driver needs 4 digital inputs to control the motors' rotation direction, and 2 PWM inputs to control the motors' rotation speed. But unfortunately, PICO only has a single PWM output pin that can't control both the direction and speed of the motor's rotation. This is where we use the PCA9685 PWM pins expansion module to increase PICO's PWM to fit our needs.
Wiring now got a bit trickier, as we are connecting 2 new motors along with 2 modules to control them. But, that will not be a problem if you follow the provided schematics and steps:
Let's start with the PCA9685 PWM module:
- Vcc (PCA9685) → Vcc (PICO)
- GND (PCA9685) → GND
- SDA ((PCA9685) → D2 (PICO)
- SCL (PCA9685) → D3 (PICO)
Now, let's connect the L298N motor driver module:
Let's start by connecting it to our power source:
- +12 (L298N module) → Positive red wire (battery)
- GND (L298N module) → GND
To control the motors' rotation direction:
- In1 (L298N module) → PWM 0 pin (PCA9685)
- In2 (L298N module) → PWM 1 pin (PCA9685)
- In3 (L298N module) → PWM 2 pin (PCA9685)
- In4 (L298N module) → PWM 3 pin (PCA9685)
To control the motor's rotation speed:
- enableA (L298N module) → PWM 4 pin (PCA9685)
- enableB (L298N module) → PWM 5 pin (PCA9685)
The L298N motor driver can output a regulated +5 volts, which we'll be using to power up our PICO:
- +5 (L298N module) → Vin (PICO)
Don't connect this pin if PICO is powered up via USB.
Now that we have everything connected, we'll program the robot to move itself to directly face the flame and turn on the fan.
Step 5: Finishing Up the Code
Now that we have everything connected properly, it is time to code it so it works as well. And these are the things that we want our code to accomplish:
- If it senses fire straight ahead (the middle sensor senses the fire), then the robot moves right towards it until it reaches the set distance and turns on the fan.
- If it senses fire to the right side of the robot (the right sensor senses the fire), then the robot rotates until the fire is right in front of the robot (the middle sensor), then moves towards it until it reaches the set distance and turns on the fan.
If it senses fire to the left side of the robot, it will do the same as above. But, it will turn to the left instead of right.
And if it doesn't sense any fire at all, all of the sensors will output HIGH value, stopping the robot.
Step 6: You Are Done!
In this project, we've learned how to read sensor output and take action depending on it, how to use the Darlington transistor with DC motors, and how to control DC motors. And we used all of our knowledge to create a firefighting robot as an application. Which is pretty cool x)
Please don't hesitate to ask any questions you might have in the comments or on our website mellbell.cc. And as always, keep making :)