pleasedontcode

Flame Alarm rev_01

Dec 6th, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Flame Alarm
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-12-06 20:09:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* i am not getting alert sms on phone via sms */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void sendSMS(String message, String phone);
  33. void send_multi_sms(String message);
  34. void make_call(String phone);
  35. void make_multi_call();
  36.  
  37. const String PHONE_1 = "+919468881616";
  38. const String PHONE_2 = ""; //optional
  39. const String PHONE_3 = ""; //optional
  40. const String PHONE_4 = ""; //optional
  41.  
  42. #define rxPin 4
  43. #define txPin 3
  44. SoftwareSerial sim800L(rxPin, txPin);
  45.  
  46. String textMessage;
  47. String lampState = "off";
  48. const int relay1 = 8;
  49. const int relay2 = 10;
  50. #define flame_sensor_pin 2
  51.  
  52. boolean fire_flag = 0;
  53.  
  54. #define buzzer_pin 5
  55.  
  56. void setup()
  57. {
  58.   pinMode(9, OUTPUT);
  59.   digitalWrite(9, HIGH);
  60.   delay(1000);
  61.   digitalWrite(9, LOW);
  62.   delay(5000);
  63.  
  64.   pinMode(relay1, OUTPUT);
  65.   pinMode(relay2, OUTPUT);
  66.   digitalWrite(relay1, LOW);
  67.   digitalWrite(relay2, LOW);
  68.  
  69.   Serial.begin(115200);
  70.   sim800L.begin(9600);
  71.  
  72.   pinMode(flame_sensor_pin, INPUT);
  73.  
  74.   pinMode(buzzer_pin, OUTPUT);
  75.   digitalWrite(buzzer_pin, LOW);
  76.  
  77.   Serial.println("Initializing...");
  78.  
  79.   sim800L.println("AT");
  80.   delay(1000);
  81.   sim800L.println("AT+CMGF=1");       // SMS text mode
  82.   delay(1000);
  83.   sim800L.println("AT+CNMI=2,2,0,0,0"); // New SMS indication
  84.   delay(100);
  85. }
  86.  
  87. void loop()
  88. {
  89.   if (sim800L.available()) {
  90.     textMessage = sim800L.readString();
  91.     Serial.print("Received: ");
  92.     Serial.println(textMessage);
  93.  
  94.     // Check commands in the received message
  95.     if (textMessage.indexOf("On1") >= 0) {
  96.       digitalWrite(relay1, HIGH);
  97.       lampState = "On 1ST RELAY";
  98.       Serial.println("Relay1 set to ON");
  99.       textMessage = "";
  100.     }
  101.     else if (textMessage.indexOf("Off1") >= 0) {
  102.       digitalWrite(relay1, LOW);
  103.       lampState = "OFF 2ND RELAY";
  104.       Serial.println("Relay1 set to OFF");
  105.       textMessage = "";
  106.     }
  107.     if (textMessage.indexOf("On2") >= 0) {
  108.       digitalWrite(relay2, HIGH);
  109.       lampState = "2ND RELAY IS ON";
  110.       Serial.println("Relay2 set to ON");
  111.       textMessage = "";
  112.     }
  113.     else if (textMessage.indexOf("Off2") >= 0) {
  114.       digitalWrite(relay2, LOW);
  115.       lampState = "OFF 2ND RELAY";
  116.       Serial.println("Relay2 set to OFF");
  117.       textMessage = "";
  118.     }
  119.     else if (textMessage.indexOf("STATE") >= 0) {
  120.       String msg = "Lamp is " + lampState;
  121.       send_multi_sms(msg);
  122.       Serial.println("Lamp state requested");
  123.       textMessage = "";
  124.     }
  125.   }
  126.  
  127.   // Flame sensor monitoring
  128.   int flame_value = digitalRead(flame_sensor_pin);
  129.  
  130.   if (flame_value == LOW) // Flame detected (depends on your sensor logic)
  131.   {
  132.     digitalWrite(buzzer_pin, HIGH);
  133.  
  134.     if (fire_flag == 0)
  135.     {
  136.       Serial.println("THEFT DETECTED");
  137.       fire_flag = 1;
  138.       send_multi_sms();
  139.       make_multi_call();
  140.     }
  141.   }
  142.   else
  143.   {
  144.     digitalWrite(buzzer_pin, LOW);
  145.     fire_flag = 0;
  146.   }
  147. }
  148.  
  149. void sendSMS(String message, String phone)
  150. {
  151.   Serial.print("Sending SMS to ");
  152.   Serial.println(phone);
  153.   sim800L.print("AT+CMGF=1\r");
  154.   delay(100);
  155.   sim800L.print("AT+CMGS=\"" + phone + "\"\r");
  156.   delay(1000);
  157.   sim800L.print(message);
  158.   delay(100);  
  159.   sim800L.write(26); // CTRL+Z to send SMS
  160.   delay(5000);
  161. }
  162.  
  163. void send_multi_sms(String message)
  164. {
  165.   if (PHONE_1 != "") { sendSMS(message, PHONE_1); }
  166.   if (PHONE_2 != "") { sendSMS(message, PHONE_2); }
  167.   if (PHONE_3 != "") { sendSMS(message, PHONE_3); }
  168.   if (PHONE_4 != "") { sendSMS(message, PHONE_4); }
  169. }
  170.  
  171. void make_call(String phone)
  172. {
  173.   Serial.print("Calling ");
  174.   Serial.println(phone);
  175.   sim800L.println("ATD" + phone + ";");
  176.   delay(20000); // 20 seconds call
  177.   sim800L.println("ATH"); // Hang up
  178.   delay(1000);
  179. }
  180.  
  181. void make_multi_call()
  182. {
  183.   if (PHONE_1 != "") make_call(PHONE_1);
  184.   if (PHONE_2 != "") make_call(PHONE_2);
  185.   if (PHONE_3 != "") make_call(PHONE_3);
  186.   if (PHONE_4 != "") make_call(PHONE_4);
  187. }
  188.  
  189. /* END CODE */
  190.  
Advertisement
Add Comment
Please, Sign In to add comment