I'm so proud!My first Arduino project is a power meter for my house.The power meter that the electric company reads every month and sends me a bill from just states how much power is used since it started. It also sends out a light pulse for every thousands of a kWh used. I use a light dependant resistor to read the pulse and count them and the time between the pulses to get power used since my Aruino started and the current power usage. All this is displayed on a LCD shield. With the buttons on the shield i can display different things:The total power used since the start and current usage.Power used last minute and mean power last minute.Power used last hour and mean power last hour.Power used last day and mean power last day.Power used last week and mean power last week.Power used last four weeks and mean power four.

The sketch saves the current usage value every ten seconds and calculates everything. The values are cyclic so last days measyre ment is rather last 24h values and so on. If the Arduino is juststarted it sets a "c" in front of the values that are not correct yet (it takes four weeks to get all values correct).

It was kind of an anti climax when all was in place and running. What do do now? I have an idea of another shield that kan show graphics so i can draw a graph of power usage. Connecting a memory card so I can import the readings to my computer and analyze the readings more. And... And... Is there evera finished product?

int seconds[6]; //Array that holds each powerreading done during the last minuteint minutes[60]; //Array that holds each powerusage reading done during the last hourint hours[24]; //Array that holds each powerusage reading done during the last dayunsigned long days[7]; //Array that holds each powerusage reading done during the last weekunsigned long weeks[4]; //Array that holds each powerusage reading done during the last four weeks

unsigned int secondsvalue=0; //Powerusage during the last minuteunsigned long minutesvalue=0; //Powerusage during the last hourunsigned long hoursvalue=0; //Powerusage during the last dayunsigned long daysvalue=0; //Powerusage during the last weekunsigned long weeksvalue=0; //Powerusage during the last four weeks

unsigned int secondsrating[6]; //Array that holds each powerrating reading done during the last minuteunsigned long secondspowerrating=0; //Powerrating during the last minute

char powervalue[6]; //Char array to hold power value for printing on LCDchar value[6]; //Char array to hold power usage for printing on LCDbyte a,b; //Used to get length from strings

byte minutehaspassed=false; //Flag to see if one minute or more has passed since start, set to false from startbyte hourhaspassed=false; //Flag to see if one hour or more has passed since start, set to false from start byte dayhaspassed=false; //Flag to see if one day or more has passed since start, set to false from start byte weekhaspassed=false; //Flag to see if one week or more has passed since start, set to false from start byte weekshaspassed=false; //Flag to see if four weeks or more has passed since start, set to false from start byte timingflag=false; //Flag that switches between 0 and 10. Used to get tome to be more accurate

for (int i=1; i<6 ;i++) //Each array that holds powerusage is set to contain 0 in every place seconds[i]=0; for (int i=0; i<60 ;i++) minutes[i]=0; for (int i=0; i<24 ;i++) hours[i]=0; for (int i=0; i<7 ;i++) days[i]=0; for (int i=0; i<4 ;i++) weeks[i]=0; for (int i=0; i<6 ;i++) //Array that holds powerrating is set to contain 0 in every place secondsrating[i]=0; seconds[0]=powerrating; //We have started so set the first seconds powerrating // Serial.begin(9600);}

result[b+3]=48+(clockmin/10); //Print what minute we are at right now. Only for testing result[b+4]=48+(clockmin%10);

if(minutehaspassed) sprintf(powervalue, "%u", secondspowerrating); //Convert long powerusage to string else sprintf(powervalue, "%u", ((secondsvalue*360)/(clocksec))); //Less than on hour has passed so minutesvalue is too small

if(dayhaspassed) sprintf(powervalue, "%u", (hoursvalue/24)); //More than one day since the start has passed so hoursvalue is ok else { sprintf(powervalue, "%u", ((hoursvalue*60)/(clockhour*60+clockmin+1))); //Less than on day has passed so hoursvalue is too small result[14-strlen(powervalue)]='c'; } a=strlen(powervalue); for (int i=1; i<=a; i++) result[15-i]=powervalue[a-i]; result[15]='W';

if (key == 4) //Button corresponding to four weeks is pressed, display last four weeks usage and rating. Works the same as for minutes { if(weekshaspassed) { sprintf(value, "%u", weeksvalue/1000); b=strlen(value); for (int i=0; i<b; i++) result[i]=value[i];

