WEEK 6 : Smart System and Sensors
This week in the lab, our teacher assigned us kits at random with the task of creating something practical from them. We were instructed to form pairs, and my friend Nelu and I teamed up. Initially, we were provided with the Arduino Flame Sensor for our project.
Let's give a short description of this kit. The flame sensor is a device capable of detecting and measuring the infrared level emitted from a flame, making it useful for fire detection1. It is also known as an infrared flame sensor or fire sensor. The sensor provides two types of outputs: a digital output (LOW/HIGH) and an analog output.
Pinout:
VCC pin: Connect to VCC (3.3V to 5V).
GND pin: Connect to GND (0V).
DO pin: Digital output pin. It is HIGH if the flame is not detected and LOW if detected.
AO pin: Analog output pin. The output value decreases as the infrared level is decreased, and it increases as the infrared level is increased.
In the following video you can see how it works with arduino.
Following that, once our project was functioning correctly, our instructor provided us with a servo motor to integrate with the flame sensor. The concept is that when a fire is detected, the motor will activate, initiating a water system to extinguish the fire in real buildings. Since I covered the details of the servo motor in week 5, let's now demonstrate its functionality.
This is the code we've implemented. I've included explanations within the comments to help you understand its functionality better.
#include <Servo.h>
// Define the pin numbers
const int flameSensorPin = A0; // Analog pin for flame sensor
const int servoPin = 9; // PWM pin for servo motor
// Define threshold value for flame detection
const int flameThreshold = 300; // Adjust this value based on sensor sensitivity
Servo servoMotor; // Create a servo object
void setup() {
Serial.begin(9600); // Initialize serial communication
servoMotor.attach(servoPin); // Attach servo to its pin
}
void loop() {
int flameValue = analogRead(flameSensorPin); // Read flame sensor value
// Check if flame is detected
if (flameValue > flameThreshold) {
Serial.println("Flame detected!"); // Print message to serial monitor
activateServo(); // Call function to activate servo motor
delay(1000); // Wait for 1 second to prevent rapid activation
} else {
Serial.println("No flame detected."); // Print message to serial monitor
}
}
void activateServo() {
// Move servo to a certain angle (e.g., 90 degrees) to open water system
servoMotor.write(90);
delay(5000); // Keep servo activated for 5 seconds
// Move servo back to initial position (e.g., 0 degrees)
servoMotor.write(0);
}
Comments
Post a Comment