Hands-on Arduino proto-board and coding practice. Coding of the Sumo-Bots.
/* Arduino Battery Tester
Created: 20/01/2016 By Gus Modified N/A By Gus
http://arduinomylifeup.com/arduino-battery-tester */ int greenLed = 11; int yellowLed = 12; int redLed = 13;
int analogValue = 0; float voltage = 0; int ledDelay = 1000; void setup() { pinMode(greenLed, OUTPUT); pinMode(yellowLed,OUTPUT); pinMode(redLed,OUTPUT); Serial.begin(9600); // start serial for output to local monitor Serial.println(“BATTERY CHECKER”); }
void loop() { analogValue = analogRead(A0); voltage = 0.0048*analogValue;
if( voltage >= 3.0 ) digitalWrite(greenLed, HIGH); else if (voltage > 1.6 && voltage < 3.0) digitalWrite(yellowLed, HIGH); else if( voltage <= 1.6) digitalWrite(redLed, HIGH);
delay(ledDelay); digitalWrite(redLed, LOW); digitalWrite(yellowLed, LOW); digitalWrite(greenLed, LOW); // Send out value to Serial port Serial.println(voltage); delay(1000); }
Hands-on Arduino proto-board and coding practice. Coding of the Sumo-Bots.
/* Arduino Battery Tester
Created: 20/01/2016 By Gus Modified N/A By Gus
http://arduinomylifeup.com/arduino-battery-tester */ int greenLed = 11; int yellowLed = 12; int redLed = 13;
int analogValue = 0; float voltage = 0; int ledDelay = 1000; void setup() { pinMode(greenLed, OUTPUT); pinMode(yellowLed,OUTPUT); pinMode(redLed,OUTPUT); Serial.begin(9600); // start serial for output to local monitor Serial.println(“BATTERY CHECKER”); }
void loop() { analogValue = analogRead(A0); voltage = 0.0048*analogValue;
if( voltage >= 3.0 ) digitalWrite(greenLed, HIGH); else if (voltage > 1.6 && voltage < 3.0) digitalWrite(yellowLed, HIGH); else if( voltage <= 1.6) digitalWrite(redLed, HIGH);
delay(ledDelay); digitalWrite(redLed, LOW); digitalWrite(yellowLed, LOW); digitalWrite(greenLed, LOW); // Send out value to Serial port Serial.println(voltage); delay(1000); }