if(weekshaspassed) sprintf(powervalue, "%u", (weeksvalue/(24*7*4))); //More than four weeks since the start has passed so weeksvalue is ok else { sprintf(powervalue, "%u", ((weeksvalue*60)/(clockweek*7*24*60+clockday*24*60+clockhour*60+clockmin+1))); //Less than four weeks has passed so weeksvalue is too small result[14-strlen(powervalue)]='c'; } a=strlen(powervalue); for (int i=1; i<=a; i++) result[15-i]=powervalue[a-i]; result[15]='W';

if (clocksec>=5) //if more than 50 (seconds are only stored as 0-5) seconds have passed seconds are set to 0 { clocksec=0; minutehaspassed=true; //One minute has passed since the start so set flag true if( clockmin>=59) //if more than 59 minutes have passed minutes are set to 0 { clockmin=0; hourhaspassed=true; // One hour has passed since the start so set flag true if(clockhour>=23) //if more than 23 hours have passed hours are set to 0 { clockhour=0; dayhaspassed=true; // One day has passed since the start so set flag true if (clockday>=6) //if more than 6 days have passed days are set to 0 { clockday=0; weekhaspassed=true; // One week has passed since the start so set flag true if(clockweek>=3) //if more than 3 veeks have passed weeks are set to 0 { clockweek=0; weekshaspassed=true; // Four week has passed since the start so set flag true } else clockweek=clockweek+1; //Less than 4 weeks have passed so update weeks by one } else { clockday=clockday+1; //Less than 7 days have passed so update days by one } } else { clockhour=clockhour+1; //Less than 24 hours have passed so update hours by one } } else { clockmin=clockmin+1; //Less than 60 minutes have passed so update minutes by one } } else { clocksec=clocksec+1; //Less than 60 days have passed so update seconds by ten }}

void sensortick() //The interrupt routine{ powercounternow=micros(); //At what time did we se the pulse? //Serial.println(powercounternow-powercounterlasttime); sensortickcounter=sensortickcounter+1; //Update number of pulses seen powerrating=3600000000/(powercounternow-powercounterlasttime); //Calculate length of pulse and update current powerrating powercounterlasttime=powercounternow; //Last time we saw a pulse was now sensorstate = LOW;}

Thanks for the positive feedback, in makes me even more proud.I learned the hard way to comment code when I studied. A professor told me to comment the some code two weeks after I wrote it. It took me four times the time to comment it than to write the code.

The light resistor is connected to 5v and pin 3 and. And there is a 4 Mohm something resistor connected to pin 3 and ground. So if the light resistor sees darkness pin 3 is connected to ground and if it sees light pin 3 is connected to 5v. That vay i can read changes from LOW to HIGH on pin 3.

that's great project - the one what I searched for.could you please give me some idea how to connect photoresistor to arduino? some sketch should be great.I want to read power usage from 3 electric meters - one heating system, one water heating system and air exchanger system.thanks in advance

Sure, here comes a schematic:The light resistor is connected to 5v and pin 3 and. And there is a 4 Mohm something resistor connected to pin 3 and ground. So if the light resistor sees darkness pin 3 is connected to ground and if it sees light pin 3 is connected to 5v. That vay i can read changes from LOW to HIGH on pin 3.

I've always wanted to know exactly how much energy I'm using, and now I'm just days away to get my own solution working

I do not have any experience in Arduinos, but I plan to use an ATmega(8,16,32), I'm not sure what will suit my application best. Those computers do have UART interface and that is good news since the old laptop I uses as home webserver has a RS232 (serial) interface. The plan is to buffer the meter reading in the ATmega and send to laptop (server) and perhaps use another ATmega coupled with a DS1620 digitalthermometer. And then correlate used energy with outdoor temperature Python and pySerial is quite easy to use when interfacing with UART.

I tried various solutions before ordering some ATmega. The first try were 6-7 years when I studied, my apartment had the meter in my office/study, and I used my (only) optical mouse and taped it to the meter with the optical sensor right above the light, and were able to make a Java program that registered changing states in the serial transfer. It was a bad solution since I were a student and a new mouse would cost too much.Just recently I tried to use a photoresistor and photodiode with a parallel port to do the same trick, but i was not able to get any stable signal through.

Mmmh, should perhaps have something measuring the take wind speed also...