CAUTION: Here is the usual caution that part of this project gets pretty close to lethal A/C mains voltage. It's not in the path of the final circuit, which is galvanically isolated, but don't be dumb along the way while building it. Don't mess around inside the power strip when it is plugged in. If you aren't sure of what you are doing, don't do it. Seriously, you could die.
(The above advice is for me, too.)
Editorial note: I wrote this description as I was building things, but I was foolishly trying to write it as if it was a description of a completed project. The author's voice roams around a bit among past, present, and future tenses. Sorry for those among you who are annoyed by things like that. I know the difference.
The PlanThe immediate problem at hand is that members of my household tend to forget about laundry in the washing machine or dryer. If you leave things in the washing machine overnight, the mildew is already starting to accumulate by morning. If you leave things in the dryer for too long, even "permanent press" articles get unwanted creases.
Having seen mentions of such things elsewhere, I set out to build a system that could notify us when one or the other machine had finished its cycle. It's a bit embarrassing, but I started thinking about this a couple of years ago and even accumulated some parts. Bad news/good news: Some of the parts for the original plan are now unneeded because ESP8266 and ESP32 have come along to simplify things tremendously.
This design uses current transformers (CTs) to sense the current draw from the machines. That's read periodically by the ADC pin on an ESP8266, and notifications are wifi-ed out when appropriate. I'm using a SparkFun ESP8266 Thing, and power will come via the USB connector (which can't be used for programming on this module). Since an ESP8266 has only a single ADC pin, I'm using a simple multiplexer to wire multiple CTs to that single pin. I'll be using a CD74HC4067-based multiplexer breaktout board similar to this SparkFun part, though I got mine somewhere else.
My first idea was to stash the whole works inside the wall with the outlet already being used. I could expand the single-gang box inside the wall to 2-gang, 3-gang, or even 4-gang. The extra space should easily house the components, and I could cover them externally with a wallplate that was blank in the unused spots. There were a couple of problems with this plan:
- I would have to open up the wall and replace the current single-gang box. I've done similar projects before, so I know I could do it. But it's, you know, a pain in the neck. I don't what is inside that wall, so there is a chance I would find something blocking my way after I had started to open things up. Finally, every time I do a job like that, it seems really simple in my mind, but it turns out to be more complicated than expected and requires multiple trips to the hardware store before it's done.
- I would have to figure out how to power my stuff from the A/C feed. It's easy when the outlets are drawing current. When they are idle, I'd have to be tapping into the A/C and converting it down to low-voltage DC. Again, that's conceptually simple, but I don't want some insurance inspector saying, after the fire, "What have we here?"
- This is not a simple cheapo outlet. Because it's a laundry room (and also a bathroom), it has a Ground Fault Interrupter (GFI). That in itself is not a problem, but this particular GFI has only a single set of external wires supplying both outlets. I would not be able to measure them separately. It might still be possible to deduce different combinations of things (washer on, dryer off, both on, etc; don't forget different power draws in different parts of their cycles). It would be much simpler if I could measure them separately.
- I thought of this only in retrospect, but the hook-up would not be portable. It would measure exactly that outlet with those two appliances and nothing else. If I sell the house some day, the next homeowner would probably want no part of it, and the inspector would probably demand that it be removed anyhow.
I resolved then to build the project with a power strip. It would either be inside the strip itself or would be attached directly outside of it. As part of the sidecar plan, I bought some 3.5mm phone plugs. The idea was that I could wire up the CTs and burden resistors inside the power strip, and then I could use generic phono cords to connect them any way I wanted to my little box of electronics. When not connected to my monitoring box, it would be just like any other power strip. Genius!
There is not much space inside your typical power strip. I have an assortment around here, and I took quite a few of them apart. They are mostly very tight inside. There was no way I was going to fit any of the CTs inside. The smallest CTs I came across were about 1 inch in diameter and about 3/8 inches thick. The phono jacks and burden resistors would fit, but not the CTs themselves.
I went on a quest to find a power strip that did have space inside. It's a little tricky because you really can't tell until you open them up. I finally found a likely candidate at the local hardware store (the same model is available online from various places). Here it is:
NOTE: I eventually changed to a different power strip. See further below.
It's good news that it is UL-approved and has some stuff about meeting OSHA standards, but the best part is that the switch is also a circuit breaker ... just in case. The (slightly) bad news is that it's only rated for 15A. The GFI in the wall is rated for 20A.
Do I need 20A? According to the data plates on the washer and dryer, I will be in the neighborhood of 15A if they are both doing their maximum current draws at the same time. I'll have to find out experimentally if that's a problem, and I'll depend on that circuit breaker to let me know. If it's a problem, I'll just have to use this gadget for something else. Sad face.
The TinkeringLet's open it up and see how much space we have inside:
If you have never dismantled a power strip before, this may be a little surprising to you. You might have been thinking that it would be a collection of something that looked like normal household electrical outlets. I have seen something like that, but it's pretty rare. More commonly, it's something like this: a collection of custom metallic parts that only looks passingly like electrical outlets. The prongs of an electrical plug force-fit between the little tabs you can see inside the red boxes. Being a veteran of power strip disassembly, this is more or less what I was expecting.
I laid most of my planned parts inside, and there seems to be just enough room. Just.
To see how the internals are held together, it's simplest to follow the white wire trail. It comes out of the electrical cord and is attached to the left-most outlets. A jumper from there attaches to the right-most outlets. The return path is through black wires that are a little harder to see. You can see black wires on the switch in the upper-left corner. If the switch is not closed, no complete circuit can be made. (I'm not sure why there is an extra white wire going to the switch. Maybe it simplifies lighting up the switch, or maybe it has something to do with the circuit breaker function.) The green and bare wires are ground.
It's probably obvious that, as far as electrical flow is concerned, the two outlets on the left are treated as one logical outlet, and the two outlets on the right are treated as one logical outlet. Each pair is wired in parallel. If you're not used to looking at such things, it may be less obvious that the left and right parts are wired in series. Any current flowing through the supply wire to the right-hand side will also have flowed through the supply wire to the left-hand side (but not vice versa).
A CT is donut-shaped and has to surround the current-carrying wire. That obviously means that some of the wires will need to be unsoldered, the CTs slipped over, and the wires resoldered. The question is, what's the best way to do that?
- If I put a CT around the left-hand supply wire, I can measure the total current of the entire power strip. If I put a CT around the jumper that supplies power to the right-hand side, I can then subtract that measured current from what the total to get the left-hand current draw.
- If I add a pigtail to the two white wires on the left-hand side (in other words, combine the two existing wires with a 3rd wire that's a few inches long), and attach the pigtail where the existing supply wire is attached, then I can put a CT around the pigtail to measure just the left-hand current. And, as before, a CT around the jumper will give me just the right-hand current.
- Neither of the above wirings gives me separate readings for all 4 outlets. I could do additional pigtail tricks to run individual supply wires to each of the 4 outlets. I would also have to cut the vertical bars that currently connect the top and bottom outlets together (otherwise, they stay as one logical path). It's thin brass, so I can do that. The pieces might not stay in place as well since they are pressure-fitted into the plastic, but some hot-melt glue should put that right. I'm still not sure what to make of the extra white wire going to the switch, so I'll be sure that something supplies power to that wire.
I've decided to go with the third option so that I can independently monitor each of the four outlets. With that extra wire and four CTs inside, it's starting to get pretty crowded inside the power strip. I'm reverting to my original plan of having the active electronics outside in a separate project box. That will save me from the need to perform microsurgery on everything jammed inside. It also means the I can use the power strip without the electronics of the monitoring circuit. I can also use the electronics in the separate project box to monitor something else. That part of the circuit just wants to measure voltages up to 1.0V (the limit of the ADC). I don't have any actual ideas for that separate use, but you never know. Maybe I'll even have a use for the additional 12 unused channels on the multiplexer.
Where am I going to get the extra wire? Someone recently severed a heavy duty extension cord while using electric hedge trimmers. Let's not get into a blame game; let's just leave it at "somebody". The extension cord was also rated at 15A, so inside are green, black, and white wires that are 14 gauge and stranded.
Here is the plan for wiring each of the CTs:
The burden resistor is soldered directly across the legs of the 3.5mm jack, and the two legs of the CT are soldered into that same blob. The jack is then panel-mounted to the case of the power strip. Each of the four jacks is located as close as possible to its associated outlet so that I don't need to label them to know which is which. The CTs that I have don't have an orientation arrow, so I will use the printed label for that and hope that the labels were applied consistently. It shouldn't matter for this application, but it could matter for some other scenarios. And, I just like to be tidy and consistent.
After the above initial wiring, I can see if things are working by plugging into the 3.5mm jack and measuring voltage with a multimeter. If I plug something in, the result is either sparks and smoke or an A/C voltage of up to 0.5V.
There are lots of explanations of CT circuits and how to interface them to microprocessors. A really nice explanation is on this Open Energy Monitor site. It's clear and complete. One of the things you have to figure out for a CT circuit is a good value for the burden resistor. It's a typical problem of wanting to cover the widest available range while not over/under-doing it. After a step by step description, they reduce the final calculation to:
Burden Resistor (ohms) = (AREF * CT TURNS) / (2√2 * max primary current)
For this particular design, the ESP8266 ADC input voltage (AREF) is 1.0V. The CT has 2000 turns. The maximum primary current is 15A (above which we expect the breaker to trip). Plugging those values into that equation yields a burden resistor value of 47.14Ω. Luckily, that's just a smidge above the common resistor value of 47Ω. I already have a bunch of those at 1% precision on my shelf.
Missed it by that muchI spent more time today than I want to admit desoldering wires and replacing wires inside the powerstrip. It was pretty easy to separate both of the brass pieces for supply into two halves. I didn't have to bother with hot glue because it turned out that the back cover had fingers pressing down in exactly the right places to hold things.
The first time, I tried to reuse as many existing wires as I could. The problem with that is that I couldn't even come close to putting the powerstrip back together.
By the way, that clear and blue translucent electrical connector I'm using is an Ideal In-Sure 6 port connector. I don't know what professional electricians think about them, but they are great for fumble-thumbs like me who can never get things to fit back into an electrical box. They are slightly tricky for stranded wire, so I smeared a little hot solder on them to hold the strands together before inserting.
For the second try, I replaced all of the white wires except for the supply coming out of the cord. I got myself some long wires (more than a foot long), soldered them onto the brass pieces, slipped a CT over each one, and then routed the wires so that I could place the CTs where they wouldn't get into trouble. I don't know if it makes any difference, but I oriented each CT on the wire the same way with respect to the supply. By "orient", I mean that I made sure the writing on the labels was the same way. Even if it matters in some electrical engineering way, I don't know if the labels are all put on the same way in the first place. I reckon since it's A/C, I'm only measuring the current, and I don't need precision ... that it doesn't matter anyhow.
Next came a pretty big disappointment. My plan was to mount the 3.5mm jacks to either the sides or top of the powerstrip. After I drilled a few holes (which you can see in the above photo), I figured out that the threaded part of the jack was just not long enough to get through the plastic and then take a nut. Believe me, I tried a lot of things to make it work, and I have the chewed up fingers and thumbs to show for it. Jeez, I've had these jacks for several months while I thought about this project, and it never occurred to me that this would be a problem. I'll have to shop for some jacks that are a bit longer in that aspect. Meantime, to avoid being blocked for who knows how long, I chose a medieval approach and let one of the jacks dangle outside the power strip case. Ugh.
This shouldn't be too disastrous as an interim solution. With something powered by that socket, I expect the current in the jack to max out at 7.5mA, and the voltage won't be higher than 0.5VAC.
While looking around for some 3.5mm jacks with longer threaded necks, I changed my mind and decided to use panel-mount RCA jacks. There are plenty of those around with fairly long threads. The only ones I could find have to be mounted from the outside in. That is, the threaded part is pushed through from the outside. I'll have to solder the burden resister and the red and black leads from the CT after the jacks are mounted. Originally, I avoided that approach because I thought it would be a hassle in a tight space. Now that I've spent some time inside the powerstrip case, I can see that it won't be too bad. The good news is that I've got bushels an bushels of cables with RCA plugs and very few 3.5mm patch cords. If Radio Shack still had a couple of stores within striking distance, I'd have the RCA jacks in my hand. As it is, I'll be waiting a few days for them to show up in the mail.
There, that's better:
For the sake of keeping things straight, I looked at the power strip outlets in the "natural" upright orientation (the writing on the on/off switch reads correctly) and referred to the outlets by compass directions: NW, SW, NE, SE.
A quick testThe good news is that I plugged my heat gun into the power strip and put a meter across the jack. I don't know offhand how much current the heat gun draws. Its data plate says 6A, but it's part of a unit that also includes a soldering iron and, of course, some electronics. I tried one of those plug-in pass-through power meters, but the amperage fluctuated constantly and the readings were mostly useless. I did see the voltage on the jack go up to a steady 0.25VAC (measured with a multimeter) while the gun was heating up. The voltage dropped back down to zero when I turned the heat off. So, yay for that.
The smart boxMy next step is to work on the separate little box holding the ESP8266 and surrounding circuitry. I was planning to use a single-gang electrical box to hold that, but I already know that its walls will be too thick for the 3.5mm jacks. With the switch to RCA jacks with longer threads, that should not be a problem.
I'll be using an off-the-shelf shallow single-gang electrical box for the enclosure. If you ignore the bump-outs where the faceplate screws go, it's about 2.1 inches wide by 2.9 inches long. There is just over an inch of depth. The 4 mounting ears will be covered by the faceplate. The faceplate will be blank, but maybe I will revise the design someday to include some indicator LEDs mounted there so you can see it's working without having to consult some other gadget. Even though this powerstrip project uses only four channels of the multiplexer, the physical layout of the components leaves room for wiring up the other 12. It would be pretty tight to put 16 RCA jacks on this tiny box, though. The sides have about 3.2 inches of usable space.
Prototyping boards ... ugh. I don't really like using this stuff. Besides being tedious, it ends up looking like a barbarian did the soldering. I have some the of usual kind that is just the right size for this circuit. I need 16 or 18 by 21 holes (depending on how I count it), and this one is 18 by 24:
On the other hand, I have a few sheets of the stuff pictured below. It's called Perf+ and I backed it on Kickstarter a couple of years ago. A slightly improved version of it is being sold by the creator, Ben Wang, on Amazon. (I am not affiliated with it, and that's not even an affiliate link.) I'm using the improved version since the original has holes that are too small for the usual pin headers. The horizontal rails you see almost, but not quite, touch the holes. On the other side, vertical rails do the same thing. It's like each hole is almost touching a cross-shaped trace that almost connects it to its four neighbors (if that makes any sense to you :-)).
How do you use this and why is it better than the usual stuff? The space between the holes and the rails is really tiny and also has a little gap in the solder mask. So, in the first place, it's easier to make the barbaric blobs of solder, and they look less barbaric. In the second place, if you need to make long horizontal or vertical runs, or some combination in a run, the rails do most of the running. You don't have to dribble solder from hole to hole along the way. It's more or less like a traditional PCB trace. All in all, quite jolly.
The boards are 24 holes by 36 holes, so I'll be could get by with half of one, though I'll lose a column when I score it and cut it apart. However, the space I have inside the box will allow me up to 20 holes by 28 holes, and I'm going to space things out a bit to have a few fewer tight spaces. The holes for the connections of the 16 channels of the mux module will dangle in the air so that I can solder directly to them. (It will be kinda-sorta supported by the resistors that I placed beneath the part.) The holes for the ground connections go horizontally across the top. I'll be cutting the board along column 18 or 19. I'll use all of the rows even though there will be empty space.
If you are used to traditional PCB layout, with top and bottom copper and vias to explicitly transit to the other side of the board, it's a little confusing to think about how to do layouts with Perf+. All of the horizontal segments go on one side, and all of the vertical segments go on the other side. The holes where you turn a corner with a trace then act like vias. Luckily, Mark Feldman created a graphical editor called Perfy for working with this kind of layout. It's pretty simple to use after you read the embedded help file. (It runs on something called "Windows", but other than that it's quite nice. :-)
Here is what the front side of my Perf+ board looks like after translating the traces from the PCB layout:
Although we are looking at perfy's front-side view, the vertical blue traces are actually on the back/bottom side. On the left, the two columns of 10 holes are for the SparkFun ESP8266 Thing. On the right, the column of 8 holes and the column of 16 holes are for the multiplexer. The 16 holes across the top are the ground connections for the multiplexer channels. The channel signal and ground holes will not have pins. Wires from the channels will be soldered directly to the holes.
OK, forget all that. Perf+ is a great idea, but I couldn't figure out how to actually make the connections when most of the mounted parts are on strips of pin headers. (I won't bore you with the details ... yet.) So, it's back to traditional perfboard.
From the front, it looks decent enough:
From the back ... well, it's not brutally ugly ... just regular ugly:
Luckily, there are lots of no-connects and easy routes. I decided to use pin headers for all the input signals and ground connections, figuring it would be easier to solder-tack onto them. After I took the picture of the front, I had to trim the short pins off a few of the yellow ground pins so that I could plug into the ESP8266 Thing USB port.
A little biasThe signal coming to the ADC port will be A/C. If I've have done the math correctly, a 15 amp load should produce a signal input that is about 1 volt peak-to-peak. The mid-point is at 0 volts, and the ADC can't measure things below that. I'm using a simple voltage divider circuit to produce a voltage at about 0.5 volts. That elevated voltage (with respect to the microprocessor ground) will be used as the ground reference for the sensor input. The microprocessor will then see the signal's +/-0.5v as 0 - 1 volt. At least that's the theory.
There are lots of web pages with voltage divider calculators if you don't happen to know the formula. The voltage driving the divider is 3.3v. I decided to use a 6.2 kohm resistor as the top and a 1.0 kohm resistor as the bottom. That calculates to a 0.46v in the middle. I could have gotten closer to 0.5v, but I wanted to give myself a little headroom. I wired it up and tested it with the specific individual resistors I later used in the circuit, and it measured pretty close to the predicted 0.46v. I'm assuming the ADC input train will be at worst a few milliamps (it's more likely to be way down in the micro or nano amps), so it won't affect the voltage divider output too much.
The next test came after I populated the board. If I wire the input signal to the ground for the multiplexer board, I should expect to see a D/C voltage of somewhere in the neighborhood of that 0.46v on the ADC port.
The good news is that the ADC readings don't vary by more than 1 tick over several minutes of observation. Values 409 and 410 would correspond to just about exactly 0.4v on the scale from 1 to 1024. That's not perfect. It's off by 13-15%. I wish it were closer to spot-on, but it will be OK for the simple use case of detecting an appliance being on or off.
I wired up a pot to a power supply and took a handful of other D/C measurements:
The readings were not as rock steady as the first batch, except for 0.0v and when it finally crossed over to 1024, which happened at about 0.670. Swings of 10-15 ticks were not unusual. I'm willing to write that off as being due to a noisy environment or the inherent crudeness of the ADC itself or the multiplexer. The range topped out at 0.67v instead of the 0.54v when you take out the 0.46v bias voltage. For a range of 0.0v - 0.67v, I get 0 - 623 ticks on the ADC, or very roughly one tick per millivolt.
Since getting these results, I have been reading what other people have to say about the ESP8266 ADC accuracy. It seems to be a mixed bag, with some getting excellent results and others getting lousy results. I wish I had done some measuring with the ESP8266 Thing before soldering it into the circuit. In my next revision of this design, I will use an external ADC (maybe something based on ADS1115).
The boxHere's the inside of the enclosure with the RCA jacks in place for 4 inputs. The leads are also soldered in place. I put shrink-wrap on things because the board will be bouncing around inside there. (Pay no attention to those scorch marks around the lip of the box. They are definitely not because leaned the soldering iron in the wrong place.)
Here's the same view, but with the board put in place. It's a tight fit, but it just makes it. I could have mounted the RCA jacks a bit closer to the back of the box to give more room for the board. All that's left is to solder the signal wires to channel inputs and ground pins, snake a micro USB cable in through the knock-out tab, put a cover on it, and all's well that ends well.
When it actually came time to wire all that up and stuff it into that single-gang box pictured above, it was just too cramped, mainly because I put the RCA jacks to far away from the back wall of the box. I went on a fact-finding mission to the hardware store and found a fairly interesting double-gang box.
This box is shallow, like the first one. It's not meant for holding switches or outlets. Rather, it's a junction box for joining or splitting runs of electrical wire. That's why the cover for it is just a big, blank square. At the bottom of the picture, you can see the two mounting tabs; I cut those off. Then I mounted the RCA jacks onto the cover. I only wired up channels 0, 4, 8, and 12 on the multiplexer. It would be easy to add more if the need arose. There's plenty of room.
I happened to have a couple of panel-mount micro USB cables, which you can see between channels 4 and 12. Overall, this doesn't have quite the polished look that my vivid imagination saw, but it's decent enough for something that will live in the laundry room mostly hidden by appliances.
Software time, part 1You'll find a link to the github repository for the project code in the code attachment section. Here's a look at some measurements averaged over 100 samples per channel and then converted to mV. Even though I was testing with a DC signal, I did the computation for both DC and AC. The only difference is that DC looks at the average and AC looks at the maximum reading of the ADC.
There is a signal only on channel 0. The other channels are not attached to anything, and the values are pretty wild. They are probably picking up noise. When I max out channel 0 (reading 1024 ticks), it somehow bleeds over into channel 1 and sometimes channel 2.
If you look at the source file IoTCayenne, you'll see how to upload the 16 channels of data to a cayenne device project (https://cayenne.mydevices.com) every 5 seconds or so. Here is what a few of the channels look like in the Cayenne dashboard (again, only channel 0 is real signal).
I took lots more DC voltage measurements to see what ADC readings I got. It turned out to be pretty wild and unstable. I decided to double-check my design, and, if that didn't turn anything up, I'd see if I made a physical mistake in soldering things together.
It didn't take long. Within about 30 seconds, I spotted a horrible mistake in the schematic (which followed through to the layout and to the physical circuit). I had originally put a filter cap in to smooth out the multiplexer circuit. It was recommended by one of the articles that I mentioned above, but I'm not sure it makes sense anyhow. The idea of the cap is to let the AC component of the signal go to ground and only let the DC component pass through. But I'm trying to measure AC, as was the article that recommended it. So, I think it was just wrong.
But that's not really the problem. I had planned to put that cap between the ADC signal and one of the two ground references. Instead, I accidentally designed it in between the two ground references. I'm not sure what effect that produces, but it doesn't produce a working design for this project.
Then a miracle happened. I fixed the project by just snipping the cap right out of the circuit. Yep, I fixed a project by removing a part. That never happens. Anyhow, once I did that, the ADC readings for various DC inputs became pretty solid.
Calibration, part 1I decided to do the calibration in a couple of parts. Besides decomposing the problem, I also might use these two boxes separately some day, so I want to know their individual characteristics. You can see a spreadsheet with all my measurements (and some pretty charts) here: https://docs.google.com/spreadsheets/d/1e5aPeEg60XhoSJqownEi-AzWW4Xvsw4WGyDEjF73gLw.
First, I used a variable DC power supply to feed a range of voltages in and measured the ADC readings. I measure separately for each of the 4 channels just in case something was out of whack. As it turned out, things were pretty close among them, probably within my measurement error. Here's a graph of that showing the linear regression for each channel.
The legend shows the formulas for the lines (that overlap each other in the graph). You can see the agreement in both slope and intercept is pretty close. Even better, the intercept in the low quarter of the 400s is not dramatically far from my predicted value of 460 for the voltage divider. They also haven't strayed very far from the ground signal measurements I made with just the board.
Calibration, part 2There is tab and graph in the spreadsheet called "AC wrong". It has some interesting measurements of input AC voltages versus massaged ADC readings. They are calculated just completely wrong. Nice linearity, though. The readings didn't seem right to me, and that led me to fix the AC rms "ticks" calculation in my code.
Next, I repeated the measurements, but this time with a variable AC source, which was really just an AC-to-AC wall wart with a pot on the low-voltage end. I wasn't confident in what I was doing, so I measured the AC voltage with both my multimeter and an oscilloscope. They gave slightly different AC readings, and the graph below uses the 'scope readings, which are probably more accurate. I also measured the peak-to-peak voltage. It's not in the graph, but you can see it in the spreadsheet.
I didn't do as many different input voltages as I did for DC, but again the linear regression was pretty decent.
Mistakes were made, part 2The final piece of the calibration puzzle is drawing various current levels through the outlets in the power strip and see what AC voltages I got out of the RCA jacks.
On the first couple of measurements, I was able to see that the RCA jack for socket SE was completely dead, and the RCA jack for socket NE was wild and inconsistent. At this point, I don't know if something came loose when I had to jam all of those wires into that tiny case, or if the current transformers are damaged, or something else. The outlets themselves still work fine.
Since I only need two instrumented outlets for the planned project, I'm not sure if I'll go back in and see if I can fix SE and NE. I probably will, just because I don't like things in a broken state. ((Later: I did open up the power strip and stare at it for quite a while. It didn't say anything or even make a noise. I didn't figure out what was wrong with the instrumentation on those two outlets.))
Calibration, part 3Finally, inputs of various AC loads versus mV rms measured at the (two, alas) RCA jacks. I don't have anything remotely like a variable current AC power supply or load. I plugged another power strip into each socket, one at a time. I ran around the house like a crazy man finding things to plug in to that second power strip to provide load. A multi-speed fan and a lamp got me up to 1+ amps, but the real winner was plugging in the toaster. That by itself gave me over 11 amps. The currents you see below are from various combinations of those appliances. To measure the total current draw, I used one of those plug-in energy consumption gadgets that gave a current reading.
It's only a few data points, and there is a big gap in the middle. On the other hand, for the points available, the linear regression is not too awful.
Software time, part 2With those linear coefficients, I can take the ADC readings and deduce the AC input voltage. I can take that AC input voltage and calculate the AC current draw. Obviously, there are some compounding errors accumulating in there, but I think it will be good enough for my immediate purposes.
Perhaps later I will add some kind of switch to the ESP8266 box so I can use it to measure AC or DC, depending on the use case.
Preliminary resultsI've now wired it all up in the laundry room. Here's a picture. Pay no attention the messy cables.
I ran a medium load of laundry through both the washer and dryer. During that test, I took measurements at approximately every 20 seconds. In the steady state, I will probably meaure much less frequently. The archived Cayenne data is only one point per minute, so that's what you see in the following graphs:
The current draw for the washing machine is variable because it's doing a lot of different things through the cycle. The small period of nearly zero current near 4:20 is because the washing machine thinks about things for a little while after getting the clothes wet. Only the electronics are active at that time. (I think the actual idea is that it's letting the clothes soak for a bit before starting the main part of the cycle.)
The dryer, on the other hand, has a pretty even current draw. It's heated by natural gas, so it's pretty much just the rotation of the drum consuming the power.
Of course, there are various washing machine cycles and, to a lesser extent, dryer cycles. Still, I am confident of being able to tell the start and stop times of each within a few minutes and with a high degree of confidence.
Hardware re-doAfter I got completely done with the hardware part of this project, I decided I wasn't too happy with the looks of the modified power strip. Things are a little sloppy, mainly because of the cramped quarters inside.
I don't know why I didn't think of this before: Those so-called "industrial" power strips have outlets that can be several inches apart. I bought the least expensive one I could find and opened it up. It was rather perfect for this project. Here are pictures and less verbose comments about re-doing with this power strip.
This is the "industrial" power strip I bought. I named it Stanley. It's also 15A. It has 6 outlets, and I had 6 CTs on hand. However, there wasn't enough room around the outlet near the switch, so I only wired CTs into the other 5.
This is one of the CTs I bought earlier but didn't use in the first power strip due to size. It's also 2000:1 in the winding. It has a nice plastic housing and all-around better construction. It was still a tight fit in the re-do, but it made it.
Stanley's insides are much roomier than the first power strip. I placed the CTs under the bare wires and ran the new wires down one of the channels on the side.
Below is a close-up of one of Stanley's sockets. Although it uses bare wires, it's closer to a traditional outlet in wiring. From left to right: black, white, green. I completely removed the "black" wire and replaced it with the same sort of flexible wire I used with the first power strip, making individual runs to each outlet.
Here are a couple of the RCA jacks on Stanley. Of necessity, they are offset slightly from their associated sockets.
I spot-checked a few current-to-voltage measurements, and all 5 RCA jacks showed the same output voltages, to the millivolt. That's pretty encouraging. Here is my calibration measurement graph for this power strip. The linear fit is very good (with just one outlier point near the bottom).
Here is the final assembly mounted on the wall in the laundry room, replacing the first power strip. Now, by comparison, the blue smart box looks pretty homely. Maybe I'll redo that someday to give it a better look.
I ran into a little mystery and thought it worth describing what it was about.
In sections above, you can read about my multi-part calibration procedures. I repeated part of it with Stanley. When I got it all installed, Cayenne was consistently showing 1 - 3 amps when neither machine was running. There are various places where things could go wrong, so I started troubleshooting.
When I ran the smart box while connected to my laptop, it seemed to be doing the right measurements, and Cayenne was displaying the expected numbers. I didn't fully repeat the variable AC input voltage calibration (mainly because it's annoying to set up ... but I would get to it later if I had to). I did ground inputs 0 and 8 to see that the ADC readings were steady (within just a couple of ticks from average over many readings).
I put my meter on the AC voltage outputs from the power strip. They were 0 mV. I thought maybe they were noisy, and my algorithm of finding the max reading to calculate the amplitude of the sine wave might be fooled by catching outliers. I put my 'scope on those outputs. There were pretty flat, with a little jitter that was at most about 1 mV. That's way too small for the bogus readings I was getting.
Still, plugged into my laptop: reasonable readings; running all hooked up: crazy readings.
I still wasn't convinced that the output signal was clean, so I did a couple of things about it in software. First, I reduced the number of samples I took. I fiddled the numbers so that I would ordinarily catch just a bit over 1 full sine wave cycle. I adjusted the number of samples to be a little over twice the frequency (60 Hz for me). The idea is that 2x the frequency is enough samples (Nyquist theorem), and limiting to a single sine wave cycle would reduce the chances of catching an outlier. Long story short, those are both things worth doing, but they made no difference at all for this problem.
Next, I started looking into a better way to get the amplitude of the AC signal. I believe the best way would be to collect all those equally-spaced sample points and do a regression calculation to find the best-fitting sine wave parameters. Once I had that, the formulaic amplitude of that sine wave would give me a good value because the regression would minimize the effects of any outlier data points. This is theoretically straightforward (the school-monopoly TI graphing calculators reduce it to a button), but in practice kind of complicated. I wasn't sure if it would even fit within the resources of the ESP8266.
It was a side-effect of the complexity of the sinusoidal regression calculations that prompted me to try something else first. As a sort of compromise between running while connected to my laptop and running while all wired up, I ran the smart box off a USB power pack but with the AC inputs connected. The crazy readings immediately vanished. Putting it back on the plug-in USB charger made the craziness return. It all came down to my using a crap USB charger. I have about a half a bushel collection of USB chargers of various types, so I just kept swapping them out until I found one that gave the expected smooth readings on the Cayenne dashboard. Mystery and problem solved.
Generic MQTTAlthough I started this project by feeding data to Cayenne, it's been a couple of years since that time. It's now July 2021. I have more sophisticated facilities of my own, so I made a version of the code that talks to a a generic MQTT server. The Cayenne version is still available as well as the generic MQTT version. See the github repository for details.
Comments