Hello there !
In the following sketch, I was using three reed switches and only one magnetic float(when the magnetic float was traveling upwards and downwards, it was making and breaking the reed switches) , now I want to use three separate magnetic float switches (each switch will have its own reed switch and magnetic float)
What modifications, I need to do in the functions in this sketch?
Thanks
#include <EEPROM.h>
// INPUT PINS
#define Buttonpin1 2 //Tank Level1
#define Buttonpin2 3 //Tank Level2
#define Buttonpin3 4 //Tank Level3
#define Auto_Man_Buttonpin 5 //Auto/manual button
// OUTPUT PINS
#define LED1 8 //Tank1 Level1 Display
#define LED2 9 //Tank1 Level2 Display
#define LED3 10 //Tank2 Level1 Display
#define Auto_Man_Led 6 //Auto/manual operation
#define Pumppin 7 // Pin for water pump activation
// EEPROM MEMORY POSITIONS
#define memposL1 0 // set constant eeprom position 0 to save Level
// variables
int state=0;
int level = 0;
int lastlevel = 0;
void setup (){
// INPUTS
pinMode(Auto_Man_Buttonpin,INPUT); // default mode is INPUT
pinMode(Buttonpin1,INPUT); // default mode is INPUT
pinMode(Buttonpin2,INPUT); // default mode is INPUT
pinMode(Buttonpin3,INPUT); // default mode is INPUT
digitalWrite(Auto_Man_Button, HIGH); // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(Buttonpin1, HIGH); // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(Buttonpin2, HIGH); // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(Buttonpin3, HIGH); // Turn on the internal pull-up resistor, default state is HIGH
// OUTPUTS
pinMode(Pumppin, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(Auto_Man_Led, OUTPUT);
pinMode(LED3, OUTPUT);
// Restore tank water Level from eeprom
level = EEPROM.read(memposL1); // Read from eeprom memPos1 the value of Level1
lastlevel = level; // also update the according lastLevel variable
if ((level == 0)||(level>3)) // if eeprom has illegal value
{
level=1; // set level to 1 (minimum)
updateprom(); // call updateprom function to set eeprom memory value to minimum too.
}
setleds(); // restore the reed states from EEPROM stored value.
delay(1000);
startstoppump();
}
// FUNCTION THAT SETS THE LEDS ACCORDING TO LEVEL VARIABLE WHENEVER CALLED
void setleds()
{
digitalWrite(LED1, LOW );
digitalWrite(LED2, LOW );
digitalWrite(LED3, LOW );
if (level > 0) digitalWrite(LED1, HIGH );
if (level > 1) digitalWrite(LED2, HIGH );
if (level > 2) digitalWrite(LED3, HIGH );
}
// FUNCTION THAT CONTROLS THE PUMP OPERATION ACCORDING TO WATER LEVEL AND AUTO_MAN SETTING
void startstoppump(){
if (level < 3) digitalWrite(Pumppin, HIGH );
if ((level == 3) & (state == 0))
{
digitalWrite(Pumppin, LOW );
}
else
{
digitalWrite(Pumppin, HIGH );
}
}
// FUNCTION THAT UPDATES EEPROM AT EACH LEVEL CHANGE
void updateprom()
{ // UPDATE LEVEL 1
lastlevel = level; // update lastLevel variable
EEPROM.write(memposL1, level); // and store new Level value to eeprom
}
// MAIN LOOP
void loop ()
{
// TOGGLE AUTO/MANUAL MODE
if ( (digitalRead(Auto_Man_Buttonpin) == LOW) & (state == 0) )
{ // Button pushed
state=1;
digitalWrite(Auto_Man_Led, state ); // Turn on the LED
startstoppump();
delay(400);
}
if ( (digitalRead(Auto_Man_Buttonpin) == LOW) & (state == 1) )
{ // Button pushed
state=0;
digitalWrite(Auto_Man_Led, state ); // Turn off the LED
startstoppump();
delay(400);
}
//END OF TOGGLE AUTO/MANUAL MODE
// CHECK WATER LEVEL
if ( digitalRead(Buttonpin1) == LOW )
{ // Button pushed
level = 1;
}
if ( digitalRead(Buttonpin2) == LOW )
{ // Button pushed
level = 2;
}
if ( digitalRead(Buttonpin3) == LOW )
{ // Button pushed
level = 3;
}
//END OF CHECK WATER LEVEL
// IF WATER LEVEL CHANGED AND CALL THE NECESSARY FUNCTIONS.
if (level != lastlevel)
{
setleds();
startstoppump();
updateprom();
}
} // END OF MAIN LOOP