Go Down

Topic: EEPROM problem (Read 1 time) previous topic - next topic

Harnam Thakur

When the system is commissioned for the first time. The tank is empty , if led1,2,3, which are suppose to indicate the level of the water are ON and pump is not starting to fill up the tank.

johnwasser


When the system is commissioned for the first time. The tank is empty , if led1,2,3, which are suppose to indicate the level of the water are ON and pump is not starting to fill up the tank.


I don't know what you mean by 'commissioned for the first time'.

You have not given enough information for me to understand what you want done different.

Are the three 'buttons' actually water level sensors?  If so I can understand why you want the pump to start wen the tank is empty (all three level sensors LOW) and stop when the tank is full (all three level sensors HIGH).  It also makes some sense that once the pump has started you want the pump to continue to run after a power failure, even if the tank is partly full.  I don't understand what else you want that is different.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Harnam Thakur

Quote
Are the three 'buttons' actually water level sensors?  If so I can understand why you want
the pump to start wen the tank is empty (all three level sensors LOW) and stop when the tank is
full (all three level sensors HIGH).  It also makes some sense that once the pump has started you
want the pump to continue to run after a power failure, even if the tank is partly full.


Yes Sir,You are absoletly right.Now the situation is that when the tank is empty the level leds
are ON which means Tank is full and pump does not start.

johnwasser


Now the situation is that when the tank is empty the level leds are ON which means Tank is full and pump does not start.


The level LEDs are ON because the level sensors are reading HIGH.  Why are the level sensors reading HIGH when the tank is EMPTY?!?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Harnam Thakur


Thank you very much Mr. johnwasser
You have saved my day !
Code: [Select]
#include <EEPROM.h>
// constants won't change.
// INPUT PINS
const int buttonPin1 = 3;
const int buttonPin2 = 4;
const int buttonPin3 = 5;


// OUTPUT PINS
const int ledPin1 = 8;
const int ledPin2 = 9;
const int ledPin3 = 10;
const int pumppin = 13;

//EEPROM MEEMORY POSITIONS
#define memposL1 1

// variables will change:
int pumppinstatus = LOW;
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonState3 = LOW;


void setup() {

  // initialize the output pins:
  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_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);

  // Restore pumppin staus from EEPROM
  // check pumppin status

  pumppinstatus=EEPROM.read(memposL1);
  digitalWrite(pumppin,pumppinstatus);
}

void loop(){

  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);

  digitalWrite(ledPin1, !buttonState1);
  digitalWrite(ledPin2, !buttonState2);
  digitalWrite(ledPin3, !buttonState3);

  // If all three buttons are HIGH and pump is running
  if (buttonState1 && buttonState2 && buttonState3 && !pumppinstatus) {
    // Turn the pump off
    pumppinstatus = LOW;
    digitalWrite(pumppin, HIGH);
    EEPROM.write(memposL1, HIGH);
  }

  // If all three buttons are LOW and pump is not running
  if (!buttonState1 && !buttonState2 && !buttonState3 && pumppinstatus) {
    // Turn the pump on
    pumppinstatus = HIGH;
    digitalWrite(pumppin, LOW);
    EEPROM.write(memposL1, LOW);
  }

  delay(100);
}

This code has solved the problem.

Go Up