View Single Post
Old 12-26-10, 01:55 PM   #22
strider3700
Master EcoRenovator
 
Join Date: Dec 2008
Location: Vancouver Island BC
Posts: 745
Thanks: 23
Thanked 37 Times in 30 Posts
Default

I got back on the project yesterday after just letting the two temps sensors collect data for a week or so.

During that week I had the serial port "vanish" once and after unplugging the arduino and plugging it back in to the USB port it went back to working just fine. I'll have to see if I can figure out what caused that as it has happened twice. All data being collected is gone when that happens of course.

I've decided at this point I'm going to change my logging to CSV files to be a new file daily. so at midnight the file name being written to will change to datalog-ddmmyyyy.csv This is of course still just a temporary datastorage but I will probably leave it in place long term when I'm done with the online logging as well. The code for that should be easy so maybe tonight I'll knock that out.

Much more interesting then my "issues" however is the progress. Yesterday I had the soldering iron out and decided to attach a chunk of the 2 pair to one of the current sensors. I then took my homemade extension cord for the wood stove which has those screw together plugs apart and ran one of the wires through the hole in the current sensor. Wiring to the arduino was simple, 5v to vcc, gnd to gnd, en to gnd(this could be switched on the arduino but power usage at this scale isn't import enough to use a pin), data to one of the analog in pins on the ardunio(0 in my case)

then in the arduino sketch I added a small section which basically just calls analogread(0); This reads the current voltage at pin 0 between slightly over 0 and slightly below 5V and turns it into an integer between 0 and 1024 with each working out to roughly 0.0049V. It turns out the current sensor returns roughly 509 when no current is flowing through it. So in the arduino code I just subtract 509 from the value returned and just get anything above or below that.

Last night I had a hell of a time getting any good readings and it was making little sense until I graphed it and went to bed to sleep on the issue. I was always getting 506-515 even when I had a 1500 watt heater plugged in that was using in the 1450 range according to my wattmeter. I was taking about 100 readings per second and averaging trying to get rid of noise on the line thinking it was noise....

This just goes to show that I'm a programmer not an electronics guy. AC is a signwave and it will go both positive and negative in one cycle. The current also seems to be going in a wave as far as I can tell and I really really didn't want an average I wanted to know the peak value each second. Realizing this while sleeping last night, this morning I got up and changed my reading code to loop through 1000 times with a delay of 1 ms each loop and take the value each time. I then took the absolute value of it and checked if it was higher then the previously recorded max. if so max became that reading, continue the loop. At the end of the loop print out the max and reset it to zero.

This works great and I'm now able to graph with only minor noise jitters the hater turning on the fan, to high, to med to off to high.... with the values being anywhere from zero to 71 and it to the naked eye appearing pretty linear. It appears to have a "resolution" of about 7 watts. Anything below that vanishes in noise. I also get the occasional spike of noise in the 7 watt range.

If you want really sensitive down to the watt 100 times per second readings my approach isn't the way to go but for having a good idea how much power something large is using this works out great and it cost me $5 for 1 sensor.

Now my next step is to get the values converted to watts for logging since that is what I care about. That should just be some math on the arduino. I also think I may change the datalogging program to handle current sensors a little differently. A minutely average may not be accurate enough.

That is all just a bit of code. The next interesting thing is figuring out how to get a 220V wattage using two of these sensors on each line running into the hotwater heater. That was the real goal of the current readings. For now I'll just wire them up and get the readings back from both sensors so the rest should just be math. Do I just sum the two?

All code for both sections will be available when I get it a bit less hacked together.
strider3700 is offline