Hey guys I'm having a bit of a trouble with my code. I can't figure out why the first if statement in my code below is not working correctly. I've tried to make it a while statement but that didn't work either.
I have a pro mini 5v controlling a 4, relay break out board.
The first if statement is suppose to read a voltage on pin A1 and and if it exceeds the threshold, it turns the relay on for 2.5 seconds, then off after that.
Another question I have is how to make that if statement only run once? To give a little background....I'm using this relay as a turn on controller for a carpc. The WL trigger is actually my interior lighting. I plan on tapping 12v off an interior light, then using a 12v-5v invertor for say a cell phone to step the voltage down for use with the arduino pin A1. I'm hoping this will allow me to use something like this:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) //WL fade speed on
analogWrite(AEDrivers, fadeValue);
to fade the drivers for my LED angel eyes on for welcome lighting. So I'd like to control the drivers as well as the relay with the if statement or another type of statement. But the relay only needs to run once per, say 5-10 minutes.
Any help is appreciated. Thanks in advanced!
const int IGN = A1; //Ingition trigger for AE DRL/CarPC Charger
const int WL = A3; //Interior lighting trigger for welcome lighting
const int RELAY1 = 6; //CarPC Start, hold 2.5 seconds
const int RELAY2 = 7; //CarPC Charger
const int RELAY3 = 8; //AE 12v supply
//Pin to control AE Drivers
//Threshold for triggers
void setup()
{
//Alters PWM Frequency
pinMode(IGN, INPUT);
pinMode(WL, INPUT);
pinMode(RELAY1, OUTPUT); //Sets assigned pins as outputs
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
digitalWrite(RELAY1, HIGH); //Sets relays to off on startup
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, HIGH);
}
void loop() //Relay Control Program
{
int WLValue = analogRead(WL); //Reads WL Voltage
int IGNValue = analogRead(IGN); //Reads IGN voltage
int threshold = 400;
if (WLValue > threshold)
{
digitalWrite(RELAY1, LOW);
delay(2500);
digitalWrite(RELAY1, HIGH);
}
if (IGNValue > threshold)
{
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
delay(1000);
}
else (IGNValue < threshold);
{
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, HIGH);
}
}