Projects/Power Meter: Difference between revisions

From Hackerspace Amersfoort
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Β 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Project
{{Project
|name=Power Meter
|name=Power Meter
|contact=Gebruiker:Zarya
|start=2012/07/07
|contact=Zarya
|info=Bitlair Power meter
|info=Bitlair Power meter
|status=Productie
|status=Production
|Picture=Zarya_15155.jpg
|end=2012-07-15
}}
}}
* Meter url https://stats.bitlair.nl/


== Code ==
== Code ==

Latest revision as of 19:15, 21 April 2013


Project Power Meter
Name Power Meter
Start 2012/07/07
End 2012-07-15
Contact Zarya
Website
Information Bitlair Power meter
Status Production


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

Schema

200px