This commit is contained in:
lukas-heiligenbrunner 2020-04-10 23:00:28 +02:00
commit 882b793cd2
2 changed files with 45 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.pio

44
src/main.cpp Normal file
View File

@ -0,0 +1,44 @@
//
// 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);
}