Projects/Power Meter: Difference between revisions

From Hackerspace Amersfoort
Jump to navigation Jump to search
(Nieuwe pagina aangemaakt met '{{Project |name=Power Meter |contact=Gebruiker:Zarya |info=Bitlair Power meter |status=Productie }} <gallery> Image:Zarya_15155.jpg| Meter </gallery>')
 
mNo edit summary
Line 5: Line 5:
|status=Productie
|status=Productie
}}
}}
== Code ==
<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));
}
</code>
== Pictures ==
<gallery>
<gallery>
Image:Zarya_15155.jpg| Meter
Image:Zarya_15155.jpg| Meter
Image:Zarya_15157.jpg| Electronic
</gallery>
</gallery>

Revision as of 19:16, 7 July 2012


Project Power Meter
Name Power Meter
Start
End
Contact Gebruiker:Zarya
Website
Information Bitlair Power meter
Status Productie"Productie" is not in the list (Alpha, Beta, Production, Finished, Abandoned) of allowed values for the "Project status" property.


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