So after 3 days of banging my head against the wall here is the issue. I have a voltage input on pin A0 then once that voltage goes above 2 turn on the relay. I have that part down working great.
Problem is when the voltage spikes its a pulse so the relay is pulsing with the voltage spikes. what i want to happen is once the spike is seen hold the relay on for 15 min then shut off and watch for another spike.
I have messed around with delay() millis() and a few others i just dont have a strong enough grasp on placement and or how to use them. ANY help or direction would be amazing.
const int RELAY = 3;
const int BUTTON = A0;
const float VOLTAGE_THRESHOLD = 1.5;
void setup() {
Serial.begin(9600);
pinMode(RELAY, OUTPUT);
}
void loop() {
int analogValue = analogRead(BUTTON); // read the input on analog pin
float voltage = floatMap(analogValue, 0, 1023, 0, 5);
if(voltage < VOLTAGE_THRESHOLD)
digitalWrite(RELAY, HIGH); // relay on
if(voltage > VOLTAGE_THRESHOLD)
digitalWrite(RELAY, LOW); //relay off
}
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}