From 33236b4a11d785254e5554aa5983b13e103d5ed8 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Sat, 11 Apr 2020 19:39:26 +0200 Subject: [PATCH] korrekt calculation of amphours. better output with more info --- src/main.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b88e78d..753fc9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,15 +4,18 @@ #include "Arduino.h" #define MINVOLTAGE 2.5 -#define OHM 55 +#define OHM 4.7 + +#define MEASUREPIN A3 +#define MOSFETPIN A2 void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); - pinMode(8, OUTPUT); - pinMode(A0, INPUT); + pinMode(MOSFETPIN, OUTPUT); + pinMode(MEASUREPIN, INPUT_PULLUP); - digitalWrite(8, LOW); + digitalWrite(MOSFETPIN, LOW); } int i = 0; @@ -20,25 +23,37 @@ double all = 0; void loop() { Serial.println(); - double voltage = (float) (analogRead(A0)) / 1024 * 5; - if (voltage > MINVOLTAGE) { - digitalWrite(8, HIGH); + double voltage = (float) (analogRead(MEASUREPIN)) / 1024 * 5; + if (voltage > MINVOLTAGE && voltage < 4.5) { + digitalWrite(MOSFETPIN, HIGH); double current = voltage / OHM; double watt = current * voltage; - double amphours = watt / 360; + double amphours = current / 360; // every 10secs is a measurement point... all += amphours; Serial.print(all * 1000, 5); Serial.print("mA/h already captured after - "); Serial.print(i * 10); Serial.println("s"); + + Serial.print("Watts: "); + Serial.println(watt); + Serial.print("Current: "); + Serial.println(current); i++; - } else { - digitalWrite(8, LOW); + } else if (voltage <= MINVOLTAGE) { + digitalWrite(MOSFETPIN, LOW); Serial.print("FINISHED voltage below minvoltage - "); - Serial.print(all / 1000, 5); + Serial.print(all * 1000, 5); Serial.print("mA/h in - "); Serial.print(i * 10); Serial.println("s"); + Serial.println("please restart the print"); + delay(999999999); + } else if (voltage > 4.2) { + Serial.println("no battery connected!"); } + Serial.print("Voltage: "); + Serial.println(voltage); + delay(10000); } \ No newline at end of file