korrekt calculation of amphours.
better output with more info
This commit is contained in:
parent
882b793cd2
commit
33236b4a11
37
src/main.cpp
37
src/main.cpp
@ -4,15 +4,18 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define MINVOLTAGE 2.5
|
#define MINVOLTAGE 2.5
|
||||||
#define OHM 55
|
#define OHM 4.7
|
||||||
|
|
||||||
|
#define MEASUREPIN A3
|
||||||
|
#define MOSFETPIN A2
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
pinMode(8, OUTPUT);
|
pinMode(MOSFETPIN, OUTPUT);
|
||||||
pinMode(A0, INPUT);
|
pinMode(MEASUREPIN, INPUT_PULLUP);
|
||||||
|
|
||||||
digitalWrite(8, LOW);
|
digitalWrite(MOSFETPIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -20,25 +23,37 @@ double all = 0;
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
double voltage = (float) (analogRead(A0)) / 1024 * 5;
|
double voltage = (float) (analogRead(MEASUREPIN)) / 1024 * 5;
|
||||||
if (voltage > MINVOLTAGE) {
|
if (voltage > MINVOLTAGE && voltage < 4.5) {
|
||||||
digitalWrite(8, HIGH);
|
digitalWrite(MOSFETPIN, HIGH);
|
||||||
double current = voltage / OHM;
|
double current = voltage / OHM;
|
||||||
double watt = current * voltage;
|
double watt = current * voltage;
|
||||||
double amphours = watt / 360;
|
double amphours = current / 360; // every 10secs is a measurement point...
|
||||||
all += amphours;
|
all += amphours;
|
||||||
Serial.print(all * 1000, 5);
|
Serial.print(all * 1000, 5);
|
||||||
Serial.print("mA/h already captured after - ");
|
Serial.print("mA/h already captured after - ");
|
||||||
Serial.print(i * 10);
|
Serial.print(i * 10);
|
||||||
Serial.println("s");
|
Serial.println("s");
|
||||||
|
|
||||||
|
Serial.print("Watts: ");
|
||||||
|
Serial.println(watt);
|
||||||
|
Serial.print("Current: ");
|
||||||
|
Serial.println(current);
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else if (voltage <= MINVOLTAGE) {
|
||||||
digitalWrite(8, LOW);
|
digitalWrite(MOSFETPIN, LOW);
|
||||||
Serial.print("FINISHED voltage below minvoltage - ");
|
Serial.print("FINISHED voltage below minvoltage - ");
|
||||||
Serial.print(all / 1000, 5);
|
Serial.print(all * 1000, 5);
|
||||||
Serial.print("mA/h in - ");
|
Serial.print("mA/h in - ");
|
||||||
Serial.print(i * 10);
|
Serial.print(i * 10);
|
||||||
Serial.println("s");
|
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);
|
delay(10000);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user