Advertisement
EmptySet5150

Beta - Low Voltage shut off

Oct 23rd, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Configure pin numbers to what chip you are using
  2. int vHigh = 4; //Led pin for voltage over 13V
  3. int vLow = 3; //Led pin for voltage below 13V
  4. int vIn = A0; //Analog voltage input from voltage divider
  5. int Relay = 2; //Output to relay
  6. int Good = 4; //((Vout = Vin*R2/(R1 + R2)) Good = (Vout*(5.0/1023.0)))
  7.  
  8. // put your setup code here, to run once
  9. void setup() {
  10.   pinMode(vHigh, OUTPUT); //Set vHi to output
  11.   pinMode(vLow, OUTPUT); //Set vLow to output
  12.   pinMode(Relay, OUTPUT); //Set Relay to output
  13.   pinMode(vIn, INPUT); //Set vIn to input
  14. }
  15.  
  16. // put your main code here, to run repeatedly
  17. void loop() {
  18.   int AV = analogRead(vIn); //Read vIn and set AV
  19.   float Voltage = AV * (5.0/1023.0); //Covert analog reading to a voltage
  20.   if(Voltage >= Good){ //If the analog read is equeal to or greater than the (Good) voltage
  21.     digitalWrite(vHigh, HIGH); //Turn on good voltage led
  22.     digitalWrite(vLow, LOW); //Turn off low voltage led
  23.     digitalWrite(Relay, HIGH); //Turn on relay
  24.   }
  25.   else { //If the analog read is anything else
  26.     digitalWrite(vHigh, LOW); //Turn off good voltage led
  27.     digitalWrite(vLow, HIGH); //Turn on low voltage led
  28.     digitalWrite(Relay, LOW); //Turn off relay
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement