korrekt calculation of amphours.
better output with more info
This commit is contained in:
		
							
								
								
									
										37
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								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);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user