Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int LipoType = 0;
- float LowVoltage = 0;
- int analogInput = 0;
- float vout = 0.0;
- float vin = 0.0;
- float R1 = 100000.0; // resistance of R1 (100K) -see text!
- float R2 = 10000.0; // resistance of R2 (10K) - see text!
- int value = 0;
- void setup(){
- pinMode(analogInput, INPUT);
- Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
- Serial.print("Arduino Digital Voltmeter for ZEO OSD");
- Serial.println();
- value = analogRead(analogInput);
- vout = (value * 5.0) / 1024.0; // see text
- vin = vout / (R2/(R1+R2));
- if (vin<0.09) {
- vin=0.0;//statement to quash undesired reading !
- }
- if (vin >13)
- {
- LipoType = 4;
- }
- else if (vin >10)
- {
- LipoType = 3;
- }
- else if (vin >6)
- {
- LipoType = 2;
- }
- else if (vin >2)
- {
- LipoType =1;
- }
- }
- void loop(){
- // read the value at analog input
- value = analogRead(analogInput);
- vout = (value * 5.0) / 1024.0; // see text
- vin = vout / (R2/(R1+R2));
- if (vin<0.09) {
- vin=0.0;//statement to quash undesired reading !
- }
- if (LipoType = 4)
- {
- LowVoltage= vin/4;
- }
- else if (LipoType = 3)
- {
- LowVoltage= vin/3;
- }
- else if (LipoType = 2)
- {
- LowVoltage= vin/2;
- }
- else if (LipoType= 1)
- {
- LowVoltage= vin;
- }
- Serial.print("INPUT V= ");
- Serial.print(vin);
- Serial.println();
- Serial.print(LipoType);
- Serial.print("S");
- Serial.println();
- Serial.print(LowVoltage);
- if (LowVoltage <= 3.6) Serial.print("LOW BATTERY:");
- Serial.println();
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement