Yes I calculated the Voltage Hysteresis which is 0.22 when the motor is running at full speed and 0.11 when the motors running at low speed
Now I want to include hysteresis in this code of Battery voltage
/BATTERY READINGS VARIABLES
const int Battery = A0;
float Voltage = 0.0; //input battery voltage
float Voltage1 = 0.0; //output voltage for analog pin A0
float R1 = 1590; // R1 =1.590
float R2 = 1000; // R2 =1000
int readValue = 0;
long previousMillis_battery = 0;
byte Bat_start_timer = 0;
int battery_wait;
unsigned long currentMillis = 0;
//BATTERY FUNCTION
void battery(long * previousMillis_battery)
{
readValue = analogRead(Battery);
Voltage1 = (readValue * 5.0) / 1023;
Voltage = Voltage1 / (R2/(R1+R2));
if(Bat_start_timer == 0) battery_wait = 1000;
if(currentMillis - *previousMillis_battery > battery_wait) {
Serial.println(Voltage); Serial.print(",V,"); Serial.print(",Volts,");
*previousMillis_battery = currentMillis;
battery_wait = 1000; Bat_start_timer = 1; }
} // battery FUNCTION END
void setup()
{
Serial.begin(9600);
pinMode(Battery, INPUT);
}
void loop()
{
currentMillis = millis();
battery(&previousMillis_battery);
}
Can anyone help me to add hysteresis which is 0.22 in this code and define voltages greater than 11. 6 volts and less than 11.6 volts ?