I'm trying to control a pump using 2 level sensors. The working conditions are as follow;
low sensor unblock and high sensor unblock -> do nothing
low sensor block and high sensor unblock -> do nothing
low sensor block and high sensor block -> turn on the pump until the low sensor is unblock.
My code is the follow but i'm having problems with the condition do while. Any suggestions?
int pump = 11;
int highsen = 7;
int lowsen = 8;
int highsig;
int lowsig;
void setup() {
pinMode(highsen, INPUT);
pinMode(lowsen, INPUT);
pinMode(pump, OUTPUT);
}
void loop() {
highsig = digitalRead(highsen);
lowsig = digitalRead(lowsen);
if ( lowsig == 0 & highsig == 0) //both unblocked
{
digitalWrite(pump, LOW);
}
if ( lowsig == 1 && highsig == 0) //lower one unblocked and upper one blocked
{
digitalWrite(pump, LOW);
}
if ( lowsig == 0 & highsig == 1) //lower one blocked and upper one unblocked
{
digitalWrite(pump, LOW);
}
if (lowsig == 1 & highsig == 1) //both blocked
{
do{digitalWrite(pump, HIGH);} while(lowsig == 1);
}
}
From your logic description It's not clear whether the pump shall fill or empty the container.
Make it simpler: if the Start (high?) sensor is active start the pump, and if the other sensor is active stop the pump. Else do nothing. No while required.
Can you please post a circuit diagram of your project?
A picture of a hand drawn circuit will be fine, please include pin and component labels as well as your power supply.
How have you got your sensors wired?
Are you using pullup or pulldown resistors on the signal line?
Hi, Sorry for my grammar mistakes. I'm using 2 reflective sensors to monitor an air bag. When the the bag is completely filled (2 sensors are block), it's necessary to activate the pump to compress it until the low sensor is unblock (the air bag needs to mantain certain volume).
Thank you so much John. That's exactly what I tried to do. I'm self-learning to program on arduino, so I was stuck (It seems that I still have a lot to learn).