Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Configure pin numbers to what chip you are using
- int vHigh = 4; //Led pin for voltage over 13V
- int vLow = 3; //Led pin for voltage below 13V
- int vIn = A0; //Analog voltage input from voltage divider
- int Relay = 2; //Output to relay
- int Good = 4; //((Vout = Vin*R2/(R1 + R2)) Good = (Vout*(5.0/1023.0)))
- // put your setup code here, to run once
- void setup() {
- pinMode(vHigh, OUTPUT); //Set vHi to output
- pinMode(vLow, OUTPUT); //Set vLow to output
- pinMode(Relay, OUTPUT); //Set Relay to output
- pinMode(vIn, INPUT); //Set vIn to input
- }
- // put your main code here, to run repeatedly
- void loop() {
- int AV = analogRead(vIn); //Read vIn and set AV
- float Voltage = AV * (5.0/1023.0); //Covert analog reading to a voltage
- if(Voltage >= Good){ //If the analog read is equeal to or greater than the (Good) voltage
- digitalWrite(vHigh, HIGH); //Turn on good voltage led
- digitalWrite(vLow, LOW); //Turn off low voltage led
- digitalWrite(Relay, HIGH); //Turn on relay
- }
- else { //If the analog read is anything else
- digitalWrite(vHigh, LOW); //Turn off good voltage led
- digitalWrite(vLow, HIGH); //Turn on low voltage led
- digitalWrite(Relay, LOW); //Turn off relay
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement