Hello there !
In the following code, I am having problem with the pumppin led when the power is restored.
The following are the working requirement and it is working OK
1.When all the three buttonPins(1,2,3) are OFF its corresponding leds are also OFF
and pumppin led is ON
2.When all buttonPins(1,2,3) are ON, its corresponding leds are also ON and pumppin led is OFF
Now I added EEPROM function to remember the pumpin led status so that in case of
power failure it remembers the pumppin status when the power is restored and switch ON/OFF
the pumppin led accordingly.
All the buttonPins are turning ON and OFF, its corresponding leds (working OK)
Removed the power from the system when pumpin led, led1 & led2 were ON
Restored the power to the system when only led1 was ON, the pumppin led also ON (working OK)
when the buttonPin3 was switches ON all the leds (led1,2,3) are ON and pumppin led is turned OFF,
(working OK)
When buttonPin3 is turned OFF, led3 is also turned OFF, led1 and led2 are ON (working OK)
but pumppin led also turned ON which is abnormal. pumppin led should come ON when
buttonPin 1 is ON.
This problem occurred after the EEPROM statments were added. Please help me to resolve this problem.
#include <EEPROM.h>
// constants won't change.
// INPUT PINS
#define buttonPin1 3
#define buttonPin2 4
#define buttonPin3 5
// OUTPUT PINS
#define ledPin1 8
#define ledPin2 9
#define ledPin3 10
#define pumppin 13
//EEPROM MEEMORY POSITIONS
#define memposL1 1
// variables will change:
int pumppinstatus =0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
void setup() {
// initialize the pushbutton pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(pumppin, OUTPUT);
// pinMode(ledPin5, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
//Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(buttonPin1,HIGH);
digitalWrite(buttonPin2,HIGH);
digitalWrite(buttonPin3,HIGH);
//Restore pumppin staus from EEPROM
//check pumppin status
pumppinstatus=EEPROM.read(memposL1);
if(pumppinstatus=1){
digitalWrite(pumppin,HIGH);
}
if(pumppinstatus=0){
digitalWrite(pumppin,LOW);
}
}
void loop(){
buttonState1 = digitalRead(buttonPin1);// read the state of the pushbutton value:
if (buttonState1 == LOW) { // check if the pushbutton is pressed.:
digitalWrite(ledPin1, HIGH); // turn LED on:
delay(100);
}
else {
digitalWrite(ledPin1, LOW); // turn LED off:
delay(100);
}
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == LOW) {
digitalWrite(ledPin2, HIGH);
}
else {
digitalWrite(ledPin2, LOW);
}
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 == LOW) {
digitalWrite(ledPin3, HIGH);
}
else {
digitalWrite(ledPin3, LOW);
}
if (buttonState1 == LOW) { // check if the pushbutton is pressed.
digitalWrite(pumppin, HIGH); // turn LED on:
}
if (((buttonState1 == LOW)&&(buttonState2 == LOW)&&(buttonState3 == LOW)))
{ // check if the pushbutton is pressed.
digitalWrite(pumppin, LOW); // turn LED on:
}
if (buttonPin1 == LOW){
EEPROM.write(memposL1,1);
}
if (buttonPin3 == LOW){
EEPROM.write(memposL1,0);
}
}