#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(3, 2); // RX, TX pins for the GSM module
const int inputPin1 = 4;
const int inputPin2 = 5;
const int inputPin3 = 6;
const int outputPinRed = 9;
const int outputPinYellow = 10;
const int outputPinBlue = 11;
const int checkPin = 8;
String receivedMessage = "";
String phoneNumbers[] = {
"+1234567890", // Replace with the first phone number
"+9876543210" // Replace with the second phone number
};
int numPhoneNumbers = sizeof(phoneNumbers) / sizeof(phoneNumbers[0]);
void setup() {
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
pinMode(inputPin3, INPUT);
pinMode(outputPinRed, OUTPUT);
pinMode(outputPinYellow, OUTPUT);
pinMode(outputPinBlue, OUTPUT);
pinMode(checkPin, INPUT);
digitalWrite(outputPinRed, LOW);
digitalWrite(outputPinYellow, LOW);
digitalWrite(outputPinBlue, LOW);
Serial.begin(9600);
gsmSerial.begin(9600);
sendSMS("System initialized.");
}
void loop() {
while (gsmSerial.available()) {
char receivedChar = gsmSerial.read();
receivedMessage += receivedChar;
delay(10);
if (receivedChar == '\n') {
processMessage(receivedMessage);
receivedMessage = "";
}
}
}
void processMessage(String message) {
message.trim(); // Remove leading/trailing whitespaces
if (message == "red") {
digitalWrite(outputPinYellow, LOW);
digitalWrite(outputPinBlue, LOW);
delay(1000);
digitalWrite(outputPinRed, HIGH);
sendSMS("Relay turned on: RED");
checkPinStatus();
} else if (message == "yellow") {
digitalWrite(outputPinRed, LOW);
digitalWrite(outputPinBlue, LOW);
delay(1000);
digitalWrite(outputPinYellow, HIGH);
sendSMS("Relay turned on: YELLOW");
checkPinStatus();
} else if (message == "blue") {
digitalWrite(outputPinRed, LOW);
digitalWrite(outputPinYellow, LOW);
delay(1000);
digitalWrite(outputPinBlue, HIGH);
sendSMS("Relay turned on: BLUE");
checkPinStatus();
} else if (message == "status") {
String status = "Showing status of input side: ";
if (digitalRead(inputPin1) == HIGH) {
status += "Red phase is high ";
} else {
status += "Red phase is low ";
}
if (digitalRead(inputPin2) == HIGH) {
status += "Yellow phase is high ";
} else {
status += "Yellow phase is low ";
}
if (digitalRead(inputPin3) == HIGH) {
status += "Blue phase is high ";
} else {
status += "Blue phase is low ";
}
sendSMS(status);
} else {
sendSMS("Invalid command.");
}
}
void sendSMS(String message) {
gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
delay(100);
for (int i = 0; i < numPhoneNumbers; i++) {
gsmSerial.print("AT+CMGS=\"");
gsmSerial.print(phoneNumbers[i]);
gsmSerial.println("\"");
delay(100);
gsmSerial.println(message);
delay(100);
gsmSerial.println((char)26); // End message
delay(1000);
}
}
void checkPinStatus() {
// Check if digital pin 8 is high
if (digitalRead(checkPin) == HIGH) {
sendSMS("Digital pin 8 is high.");
} else {
sendSMS("Digital pin 8 is not high.");
}
}
When the system is turned on, "System initialized" message is received via sms. But other sms functions are not working