AkkuPowerMeter/src/main.cpp

44 lines
1007 B
C++
Raw Normal View History

2020-04-10 21:00:28 +00:00
//
// Created by lukas on 10.04.20.
//
#include "Arduino.h"
#define MINVOLTAGE 2.5
#define OHM 55
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A0, INPUT);
digitalWrite(8, LOW);
}
int i = 0;
double all = 0;
void loop() {
Serial.println();
double voltage = (float) (analogRead(A0)) / 1024 * 5;
if (voltage > MINVOLTAGE) {
digitalWrite(8, HIGH);
double current = voltage / OHM;
double watt = current * voltage;
double amphours = watt / 360;
all += amphours;
Serial.print(all * 1000, 5);
Serial.print("mA/h already captured after - ");
Serial.print(i * 10);
Serial.println("s");
i++;
} else {
digitalWrite(8, LOW);
Serial.print("FINISHED voltage below minvoltage - ");
Serial.print(all / 1000, 5);
Serial.print("mA/h in - ");
Serial.print(i * 10);
Serial.println("s");
}
delay(10000);
}