According to the "Button" example of the Arduino i made the same circuit with only one diference. I replace the button with a Normaly Open (NO) relay contact.
I want the serial monitor give me a feedback in each state. So here is my code which is working perfect in the 1st case
const int buttonPin = 4; // the pin that the pushbutton is attached to
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT); // initialize the button pin as a input
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == 1) {
Serial.println("LED IS ON");
}
else {
Serial.println("LED IS OFF");
}
lastButtonState = buttonState;
}
delay(1000);
}
1 case. With the button everything working fine
2 case. With the NO relay contact it works only once when the relay is energized and the contact is close. Then everything stucks.
i have attached a picture with the circuit diagram.
As the circuit works with the button that means that there is no problem with my code. So is There somethin that i miss in the 2nd circuit?????