Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #define gasPin A0
- #define buzzerPin 12
- SoftwareSerial SIM900A(10, 11);
- int sensorValue = 0;
- void setup()
- {
- pinMode(buzzerPin, OUTPUT);
- pinMode(gasPin, INPUT);
- digitalWrite(buzzerPin, LOW);
- SIM900A.begin(9600);
- Serial.begin(9600);
- Serial.println ("SIM900A Ready");
- delay(15000);
- SendMessage();
- }
- void loop() {
- sensorValue = analogRead(gasPin);
- Serial.println(sensorValue);
- if (sensorValue > 150) {
- SendMessage();
- digitalWrite(buzzerPin, HIGH);
- delay(3000);
- digitalWrite(buzzerPin, LOW);
- delay(1000);
- }
- }
- void SendMessage()
- {
- Serial.println ("Sending Message");
- SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
- delay(1000);
- Serial.println ("Set SMS Number");
- SIM900A.println("AT+CMGS=\"+96658022####\"\r"); //Mobile phone number to send message
- delay(1000);
- Serial.println ("Set SMS Content");
- SIM900A.println("Gas Alert !! Warning!!");// Messsage content
- delay(100);
- Serial.println ("Finish");
- SIM900A.println((char)26);// ASCII code of CTRL+Z
- delay(1000);
- Serial.println ("Message has been sent ->SMS Selesai dikirim");
- }
Advertisement
Add Comment
Please, Sign In to add comment