I build a charger for my battery, connected to relay and everything work.
but I am confused about using "IF" in my code, I have a rechargeable lithium battery 3.7V
}
if (v2 <= 2.1) { digitalWrite (2,HIGH);
}
else if (v2 >= 3.4) { digitalWrite (2,LOW);
}
So from my code if the battery under 2V the relay will connect the charger.
but what if the charger start charging at 2.1 , if the battery is 2.2 the charger will stop again!!!!
This is my full code
sorry i made an update for the main question to be more clear, i build a small circuit "voltmeter" and call it V2 in my code so V2 is the voltage value to my battery
}
if (v2 <= 2.1) { digitalWrite (2,HIGH);
}
else if (v2 >= 3.4) { digitalWrite (2,LOW);
}
ok what about this case:
battery under or equal 2.1V so the relay will connect the charger.
but when the battery is 2.2V the relay will stop again and enter in infinity loop!! so my code will be stuck between 2.1V - 2.2V
or i am understand it wrong !
pin2 to relay, you can read my full article on my blog
if you want to know how exactly my circuit work, i am still working in my code i know the code not make sense for that i am asking
You need a (series of) compound if statement(s).
If the voltage is low OR the thermistor is low, turn the pin on.
If the voltage is good AND the thermistor is good, do nothing.
If the voltage is high OR the thermistor is high, turn the pin off.
You do NOT want to turn the pin on because the thermistor is low and then immediately turn it off because the voltage is good.