Projects/Power Meter: Difference between revisions
< Projects
No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{Project | {{Project | ||
|name=Power Meter | |name=Power Meter | ||
|start=2012 | |start=2012/07/07 | ||
|contact=User:Zarya | |contact=User:Zarya | ||
|info=Bitlair Power meter | |info=Bitlair Power meter | ||
|status=Production | |status=Production | ||
|Picture=Zarya_15155.jpg | |||
|end=2012-07-15 | |||
}} | }} | ||
* Meter url https://stats.bitlair.nl/ | * Meter url https://stats.bitlair.nl/ | ||
Revision as of 21:41, 23 January 2013
Project Power Meter | |
---|---|
Name | Power Meter |
Start | 2012/07/07 |
End | 2012-07-15 |
Contact | User:Zarya |
Website | |
Information | Bitlair Power meter |
Status | Production |
- Meter url https://stats.bitlair.nl/
Code
#include <WProgram.h>
#include <inttypes.h>
#define MS_PER_HOUR 3.6e6
int cycles_per_kwh = 100;
int max_watt = 6000;
unsigned long previous = 0;
unsigned long cycle = 0;
boolean last = LOW;
void kwhChange() {
unsigned long now = millis();
unsigned long time = now - previous;
if (cycle == 0) {
cycle++;
return;
}
// digitalWrite(13,last);
previous = now;
double W = 1000 * ((double) MS_PER_HOUR / time) / cycles_per_kwh;
Serial.print("Cycle ");
Serial.print(cycle, DEC);
Serial.print(": ");
Serial.print(time, DEC);
Serial.print(" ms, ");
Serial.print(W, 2);
Serial.println(" W");
cycle++;
if (last) last = LOW;
else last = HIGH;
}
void setup () {
Serial.begin(57600);
pinMode(13, OUTPUT);
attachInterrupt(0, kwhChange, FALLING);
}
void loop () {
digitalWrite(13,digitalRead(2));
}
Pictures
-
Meter
-
Electronic