Hi everybody,
I'm doing a project protection by SMS massage sent to my hand phone when have a change from High to Low at input pin
My input is a contact of relay, common pin / normal open (NO) / normal close (NC). Common in connected to ground, NO and NC is connected to 2 pin input of arduino. Meaning have 1 input is always active, it is NC.
When I test with code below by input change form High to Low and release (likely a button after pressed and release), it is working fine. i received a SMS massage to my hand phone but when I connect input with relay, i always received SMS massage from NC input because it is always LOW until when I energized relay, the contact is change over and state there. I also received another SMS massage from NO contact (changed to closed when relay energized)
So, i need all of you to review the code and help me how to do it. I'm very glad with you with high appreciated to help me
Finally, i just only want to receive 1 SMS for each input when this input go to Low and state there until relay contact change over and resend SMS when the contact is repeat change status.
Here is the code as i'm doing
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8); // connection wiring of SIM800A module with arduino
int buttonPin3=10;
int buttonPin4=11;
// Variables will change:
int buttonState3 = 0; // current state of the button
int lastButtonState3 = 0; // previous state of the button
int buttonState4 = 0; // current state of the button
int lastButtonState4 = 0; // previous state of the button
void setup() {
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
SIM900.begin(9600);
Serial.begin(9600);
Serial.println("press button");
}
void sendSMS3()
{
SIM900.println("AT+CMGF=1"); // AT command to send SMS message
delay(1000);
SIM900.println("AT+CMGS = \"+xxxxxxxxx\"\r"); // recipient's mobile number, in international format
delay(1000);
SIM900.println("confirmed switch 1 is on"); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
}
void sendSMS4()
{
SIM900.println("AT+CMGF=1"); // AT command to send SMS message
delay(1000);
SIM900.println("AT+CMGS = \"+xxxxxxxxxxxx\"\r"); // recipient's mobile number, in international format
delay(1000);
SIM900.println("confirmed switch 2 is on"); // message to send
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
}
void loop() {
// read the pushbutton input pin:
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
if (buttonState3 != lastButtonState3) {
if (buttonState3 == LOW) {
Serial.println("button1 pressed");
delay(2000);
sendSMS3();
}
if (SIM900.available()>0)
Serial.write(SIM900.read());
delay(50);
lastButtonState3 = buttonState3;
}
if (buttonState4 != lastButtonState4) {
if (buttonState4 == LOW) {
Serial.println("button2 pressed");
delay(2000);
sendSMS4();
}
if (SIM900.available()>0)
Serial.write(SIM900.read());
delay(50);
lastButtonState4 = buttonState4;
}
}