0% found this document useful (0 votes)
11 views3 pages

LKKK

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

LKKK

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ARDUINO CODE

#include <SoftwareSerial.h>

// Pin for fire sensor (analog or digital, here A0 for analog)

const int fireSensorPin = A0;

// GSM module RX and TX pins

SoftwareSerial gsmSerial(10, 11); // RX, TX for communication with GSM module

// Fire detection threshold

const int fireThreshold = 600; // Set this value according to your sensor

// Phone number to call

const String phoneNumber = "+9068355399"; // Replace with the actual number

void setup() {

// Start serial communication for debugging

Serial.begin(9600);

gsmSerial.begin(9600); // Initialize GSM serial

pinMode(fireSensorPin, INPUT);

Serial.println("Fire Detection System Initialized");

delay(1000);

}
void loop() {

int fireLevel = analogRead(fireSensorPin); // Read fire sensor value

// Debugging value for fire sensor

Serial.print("Fire Sensor Value: ");

Serial.println(fireLevel);

// Check if fire is detected (based on threshold)

if (fireLevel > fireThreshold) {

Serial.println("Fire detected! Calling emergency contact...");

callEmergencyNumber();

delay(30000); // Wait 30 seconds before next reading

} else {

Serial.println("No fire detected.");

delay(1000); // Delay for a while before reading again

// Function to call the emergency number using GSM module

void callEmergencyNumber() {

gsmSerial.println("ATD" + phoneNumber + ";"); // Dial the number

delay(1000);

gsmSerial.println("ATH"); // Hang up after a delay (you can leave out if you want to auto-end)

delay(1000);

}
Explanation of the Code:

1. Fire Detection Logic:


o The fire sensor value is read via the analogRead() function (assuming you're
using an analog fire sensor).
o If the sensor value exceeds a certain threshold (i.e., fire detected), the system will
initiate a call.
2. GSM Communication:
o A SoftwareSerial instance is used to communicate with the GSM module on
pins 10 and 11.
o The callEmergencyNumber() function uses the AT command ATD to dial the
specified phone number and ATH to hang up after the call (you can adjust the logic
for manual hang-up or automatic call management).
3. Threshold Value:
o The fireThreshold is a value that you need to adjust based on your sensor's
sensitivity and the environment's lighting conditions. You can test this by printing
out the sensor value and adjusting accordingly.

GSM Module AT Commands:

 ATD<PhoneNumber>; : Dial the given phone number.


 ATH : Hang up the call.

Testing and Adjustments:

 After uploading the code, monitor the serial output in the Arduino IDE to check if the fire
sensor is working properly.
 You may need to tweak the threshold value depending on how sensitive your fire sensor
is and the conditions in which you're testing it.

Important Notes:

 Power Supply: The GSM module requires a stable power supply, so make sure you are
using a dedicated power source if needed (e.g., a separate 5V supply).
 GSM Module Activation: Some GSM modules might need to initialize the network
before dialing. You might need to include additional AT commands (like AT+CSQ to
check signal strength) depending on your module's behavior.

You might also like