/* ===========================================================
SHOP VAC AUTOMATION
->> CONNECT RELAYS IN TO DIGITAL OUTPUT 02 + VCC + GROUND
RELAY INTERRUPTS SHOP VAC POWER CORD
->> CONNECT ACS712 30A TO ANALOG INPUT A0 + VCC + GROUND
ACS712 MUST SENSE ON THE MAIN FUSE BOX
==============================================================*/
const int analogIn = A0;
int mVperAmp = 66; // use 185 for 5A, 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
const int pinRelay = 2;
double Amps1 = 0;
double Amps2 = 0;
double Amps3 = 0;
double Amps4 = 0;
double Amps5 = 0;
void setup(){
Serial.begin(9600);
pinMode (pinRelay, OUTPUT);
}
void loop(){
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps1 = abs((Voltage - ACSoffset) / mVperAmp);
Amps5 = Amps4; // that's just for the timing to turn off, aproximately 20 sec.
Amps4 = Amps3;
Amps3 = Amps2;
Amps2 = Amps1;
Amps = max(Amps1, Amps2);
Amps = max(Amps, Amps3);
Amps = max(Amps, Amps4);
Amps = max(Amps, Amps5);
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,2); // the '2' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.print(Amps,2); // the '2' after voltage allows you to display 3 digits after decimal point
if ( Amps > 6.8 ) // change value here whit the value of the machine you want to use for ( for more than one, use the lower value)
{ digitalWrite( pinRelay, HIGH); // over 6.8 Amp activates the relay
Serial.println(" High");
delay (5000); // wait 5 seconds
}
if ( Amps < 6.8 )
{digitalWrite( pinRelay, LOW); // under 6.8 Amp the relay turns off
Serial.println(" Low");
}
delay(500);
}
Comments
Please log in or sign up to comment.