Hello
Please I'm trying to build fire alarm system with GSM 800l module but it's not working. I connected properly and uploaded the code on the Arduino and all the components indicate light when I connected it to power source but it's not detecting fire but the buzzer keep beeping.
Below was the code I used.
#include <SoftwareSerial.h>
//Alarm reciever's phone number with country code
const String PHONE_1 = "+2348149774052";
const String PHONE_2 = ""; //optional
const String PHONE_3 = ""; //optional
#define rxPin 2
#define txPin 3
SoftwareSerial sim800L(rxPin,txPin);
#define flame_sensor_pin 5
//fire_flag = 0 means no fire detected
boolean fire_flag = 0;
#define buzzer_pin 4
void setup()
{
//Begin serial communication: Arduino IDE (Serial Monitor)
Serial.begin(115200);
//Begin serial communication: SIM800L
sim800L.begin(9600);
pinMode(flame_sensor_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
digitalWrite(buzzer_pin,LOW);
Serial.println("Initializing...");
//Once the handshake test is successful, it will back to OK
sim800L.println("AT");
delay(1000);
sim800L.println("AT+CMGF=1");
delay(1000);
}
void loop()
{
while(sim800L.available()){
Serial.println(sim800L.readString());
}
int flame_value = digitalRead(flame_sensor_pin);
//The fire is detected, trigger Alarm and send sms
if(flame_value == LOW)
{
digitalWrite(buzzer_pin,HIGH);
if(fire_flag == 0)
{
Serial.println("Fire Detected.");
fire_flag == 1;
send_multi_sms();
make_multi_call();
}
}
//No fire is detected, turn OFF Alarm
else
{
digitalWrite(buzzer_pin,LOW);
fire_flag = 0;
}
void send_multi_sms()
{
if(PHONE_1 != ""){
Serial.print("Phone 1: ");
send_sms("Fire is Detected", PHONE_1);
}
if(PHONE_2 != ""){
Serial.print("Phone 2: ");
send_sms("Fire is Detected", PHONE_2);
}
if(PHONE_3 != ""){
Serial.print("Phone 3: ");
send_sms("Fire is Detected", PHONE_3);
}
}
void make_multi_call()
{
if(PHONE_1 != ""){
Serial.print("Phone 1: ");
make_call(PHONE_1);
}
if(PHONE_2 != ""){
Serial.print("Phone 2: ");
make_call(PHONE_2);
}
if(PHONE_3 != ""){
Serial.print("Phone 3: ");
make_call(PHONE_3);
}
}
void send_sms(String text, String phone)
{
Serial.println("sending sms....");
delay(50);
sim800L.print("AT+CMGF=1\r");
delay(1000);
sim800L.print("AT+CMGS=\""+phone+"\"\r");
delay(1000);
sim800L.print(text);
delay(100);
sim800L.write(0x1A); //ascii code for ctrl-26 //Serial2.println((char)26); //ascii code for ctrl-26
delay(5000);
}
void make_call(String phone)
{
Serial.println("calling....");
sim800L.println("ATD"+phone+";");
delay(20000); //20 sec delay
sim800L.println("ATH");
delay(1000); //1 sec delay
}
Below was my wiring diagram.
Please help me
Did you test EACH device, separately, before you combined the whole into a single program? If not, go back and test each device with it's own test code, so you know IT works. As it is now, you do not know which piece is causing problems.
I only tested all the components by using power supply and ensuring that the LED indicator is ON. I'm new to Arduino so I don't know how to test with test code
The buzzer continue beeping anytime I power the whole system meanwhile it's supposed to beep only when flame is detected
Your code doesn't compile.
Please help me on this...
How can I make it compile?
It shows 'compiling...' and 'done uploading' when I uploaded the code on Arduino..
Somehow when you copied it to the forum, it acquired some extra characters that mean I get errors like:
stray '\342' in program
which usually means it was copied or pasted from a web page. Just copy it from the IDE and paste it here in code tags.
#include <SoftwareSerial.h>
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Alarm reciever's phone number with country code
const String PHONE_1 = "+2348149774052";
const String PHONE_2 = ""; //optional
const String PHONE_3 = ""; //optional
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#define rxPin 2
#define txPin 3
SoftwareSerial sim800L(rxPin,txPin);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#define flame_sensor_pin 5
//fire_flag = 0 means no fire detected
boolean fire_flag = 0;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#define buzzer_pin 4
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
void setup()
{
//-----------------------------------------------------------------------------------
//Begin serial communication: Arduino IDE (Serial Monitor)
Serial.begin(115200);
//-----------------------------------------------------------------------------------
//Begin serial communication: SIM800L
sim800L.begin(9600);
//-----------------------------------------------------------------------------------
pinMode(flame_sensor_pin, INPUT);
//-----------------------------------------------------------------------------------
pinMode(buzzer_pin, OUTPUT);
digitalWrite(buzzer_pin,LOW);
//----------------------------------------------------------------------------------
Serial.println("Initializing...");
//Once the handshake test is successful, it will back to OK
sim800L.println("AT");
delay(1000);
sim800L.println("AT+CMGF=1");
delay(1000);
//-----------------------------------------------------------------------------------
}
void loop()
{
while(sim800L.available()){
Serial.println(sim800L.readString());
}
int flame_value = digitalRead(flame_sensor_pin);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//The fire is detected, trigger Alarm and send sms
if(flame_value == LOW)
{
digitalWrite(buzzer_pin,HIGH);
//----------------------------------------------------------------
if(fire_flag == 0)
{
Serial.println("Fire Detected.");
fire_flag == 1;
send_multi_sms();
make_multi_call();
}
//----------------------------------------------------------------
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//No fire is detected, turn OFF Alarm
else
{
digitalWrite(buzzer_pin,LOW);
fire_flag = 0;
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
void send_multi_sms()
{
if(PHONE_1 != ""){
Serial.print("Phone 1: ");
send_sms("Fire is Detected", PHONE_1);
}
if(PHONE_2 != ""){
Serial.print("Phone 2: ");
send_sms("Fire is Detected", PHONE_2);
}
if(PHONE_3 != ""){
Serial.print("Phone 3: ");
send_sms("Fire is Detected", PHONE_3);
}
}
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
void make_multi_call()
{
if(PHONE_1 != ""){
Serial.print("Phone 1: ");
make_call(PHONE_1);
}
if(PHONE_2 != ""){
Serial.print("Phone 2: ");
make_call(PHONE_2);
}
if(PHONE_3 != ""){
Serial.print("Phone 3: ");
make_call(PHONE_3);
}
}
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
void send_sms(String text, String phone)
{
Serial.println("sending sms....");
delay(50);
sim800L.print("AT+CMGF=1\r");
delay(1000);
sim800L.print("AT+CMGS=\""+phone+"\"\r");
delay(1000);
sim800L.print(text);
delay(100);
sim800L.write(0x1A); //ascii code for ctrl-26 //Serial2.println((char)26); //ascii code for ctrl-26
delay(5000);
}
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
void make_call(String phone)
{
Serial.println("calling....");
sim800L.println("ATD"+phone+";");
delay(20000); //20 sec delay
sim800L.println("ATH");
delay(1000); //1 sec delay
}
Simple code like this to confirm that the flame sensor responds as you think it should.
#define flame_sensor_pin 5
void setup()
{
Serial.begin(115200);
pinMode(flame_sensor_pin, INPUT);
}
void loop()
{
int flame_value = digitalRead(flame_sensor_pin);
Serial.println(flame_value);
delay(1000);
}
Then add buzzer code
#define flame_sensor_pin 5
#define buzzer_pin 4
void setup()
{
Serial.begin(115200);
pinMode(flame_sensor_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
}
void loop()
{
int flame_value = digitalRead(flame_sensor_pin);
Serial.println(flame_value);
if (flame_value == LOW)
{
digitalWrite(buzzer_pin, HIGH);
}
else
{
digitalWrite(buzzer_pin, LOW);
}
delay(1000);
}
If the flame sensor and buzzer work as expected, then add the sms code or go and try the code you found and copied. The delay(1000) is only for simple test purposes , and will not be in your final code.
1 Like
Don't make a fire alarm system with Arduino that is for actual life safety application. For a science project, sure. That's it.
1 Like
Okay, I will do that
Thank you
No, it's just for final year project..
Thank you
1 Like
Thank you so much for this... The flame sensor and the buzzer is now working properly but the sim800l is not sending any message. I'm always getting question mark
The below is the image of the message I always get
Sorry for the poor background and quality
The best tutorial I know for the sim800l is
https://lastminuteengineers.com/sim800l-gsm-module-arduino-tutorial/
Pay attention to the power requirements.
Just like with the buzzer and flame sensor you can write simple test code to develop and verify the AT communications with the module.
Good luck.
Thank you so much...
I used test code for it too, but it's still giving me question mark. I changed the sim800l to another one but same thing keep happening...
I will check the tutorial you sent to me, thank you so much
system
Closed
November 10, 2022, 12:29am
16
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.