44 lines
1007 B
C++
44 lines
1007 B
C++
|
//
|
||
|
// 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);
|
||
|
}
|