Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Flame Alarm
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-12-06 20:09:12
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* i am not getting alert sms on phone via sms */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void sendSMS(String message, String phone);
- void send_multi_sms(String message);
- void make_call(String phone);
- void make_multi_call();
- const String PHONE_1 = "+919468881616";
- const String PHONE_2 = ""; //optional
- const String PHONE_3 = ""; //optional
- const String PHONE_4 = ""; //optional
- #define rxPin 4
- #define txPin 3
- SoftwareSerial sim800L(rxPin, txPin);
- String textMessage;
- String lampState = "off";
- const int relay1 = 8;
- const int relay2 = 10;
- #define flame_sensor_pin 2
- boolean fire_flag = 0;
- #define buzzer_pin 5
- void setup()
- {
- pinMode(9, OUTPUT);
- digitalWrite(9, HIGH);
- delay(1000);
- digitalWrite(9, LOW);
- delay(5000);
- pinMode(relay1, OUTPUT);
- pinMode(relay2, OUTPUT);
- digitalWrite(relay1, LOW);
- digitalWrite(relay2, LOW);
- Serial.begin(115200);
- sim800L.begin(9600);
- pinMode(flame_sensor_pin, INPUT);
- pinMode(buzzer_pin, OUTPUT);
- digitalWrite(buzzer_pin, LOW);
- Serial.println("Initializing...");
- sim800L.println("AT");
- delay(1000);
- sim800L.println("AT+CMGF=1"); // SMS text mode
- delay(1000);
- sim800L.println("AT+CNMI=2,2,0,0,0"); // New SMS indication
- delay(100);
- }
- void loop()
- {
- if (sim800L.available()) {
- textMessage = sim800L.readString();
- Serial.print("Received: ");
- Serial.println(textMessage);
- // Check commands in the received message
- if (textMessage.indexOf("On1") >= 0) {
- digitalWrite(relay1, HIGH);
- lampState = "On 1ST RELAY";
- Serial.println("Relay1 set to ON");
- textMessage = "";
- }
- else if (textMessage.indexOf("Off1") >= 0) {
- digitalWrite(relay1, LOW);
- lampState = "OFF 2ND RELAY";
- Serial.println("Relay1 set to OFF");
- textMessage = "";
- }
- if (textMessage.indexOf("On2") >= 0) {
- digitalWrite(relay2, HIGH);
- lampState = "2ND RELAY IS ON";
- Serial.println("Relay2 set to ON");
- textMessage = "";
- }
- else if (textMessage.indexOf("Off2") >= 0) {
- digitalWrite(relay2, LOW);
- lampState = "OFF 2ND RELAY";
- Serial.println("Relay2 set to OFF");
- textMessage = "";
- }
- else if (textMessage.indexOf("STATE") >= 0) {
- String msg = "Lamp is " + lampState;
- send_multi_sms(msg);
- Serial.println("Lamp state requested");
- textMessage = "";
- }
- }
- // Flame sensor monitoring
- int flame_value = digitalRead(flame_sensor_pin);
- if (flame_value == LOW) // Flame detected (depends on your sensor logic)
- {
- digitalWrite(buzzer_pin, HIGH);
- if (fire_flag == 0)
- {
- Serial.println("THEFT DETECTED");
- fire_flag = 1;
- send_multi_sms();
- make_multi_call();
- }
- }
- else
- {
- digitalWrite(buzzer_pin, LOW);
- fire_flag = 0;
- }
- }
- void sendSMS(String message, String phone)
- {
- Serial.print("Sending SMS to ");
- Serial.println(phone);
- sim800L.print("AT+CMGF=1\r");
- delay(100);
- sim800L.print("AT+CMGS=\"" + phone + "\"\r");
- delay(1000);
- sim800L.print(message);
- delay(100);
- sim800L.write(26); // CTRL+Z to send SMS
- delay(5000);
- }
- void send_multi_sms(String message)
- {
- if (PHONE_1 != "") { sendSMS(message, PHONE_1); }
- if (PHONE_2 != "") { sendSMS(message, PHONE_2); }
- if (PHONE_3 != "") { sendSMS(message, PHONE_3); }
- if (PHONE_4 != "") { sendSMS(message, PHONE_4); }
- }
- void make_call(String phone)
- {
- Serial.print("Calling ");
- Serial.println(phone);
- sim800L.println("ATD" + phone + ";");
- delay(20000); // 20 seconds call
- sim800L.println("ATH"); // Hang up
- delay(1000);
- }
- void make_multi_call()
- {
- if (PHONE_1 != "") make_call(PHONE_1);
- if (PHONE_2 != "") make_call(PHONE_2);
- if (PHONE_3 != "") make_call(PHONE_3);
- if (PHONE_4 != "") make_call(PHONE_4);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment