Created
November 28, 2023 12:55
-
-
Save Eboubaker/dacb82ff2ac44ed44165f806df051d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SoftwareSerial.h> | |
#define ON HIGH | |
#define OFF LOW | |
SoftwareSerial SIM900A(10, 11); // RX, TX pins | |
String textMessage; | |
String pumpState; | |
const int pumpPin = 12; // pump connected to pin 12 | |
void setup() { | |
pinMode(pumpPin, OUTPUT); // configure pin 12 as OUTPUT | |
digitalWrite(pumpPin, ON); // set current state of the pump to ON | |
Serial.begin(9600); // bitrate speed 9600 | |
SIM900A.begin(9600); // must be the same | |
SIM900A.print("AT+CMGF=1\r\n"); // set GSM to text format | |
SIM900A.print( | |
"AT+CNMI=2,2,0,0,0\r\n"); // NewMessageIndicator: notify micro-controller | |
// and store message on sim memory | |
} | |
void loop() { | |
textMessage = ""; | |
if (SIM900A.available() > 0) { // new message exist? | |
textMessage = SIM900A.readString(); | |
} | |
if (textMessage == "ON") { | |
// If "ON" is sent the pumps will turn on | |
digitalWrite(pumpPin, ON); | |
pumpState = "ON"; | |
SIM900A.println( | |
"AT+CMGS=\"+2137979213070\""); // number with international code | |
SIM900A.print("Pump is ON.\r"); | |
SIM900A.write(26); // 26 means execute send SMS message | |
} | |
if (textMessage == "OFF") { | |
digitalWrite(pumpPin, OFF); | |
pumpState = "OFF"; | |
SIM900A.println( | |
"AT+CMGS=\"+2137979213070\""); /// RECEIVER: the phone number | |
SIM900A.print("Pump is OFF.\r"); | |
SIM900A.write(0x1a); // 26 means execute send SMS message | |
} | |
if (textMessage == "STATUS") { | |
SIM900A.print("AT+CMGF=1"); | |
SIM900A.println( | |
"AT+CMGS=\"+2137979213070\""); /// RECEIVER: the phone number | |
String message = "Pump is " + pumpState; | |
SIM900A.println(message); | |
SIM900A.write(0x1a); // 26 means execute send SMS message | |
} | |
delay(1000); // wait 1 second(1000ms) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment