The Wiring in our House

I continue to learn how our house is wired.  Here’s where all the breaker switches are located:

IMG 6214

We started out with the original box.  Then when we added a generator, the other panel was added.  I have been adding energy monitoring hardware goo to wires in the newer panel.  For example, I live to tell about my installation of a Sense monitor.

IMG 6215

I bought and installed the Sense because I wanted to experience a consumer ready experience and the idea of the Sense figuring out what appliances were in my house intrigued me.  How good was it at doing this?  What I enjoyed most was how easy it was for me to start tracking our energy use.  I didn’t have to figgle around with config files, go through any complex setups – it just worked.  Now I figure I can DIY the hardware and software for my HappyDay Neighbors project.

When I started exploring what CTs to use, I noted:  I measured the wire gauge of the two wires where the Sense CTs are located.  They are  1/0 AWG.  This surprised me since most cable examples I had seen on the Internet used the wider 4/0 cable.

Hold on.  Wait a minute.  It became clear to me I didn’t understand our wiring.  In particular, where the heck is the mains breaker switch?  How is the electricity really flowing in from the transformer?  What Amps? 100A? 200A?..I dunno…

Bumbling back to the original breaker box, here are the innards:

IMG 6225

Hmmm….couple of things I am not sure about:

  • I expected to see a neutral wire in the center.
  • I expected to find a mains breaker.

But I didn’t.  Is this because of the installation of the generator and the newer panel?  Where is the mains breaker?  Why isn’t there a neutral wire?

Advertisements

Getting the Hardware Together – the Current Transformers

I’m (still?) getting up to speed on how electricity flows through our house and how use is commonly measured. ..

The Goal

The goal of this post is to:

  • explain why I chose to buy two SCT-013-000 CTs.
  • write down my understanding of how 240V electricity comes into our house.

Our House

All the energy monitors I know about use Current Transformers (CTs) to read the voltage and current used by appliances within a house.

Our house is wired with a three-wire single phased system.  As the Wikipedia article notes: This three-wire single phase system is common in North America for residential and light commercial applications. In this case, the voltages are 120 V line to neutral (grounded center tap of transformer) and 240 V line to line. This system allows 120 volts to be supplied for lighting and convenience outlets, and 240 volts for higher-demand appliances such as space heating, air conditioning, kitchen stoves or water heaters.

I copied this image from Home Depot’s Basics of Your Home’s Electrical System video:

Pasted Image 9 20 17 3 50 AM

The Learn section of OpenEnergyMonitor has a great article on North American Power Supply characteristics.  It includes this diagram:

As is true with my house: Standard practice among US electricians is to connect the circuits to the breakers in numerical sequence, with odd numbered breakers connected to one leg and even numbered breakers connected to the other leg. Thus, half of them will be on one leg, half on the other leg, with the aim being to balance the load evenly.

The implications of North American Power Supply characteristics to the firmware are briefly covered on the Use In North America/OpenEnergyMonitor’s setup guide.

Ordering CTs

How Many

Given the split of the 240V into two 120V lines, I will need two CTs, one for each line.

What Size

I used my caliper and measured the diameter of each of the 120V cables to be .32” or 8mm.

IMG 6222

According to the AWG wire sizes, this makes the cables 1/0 AWG.  This surprised me since I most cable examples I had seen on the Internet that had similar wiring to our house was 4/0, which is significantly wider.  Perhaps this is because the panel is actually a sub-panel that was put in place when we had a generator installed.  I didn’t open the original (main) panel.  Perhaps the cables for the 2 120V lines are 4/0 in the original panel.

IMG 6214

YIPPEE! This means I can use the common SCT-013-000 (data sheet).  YHDC sells several different CTs.  The SCT-013-000 is the one sold by OpenEnergyMonitor.  I would have ordered from their store.  Unfortunately, I would have to pay to have it delivered from the UK.  Instead I ordered two from Newegg.com.  

 

…so much for that…

Jupyter Notebooks are Awesome

I made my first Jupyter Notebook.  I had installed Jupyter awhile back after listening to Adafruit’s Python Playgrounds LIVE! Youtube video.  The video got me totally inspired by the Python community and the usefulness of Jupyter Notebooks.  The blog post documents my first experience creating a Jupyter Notebook.

Thanks To Those Before

  • A HUGE shout out to Tisham Dhar.  Tisham is the creator of the ATM90E26 Single-Phase Energy Monitor Dev Kits.  I just found out about Tisham and his work.  I have been impressed with the intelligence and care Tisham has taken to Open Source his work.  Tisham also kindly answered all the questions I peppered him with.  His work looks super sharp to me.  I have already learned a lot from what he has Open Sourced.
  • Adafruit for their Python Playgrounds Youtube video.  I learn quite a bit from Adafruit’s learning sections and videos.  This inspirational video got me yearning to play with Python and Jupyter Notebooks.

On To The Show

A few days back, I found out about Tisham’s fantastic work. In particular, the ATM90E26 Single-Phase Energy Monitor Dev Kits.   YIPPEE!!!…but..bummer…I won’t receive them until December 5th.

So I emailed Tisham if there was a way for me to get my hands on some of the data output (power readings over time) so that I can start working on the end user side of the Neighborhood Energy Monitoring Project I decided to start up.  Tisham kindly gave me access to his Jupyter Notebook that pulls data from his feed. 

Not letting the fact that I have an advanced beginner knowledge of Python and no knowledge of how Jupyter Notebooks work, I am happy to say after a few hours, I was able to create a Jupyter Notebook that fetched energy data from Tisham’s ThingSpeak feed, plotted the data, and wrote the data to a CSV file.

 

ChallengesBringOpportunites Talk about exhilarating.  I can see why I am hearing more about Jupyter Notebooks.  What a fun environment.  It reminds me of the times I used Swift Playgrounds when I was programming on the iOS.  A great thing about Jupyter Notebooks are the incredible amount of extremely powerful libraries available – for AI, machine learning, image recognition, plotting…tons of stuff I don’t understand….

 

Now that I have sample energy data to simulate what would be coming from DAH cloud to the web browser and/or smart phones, I can prototype this software as I wait for Tisham’s dev kits to arrive.

New Project: Neighborhood Energy Monitoring

Tags

, , ,

I decided for my next project to build an energy monitor experience for our neighborhood.  My goal is to change our behavior from wasting to saving energy.  

Hardware will be placed in our breaker boxes that monitor the voltage and current being provided to the house.  The hardware includes:

  • CTs on the mains lines (the white circle with clamps on the breakout box image)
  • Sensors, micro controller, and wifi to read in, digitize the current and the voltage, and send the readings to dah Cloud.
  • A web browser or smart phone app knows how to access the current and voltage readings that are stored in dah Cloud.  The readings are displayed as a graph.  This way, we can tell not only how much electricity is being used, but also what appliances are using the most electricity.  Using this information, we can adjust our electricity usage to bring the amount we use down.
  • A social app (on Facebook?  Twitter?  Text messages?) will reward members of our neighborhood with knowledge of how much CO2 they have saved from being released into the atmosphere – as well as other social game techniques.  Social gaming will be a method to get a social bond around energy conservation.  Perhaps from this we can decide as a group to install solar panels on our houses, etc.
I plan to use these blog posts as a way to document my progress.

 

Installing the Sense Monitor

I bought a Sense Monitor.  

NewImage                  NewImage

I am thrilled to see technology that uses a non-invasive method to monitor our home’s power usage than figures out what device is using what power.  I have this thought it would be most excellent to build one as a DIY project….As their product page notes: “Over the next few weeks, Sense will start automatically identifying devices, reveal trends in your power use, and keep getting smarter!”  OOH – I just had to have one.

Thanks To Those That Went Before

  • Ken at Home Depot.  Ken is a major reason to shop at Home Depot over Amazon.  Ken is a retired mega-electrician-manager (truly exceptional) who works at my Home Depot most mornings.  Here is just one of the many examples of why I am a HUGE fan of Ken’s.  Which makes me a HUGE fan of Home Depot.  The Sense installation requires a 2 pole breaker.  Easy enough to Google and figure out about 2 pole breakers.  Easy enough to check in my breaker box and make room for one.  BUT…even after carefully measuring the dimension of the 1 pole breakers, I still would have not know they were QOs. After all, there is no marking on them and until I knew about QO’s I didn’t know to Google QO.  If I did, I would have gotten this Square D Wikipedia page and enlightenment would follow.  Prior to going to Home Depot, I removed a 1 pole breaker from our box.  (aside – silly me – I thought no devices were using this circuit.  Imagine my surprise when I open the refrigerator and it’s power is off…ooopssss….now the time crunch began or my left overs were going to go bad.  Not happening on my watch!).  I bumble my way to the Home Depot electronics aisle, truly delighted to see Ken (another aside – Ken is a really nice person although he wasn’t as enthusiastic to see me.  Perhaps he was being professional? 🙂 ).  I show Ken the 1-Pole switch.  Ken looks at it and starts walking to this bin I hadn’t noticed.  Since there are oh – I dunno – about a gazillion different circuit breakers spanning several bins (another aside – it’s about as confusing to me as the cereal section is in the grocery store.  I mean – how many variants of cereals do we need?  Seriously…but I diverge).  Then Ken pulls out the 2-pole QO and explains the story of QO versus the HOM model. The two different models look similar to me and the display I picked circuit breakers from were the HOM models – which wouldn’t work.  But I’m leaving out the best part.  The best part is the story of why our breaker box has the QO models.  Ken says they are the older model.  More recently, Square D started making the HOM model – for well, homes.  Now, yes.  Any electrician would have known this.  And indeed I could have had an electrician do this.  But what’s the fun in that?  I would have missed talking with Ken and hearing his narratives on why electronic components are the way they are.  Can Amazon provide that?  I think not.  Would I ask the electrician that came to install?  No….  So THANK YOU KEN.

Installation

I followed the instruction in the installation guide, ignoring the part…Installing the Sense monitor is easy, but should only be done by a qualified electrician.  

NewImage

the key to my living through the installation was using one of these:   

IMG 6211

What a wonderful tool. A must for this project.  All I need to do is touch the point to a wire in the break box.  If the wire is hot/live, the tip flashes red and the tool starts beeping. What a lifesaver (literally).

Turning off Power

Here’s the electricity setup in our garage:

IMG 6214     IMG 6213

In between the active panel and the older panel is the “big gray” transfer power from the company that installed the generator.  We’ll make this area even more complicated when we install solar.  But that is in the future.

It was a bit of a search to find the mains switch.  Many years ago we installed a generator that kicks on when there is a power outage.  After googling a bit, I found terms like “sub-panel” that helped me realize the mains breaker switch was on the other panel labeled “sub-panel.”   

Connecting the Power

Connecting the power requires the use of a double pole breaker.  Luckily, we have room in our breaker box.

IMG 6187

I told the story of getting a 2 Pole breaker earlier.  Following the rest of the directions that came with the installation info with the Sense is easy.  

IMG 6215

 

All the pieces fit nicely into the breaker box.  I thought the design was well done.  The antenna fits nicely.  To insert it, I just removed a knockout.  The CTs fit easily around the main cables.  As I noted, installing the 2 pole breaker and connecting the three wires (red, black, and white) was easier than working with a breadboard.

Wait

So now I wait for the Sense to detect our devices.  The software says to give it a week…so I wait…I wait….but YIPPEE!!! I’m excited to see how well device detection is and what conclusions can be made about our current energy consumption.  Will what we find out change our behavior?  I come into this experiment assuming we waste a significant amount of energy we don’t even realize we are wasting.  I’d like to stop that.

 

 

Thanks for reading this far.  Please find many things to smile about.

Summer Project: Automatic Irrigation

The summer is pretty much over so I decided to finish up my summer auto irrigation project with a post.  I’ve had a few posts about the progress I have made on my summer project to implement an automatic irrigation system.  I have not had a summary post describing the different components.

The Goal

The goal of this post is to document the project.  Included:

  • a high level documentation of the auto irrigation system I implemented.
  • links to the code and anything else needed to rebuild the system.

Thanks To Those That Went Before

  • Adafruit for great products and services.  Their prototype stuff and Adafruit.io made this project possible.  What an excellent company.  THANK YOU.
  • Ray’s DIY Electronics Hobby Projects – An exceptional open sourced open sprinkler hardware and software project.  In particular, Ray provides thoughtful blog posts on stuff like how to use a 24VAC irrigation directed power source to also power a microcontroller.  THANK YOU.

Open Source

The Arduino sketches for the Controller, Moisture Puck and Watering Puck are located at this GitHub location.

High Level Diagram

The Job of the Auto Irrigation System is to water the plants when the soil is dry.  It is “smart” about this by not overwatering and watering at the best time of day to do so.  The  Auto Irrigation System consists of three pieces of hardware:
  • The Moisture Puck whose job is to send moisture info to the Controller.  I covered aspects of the Moisture Puck in this post and in this post.
  • The Controller whose job is to coordinate between the Moisture Puck, Watering Puck, and Adafruit IO.
  • The Watering Puck whose job is to turn on/off the irrigation valves.  More on the Watering Puck in this post.

A Bit About the Hardware

Since I didn’t know what I was doing when I started, all hardware is prototype.  It is either too expensive, too cobbled together, or not robust enough to be “mass produced.”  However, I am happily using the system.  I like to think and evolve these type of projects.  My hope is next year I will feel inspired to improve….until one day…who knows?  Every member of my family is using this system :-).

Interaction Between

The Moisture Puck, Controller, and Watering Puck talk to one another using the RFM69 wireless protocol at 915 MHZ.  The Moisture and Watering Puck use the Adafruit Feather M0 RFM69HCW.  

The three pieces of hardware wirelessly communicate with one another using the RFM69 wireless protocol at 915 MHz.

  • When the Moisture Puck is powered on, it requests and receives the current time (i.e.: current hour, minute, second).  This gives the Moisture Puck the knowledge to know when it is 4AM.  4AM is the time I determined is best to water the plants if they need watering.
  • At 4AM every day the Moisture Puck takes a moisture reading and sends the reading along with readings for the battery level and chip temperature of the RFM69 to the Controller.  The Controller checks to see if the reading is below the threshold for determining if the soil is dry.  If it is, the Controller tells the Watering Puck to water the soil.

Interaction With The Internet

The Controller talks not only to the pucks, but also to Adafruit.io over…DAH INTERNET….So the “heavy lifter” is the Adafruit Feather ESP8266 Huzzah.  Sitting on top of the Huzzah is the RFM69 FeatherWing.  The Huzzah yaps it up with Adafruit.io and runs the Arduino sketch.  The FeatherWing yaps it up with the Pucks.

Keeping Private WiFi Password, SSID and Adafruit.io AIO_USERNAME, AIO_KEY

I used the WiFiManager library to keep the WiFi stuff:

#define WLAN_SSID       “XXXXX"
#define WLAN_PASS       “XXXXX"

private.

Then there is the Adafruit.io private stuff:

#define AIO_USERNAME    “XXXXX"
#define AIO_KEY         “XXXXXXXXXXXXXXXXXX"

I put these into an include file (AdafruitIOLogin.h).  I added AdafruitIOLogin.h to .gitignore when pushing the sketches to GitHub.

Adafruit.io

I created a dashboard on Adafruit.io:

NewImage

and several feeds:

NewImage

I ended up not using the water feed.  The water feed is fed by an IFTT channel.  The channel lets me know when sunrise and sunset occur.  I was going to base watering on these values.  However, after thinking through watering, I decided it best to water at 4AM each morning.  I like knowing how the sunset and sunrise change over the days so I leave the feed in.

The feeds I pay the most attention to are the ControlInput and Log feeds.  

Control Input Feed

The ControlInput feed accepts commands that are sent to the Controller.  The challenge with using commands through Adafruit.io to get to the Controller is about 1/3 of the time I have to enter the commands multiple times.   To make sure a command completes, I open two Adafruit.io web pages – one focused on the ControlInput feed and the other focused on the Log Feed.  More on the log feed in a bit.

The commands include:

  • threshold=<value>  where the default value is 215.  Notice in the above images the moisture reading was 246.  The Controller checks this reading against the threshold value to figure out if the watering puck should water.  When the threshold = 215… 246 > 215 so watering does not happen.  If I enter the command threshold=247, 246 < 247 so watering would occur.  The Controller remembers the threshold value and will use it as long as the Controller is not rebooted.
NewImage
  • zones= <zone color> where zone color can be blue, green, yellow or a combination.  For example zones=yellow,green will tell the Controller to only ask the watering puck to  turn on the valves that are labeled yellow and green.  
IMG 6138

I put in three valves and color coded them.

NewImage
Notice the zone=yellow in the ControlInput feed.  The command that the Controller recognizes is zones= (or ZONES = …or ZoNeS=…).  The log feed gives me feedback on whether command is correct.  In this case, I received:
NewImage
  • start commands the Controller to tell the watering puck to start watering.  This command is useful when I want to force watering which was the case when I added an irrigation line to water our trees.
  • stop commands the Controller to tell the watering puck to stop watering.

Log Feed

I use the log feed to know whether a command got to the Controller and as a way of debugging.  I broke up the Controller’s activities into states.  The below logged the Moisture Puck sending data to the Controller and the Controller checking the moisture reading against the threshold.  In this case, the reading was above the threshold so no watering.

NewImage

Here is a section of the log feed when the start command is entered:

NewImage

IFTT

To explore IFTT integration with Adafruit.io, I explored these feeds:

NewImageNewImage  NewImage       Pasted Image 9 12 17 4 56 AM

The only one I am using to control the system is the battery level notification that goes to my cell phone.  I am having a challenge with the LiPo battery.  All of a sudden, readings went from somewhere around 4V to 3V on the next reading. The readings started waffling around 3.2V.  I think (not completely sure) the battery got damaged from being out in the garden when temperatures on the battery’s surface got around 100˚F.  If this keeps happening, I’ll look into it more.

And That Is That

The great news is everything works and I learned a lot.  Plus, there were issues with our plumbing that this project surfaced and we then fixed.  There is more I can do to make the system more robust and all that good stuff.  But for now, I am saving a lot of time not having to hand water the different areas of the house.

On To The Watering Puck

I got automatic watering working almost a month ago.  Then I broke it:

  • Turns out there was a problem with the water valves in the house.  These had to be fixed.
  • As I got more familiar with RF69 traffic / library, I realized RF69 messaging is best done to completion within (a tight) loop().  I had spread out the RF69 messages into functions in which I would loop through expecting a specific message.  The challenge with this is the Controller sent/received messages in an unpredictable way because the Controller is dealing with both MQTT traffic and commands as well as RF69 traffic.

The Goal

The goal of this post is to document the implementation of the first beta of the Watering Puck. 

Thanks To Those That Went Before

The Valves

I decided it made the most sense to use off-the-shelf solenoids from Orbit and a 24VAC power supply.  24VAC is the standard used in irrigation systems.  

Orbit Valve Box Base (YouTube video description

 I also got a “professional looking” enclosure, base and 24VAC Power (all Orbit products).  I watched this video on getting the wiring straight.

The Relays

I am using these three relays.  The cost was  ($13 for 4)/4 + $8 shipping (I ordered 4)  = $11.25 (high shipping cost).

Always looking for a good explanation on how relays work.  I found dial2fast’s How Does a Relay Work Youtube video to be very clear.  The DC current flows through copper coils inside the relay.  This generates a magnetic field which moves the switch to the other side.  NO (Normally Open) moves the arm from the open circuit to closing the circuit and letting the 24VAC flow through the valve.  

This image from 12VoltPlanet works for me:

NewImage

Since I am not smarter than a 5th grader, I thoroughly enjoyed these videos on how electricity can be used to create a magnetic field as is done within this relay.  In UniServeScienceVIDEO’s Magnetic Field Demonstrations Youtube video, there are three demonstrations that are fun to watch.  Jeff Regester’s Magnetic Field of a Coil of Wire Youtube video demonstrates a compass spinning when electricity goes through the coil.  I like both. UniServe’s is great in that it shows the motion of the magnetic field.  Jeff;s is awesome because it shows the standard physics class example.

Powering the Feather using the 24VAC

I want to run the Feather off the same 24VAC Power supply being used by the valves.  I’ll do this by adding a way to smooth out the AC waves into a flat DC line as well as a way to down shift the power from 24VDC to 5 VDC and connect the Feather through the USB port.  

First Attempt

My first attempt used this setup:

  • Rectifier circuit to convert AC to DC.  I’m thrilled to see the need for the rectifier circuit…of course, I couldn’t leave home without it if I’m ever taking AC to DC…I spent time understanding peak detection/rectifier circuits when I designed and built the Ladybug Shield.  Based on this experience, and the great advice in Dave’s excellent EEVBlog #490 Peak Detector Circuit.  I am going to use the very simple diode + capacitor peak detection circuit Dave talks about at the beginning of his video.  I am not doing any precision measuring as was the case with the EC circuit of the Ladybug Shield.  Rather, I just want to get the signal ready as input to the DC-DC Buck Converter.  While the diode will eat up about .7V, I don’t need to adjust anything because I’m not interested in the actual DC value.  Sure this method of rectification leaks current and drifts over time.  However, for this scenario that is ok.
  • DC-DC Buck Converter – The VDC output after using the rectifier circuit measured 40V. 
My first attempt “sort of” worked.  The DC signal was very noisy.  I was having trouble at this point with the electronics of the watering puck so I decided to do a better job with going from 24VAC to 3.3VDC.

Second Attempt

  I decided to use the schematic I found on RAYSHOBBY.NET:

NewImage

Since I easily forget how different components – such as diodes – do their magic, I thought Sparkfun’s diode tutorial was helpful. 

Parts I need:
  • D2 – 1N5819 Schottky Diode (Digikey)
  • C1 – 100µF / 50V Capacitor (Digikey)
  • L1 – 150 µH / 800mA Inductor (Digikey)  …argh I forgot to order this, so I ran down to our local electronics store.
  • IC1 – MC34063 (Digikey)

Parts I have:

  • D1 – Diode
  • C2 – 220µF/6.3V Capacitor
  • RT – 30K Resistor
  • RB – 10K Resistor
  • CT – 100pF Capacitor
  • RSC – 2 1 Ω Resistors
As I put this together on a prototype board, I realize my skill at layout of these simples skills could use a lot more practice. hmm.. I went put together two prototypes….
IMG 6101          NewImage
…and yet…sadly…I did get to see the inside of a capacitor…hmmm…
on to my third attempt.

Third Attempt

This time I’m going back to the first attempt – that is using the DC-DC Buck Converter.  However, the rectifier design I’ll use will be the more effective full wave rectifier.  Afrotechmods did an excellent YouTube video on this type of rectifier.

 

NewImage

The above image shows the difference between using a half-wave and full-wave rectifier.  The full-wave rectifier uses both the positive and negative parts of the AC to recharge the capacitor.  Much better.  I’ll use that technique.

Capacitor Size

What size of capacitor should I use?  Afrotechmods shows a design with a 1µF capacitor when there is no load:

Pasted Image 9 2 17 4 27 AM

The voltage will be 3.3V, the amount of current drawn will be about 35mA.  I guesstimate 35mA based on the RFM69 tests I did in a previous post.  Using the formula noted in this post:

NewImage

I = .035A

t = 1/60 Hz  = .0167s (NOTE: See DOH! below…)

for the ripple I’ll use 1V.

C = .035 * .0167 / 1 = .0005845  = 585 µF.  I need a capacitor that is at least 585µF that can handle around 50V.  I found this 680µF/50V capacitor at my local electronics shop.  The voltage ripple I should see V = .035*.0167/.00068 = about .86V.  Even better!

So crafty me…I built one:

IMG 6116

but…

Simpson DOHum… I screwed up for the time period.  Full wave is at 120 Hz, not 60 Hz.  So:

t = 1/120 = .0083

C = .035 * .0083 / 1 = .0002905  = 291 µF.  

DOH-DEE-DOO..I’m leaving the 680µF capacitor.  Overkiil, but from what I can tell should mean even less ripple.

 

The Firmware 

Arduino Sketch

The firmware code, WateringPuck2017_v3.ino, is located at this GitHub location.

Logic Pins

I needed to make sure I used available logic pins…Looking at the Feather m0’s logic pins

 I’m going to NOT use:

  • any pin between A0 and TX1
  • pin 13 since it is used by the LED
  • the SCL and SDA pin
ChallengesBringOpportunites And YIPPEE!!!! It all works…

 

First Attempt at Energy Monitoring

I want to measure how much electricity our family is using.  This way, we can find ways to use less.  Lucky for all of us, there is the OpenEnergyMonitor project.

Thanks To Those That Went Before

OpenEnergyMonitor (OEM) project – It is inspiring and exciting to be able to benefit from the vast amount of information and resources provided by the OEM project.  In addition, the folks participating on their forums are exceptionally responsive and helpful.  THANK YOU.

boblemaire’s IOTAWATT project – What a fantastic source!  THANK YOU.

My First Prototype

The goals of my first prototype are to:

  • gain an understanding of how to build a DIY electricity use monitoring system.
  • evolve my thoughts on how I want myself (and potentially others) using this system (e.g.: if my neighborhood participates, can we collectively lower our use?).
  • Build a prototype that is the simplest possible to figure out stuff.

The High Level Design

This image shows the major components of the prototype:

For this project, I decided to measure the current flowing through the circuits instead of the main line.  The maximum current that can flow through each circuit in our house is 20A.  The voltage is ~ 120V.  This means the maximum power a microwave, toaster, or any combination on a circuit can draw is P = IV = 20*120 = 2,400 Watts.  Looking at our microwave, it requires 1,250 Watts.  The circuit breaker would constantly be flicking on if I were to try to put two of these microwaves on the same circuit.

The CT is attached to one of the 20A circuits in our panel (1).  The CT has a 3.5mm jack(2 & 3).  This AC circuit gets converted to DC through one of the Feather M0’s ADCs.  RFM69 is used to communicate with another device within my house.

Energy Monitoring 101

This recollection is really for my own benefit since I am a novice when it comes to energy monitoring.  Besides, any project that has me in close proximity of a high voltage of electricity commands my respect.

A question I have going in is how do we go from a wire that provides 20A to an area of our house to measuring some appliance using the electricity?  I mean, I can’t very well measure 120V and 20A with my trusty Arduino…even if it is the mighty Feather…

Lucky for me, the OpenEnergyMonitor web site tries very hard to explain all this to me.:

The first thing I needed to understand was the job the CT played in energy measurements.  The job of the CT is to produce an AC current that is proportionally lower to the AC current that is flowing through the house.  The amount the CT scales down the current is the amount needed to be measured by the voltage/current constraints of the chips the measurement hardware is using.  In the example above, the current needs to scale such that it can be measured by an Arduino.

The CT

The CT I got for this experiment

NewImage

 has the following specs:

NewImage

and schematic:

NewImage

I noticed on the specs it says Iout instead of Vout.  Given the 0-1V output and schematic, I assume the spec should be Vout for this model.

From what I can tell, split core CTs from YHDC are popular with the OEM folks.  The OEM project describes the YHDC sensor they tested in this post.  Looking at the YHDC web site, I got a better feel for which sensors output current and which output voltage.  For example, here are a few:

NewImage

In addition, the number after SCT is the hole size.  The 13mm diameter hole size was big for the wires coming off of the breaker switch.  Eventually I’m interested in measuring all the wires, so I ordered an SCT006 from eBay.  I’ll figure out how to set up the circuit when it comes in.

The Turns Ratio-1

To understand the importance of the turns ratio, I like the image drawn during this video:
NewImage

In the case of the CT I’m using, Np = 1 and Ns = 1800.  So the current coming in (Ip) is scaled to 1/1800 in order to get to the measured current (Is).  So if an appliance used a full 20A, the CT would scale this to 1/1800*20 = 10mA.  10mA…I’m much more comfortable measuring that amount of current.

CT Output

What gets measured out of the CT depends on the CT.  The one I got returns a reading between 0 – 1 V.  What this tells me is it has a built in Burden Resistor.  

Negative Voltage

The challenge then is how do we measure negative (AC) voltage?  The same way I did when I designed the EC circuit – which I called a floating ground.  Thisis also commonly called a bias.

Notice R1 and R2 in the image.  These create a voltage divider that lifts (biases) the ground up from 0V to 1/2 the voltage of the Arduino (which in the diagram is 5V – so the bias is 2.5V).  The GND connection of the CT connector is connected to the mid-point of the voltage divider.  Thus, readings will be (positively) biased by 2.5V.  A reading would be Is a secondary voltage reading( which in our example will be +/- 10mA) +2.5V.

Wiring

For my hands on part of my energy 101 learning, I set up the circuit OpenEnergy kindly provided.

 

 
IMG 6070IMG 6059
I mounted the female side of the jack to a proto board.  This way I could make sure the signal got from the CT to the Arduino’s A1 pin. 
 
I ended up putting the CT around two circuits because of space constraints.  So instead of measuring a max of 20A, I am measuring a max of 40A.
 
The CT has a 3.5mm male jack.  I used this female jack from Digikey:  

Pasted Image 8 13 17 1 11 PM

NewImage

 

 

 

 

 

 

 

hooking 1 on the female jack to the BIAS on the breadboard and 2 to A1 of the Arduino.  

Software

I ran the current_only.ino Example that comes with the EmonLib library.

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"                   // Include Emon Library
EnergyMonitor emon1;                   // Create an instance

void setup()
{  
  emon1.current(1, 60);             // Current: input pin, calibration.
}

void loop()
{
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only
  
  Serial.print(Irms*123.7);	       // Apparent power
  Serial.print(" ");
  Serial.println(Irms);		       // Irms
}

Calibration

Why did I put 60 for the second variable in the call to current (i.e.: emon1.current(1,60) )?

The OpenEnergyMonitor docs includes a section on current sensor calibration.  I found the most important info to be:

 

If you use a current transformer with a built-in burden (voltage output type)

(MY NOTES: I am…see below).

Look at the last line of the theory where the current constant is derived:

current constant = (100 ÷ 0.050) ÷ 18 = 111.11

“100” is the current transformer primary current, and “0.050 × 18” is in fact the voltage across the burden resistor for the standard CT and burden at that current, so to arrive at your current constant you simply substitute your transformer’s rated current in place of “100” and the voltage it gives in place of “0.050 × 18”. For example, the YHDC SCT-013-030 gives 1 V at a rated current of 30 A, so for this transformer you have:

current constant = 30 ÷ 1 = 30
(MY NOTES: I am using the YHDC-SCT-013-060.  In this case, the current constant I will use is 60….and yah - looks like I don’t need a burden resistor).

Or to put it in words, the current constant is the value of current you want to read when 1 V is produced at the analogue input.

Irms

I am sadly intimidated by terms like “Root Mean Square.”  It sounds so physics/math related.  It sounds so much like the professor who always glared directly into my eyes  when he said “Assuming you have the intelligence….”  (seriously!..as an aside, if you have a daughter, don’t let this happen to her…).  Anywho, I think of Irms is the DC equivalent value of an AC current.  While this video starts off slow, “The Concept of RMS” gives me a feeling for Irms (Vrms) perhaps assuming I don’t  have the intelligence….

in the call to the sampling function: emon1.calcIrms(1480); I left the number of samples to what the script recommends.  Here’s a little bit more info (from this web site): The sketch reads approximately 106 samples of current in each cycle of mains at 50 Hz. 1480 samples therefore works out at 14 cycles of mains. That will give you a good average reading. You can change the number, but you should get as close as possible to having a whole number of mains cycles, otherwise if you have only part of a cycle on the end, you will introduce an error.

 

Measurements

Before I list some numbers, I should point out my simple project isn’t measuring voltage.  This means I’m not measuring the real power being used.  Rather I’m measuring the apparent powe

Apparent Power

Note: I am writing this section for my own benefit.  By doing so, I can use wording that helps me understand Apparent Power since it is a key aspect in AC Power measurement.

I found the following info the most helpful:

I am thrilled to have done this experiment if only to learn more about AC Power.  So far, my focus in electronics has been around Ohm’s law – DC Power.  I didn’t know one way or the other about AC, but assumed it too follows Ohm’s law.  Well, most of the time it doesn’t.  If the load drawing current is like a resistor – e.g.: things that use resistance to heat or light – incandescent light bulbs, hair dryers, toasters, and kettles…then P = IV.

However, most of the loads in our houses (as note in this document):

  • Refrigerators, Freezers
  • Air conditioners (all types)
  • Fluorescent lights including CF lights
  • TV, computer, stereo, any wall-wart
  • Microwave Oven
  • Washer, Dryer
  • Vacuum cleaner
  • Fans
  • Power tools: grinder, electric saw, compressor, etc.
  • Humidifier, dehumidifier
  • Garage door opener, pool pump, electric lawn mower, etc 

use inductors and / or capacitors which momentarily store some of the energy and then return it to the energy source.  This means Power measurements using the simple IV calculation that is used in the Arduino sketch for this project where the voltage is approximated at all points to be 123.7V (based on a Kill-A-Watt reading),  will be higher than the actual amount of power being used.

Not Much Load

Here are some measurements I got when I wasn’t running much on the circuit:

0.23 123.7 28.97
0.27 123.7 32.83
0.33 123.7 41.16
0.28 123.7 34.61
0.24 123.7 30.18

The first column is Irms, the third column is the first column multiplied by the second column = Apparent Power.

Microwave

When I turned on the microwave, I got readings like these:

33.94 123.7 4198.91
32.5 123.7 4019.83
30.85 123.7 3816.13
31.82 123.7 3935.75
31.83 123.7 3936.79
31.79 123.7 3932.57

Certainly a much higher amount of Apparent Power.

Coffee Machine

I have a fairly elaborate coffee machine.  The first thing it does upon turning on is heat to 200˚F.

25.41 123.7 3143.41
25.17 123.7 3112.98
25.25 123.7 3123.45
25.23 123.7 3121.1

Heating takes a lot of energy. Given that this process is heating, I assume the Apparent Power is much closer to the real amount of power being used.

What’s Next

To evolve my knowledge, I plan to measure the real amount of power being used coming in from the source rather than one of the (smaller) circuits.  By doing this, I can compare/contrast my readings to the monthly readings I get from my energy provider.  Using these results, I can calibrate future energy monitoring projects to accurately reflect the amount of energy actually being used.

 

 

 

Thanks for reading this far.  Please find many things to smile about.

We’ve Got Mail

ChallengesBringOpportunitesI’ve been delighted with the results of my We’ve Got Mail project.  Now we know when mail is put into our mailbox.  Our mailbox is down the road from our house.  There are days when my husband goes down and checks for mail delivery several times.  A little exercise is a great thing.  But some days it is cold, rainy, and dark.  

NOT ANY MORE – when mail comes, the super-dah-dee-duper We’ve Got Mail home device starts to sparkle…a DEFINITE YIPPEE moment…It knows when to sparkle because the Mail Box Puck – which sits inside the mailbox – sends a message to the controller when the mailbox door is opened.

WeGotMailController

This can’t be seen in the image, but the top of the device’s enclosure is printed with translucent filament.  When mail comes, the neopixel FeatherWing starts lighting up in a sparkle panel.  There is a button on the left side of the enclosure that turns off the sparkling.

Thanks To Those That Went Before

I am very grateful for the knowledge, excellence, and practical use of:

  • the RadioHead RF arduino libraries.  These libraries have been the backbone of my radio projects.  Well done.  My only challenge is in power management with the m0 – getting to deep sleep requires waiting for an interrupt.  My current challenge is the RF library takes over the interrupt I define for RF traffic.  When I put the m0 in idle mode 2, I get the interrupt.  When I put the m0 into deep sleep and wait for an interrupt, I don’t receive one.  I should do more investigation.  However, at this time I want to make progress on other project.
  • Adafruit products and services.  THANK YOU for the spirit of “We all do better when we all do better.” (see Al Franken’s book).  For the RF95 feather, neopixels, their exceptional service, exceptional support, exceptional videos.  From all I can tell employees are treated well.  They care about each other and us.  It would be SO AMAZING if more companies shared the “We all do better when we all do better” spirit.
  • John Ericksen’s really nice neopixel sparkle sketch.  It would take me a long, long time to figure out the graphics/math and put this together.  John made this easy and shared it with us.  THANK YOU.
  • Tweaking4All’s also really nice Fire neopixel sketch.  Same comments as with John’s work.  THANK YOU.
  • Jeremy Bloom’s tutorial on using hardware to debounce button input.

Open Source

The two Arduino sketches I used:

  • GotMail_Home_V2.ino
  • GotMail_MB_V1.ino
are located at this GitHub location.

The Goal

The goal is to build a Mail Box puck and Controller that lets us know when mail has arrived.  The Mail Box puck sits in the mail box.  When the door is opened, it sends a notification to the Controller.  The Controller is responsible for:

  • receiving the message from the Mail Box puck.
  • sparkling when it receives the message.
  • turning off sparking when a button is pushed. 

The Hardware

NewImage

The Mail Box Puck

MailBoxPuck

Thankfully, the RFM95 LoRa sends a strong enough signal to easily reach inside our house from the mailbox.  The mail box puck is extremely simple (see GotMail_MB_V1.ino):

  • The PIR sensor is hooked up to a GPIO pin.
  • The first thing the loop() does is goToSleep() – i.e.: set the M0 into deep sleep mode, put the RF95 to sleep, and set the motionDetected interrupt to be called back when the GPIO pin assigned to the PIR sensor goes off.  The GPIO pin will change from LOW/HIGH when the mailbox is opened.  When this happens, the __WFI() happens, which plops the code into motionDetected().
  • The bMotionDetected is set to true.  
  • When bMotionDetected is true and now the code is running below the interrupt in the loop(), a mail message is sent to the WeGotMail home device. 
  • The message includes the battery level.

The Controller

The Controller uses the GotMail_Home_V2.ino code.

There are three Feather boards inside the Controller – a Feather M0 RFM95 LoRa, a proto FeatherWing, and a neopixel FeatherWing.  This image shows the neopixel Featherwing connected to the proto Featherwing.

NewImage

The RF95 code was easy because I was familiar with how RadioHead’s library worked after using it for my outdoor gardening project.  I LOVE evolving what I have learned.

Start Sparkling

I grabbed the sparkle() routine from John Ericksen’s Multicolored Plasma for the Arduino Micro-Controller and NeoPixel Shield sketch.  When a message is received from the Mail Box Puck with a battery reading <= 3.7, the sparkle pattern changes to flickers of red in the Fire() routine.  I grabbed this code from Tweaking4All’s work and slightly modified it.

Stop Sparkling

There is a button on the side of the enclosure that when pressed turns off the neopixels.

Button Wiring

I hooked up a  button I found lying around.  Because I easily forget the basics, I decided to document how a simple button switch works.  

Here is an image from an Adafruit tutorial that shows how a button switch should be wired:

note:

  // initialize the pushbutton pin as an input.  Use INPUT_PULLUP
  // so that when the button is open, the digitalRead will be HIGH.
  pinMode(buttonPin, INPUT_PULLUP);

These two tidbits of information made it easy for me to wire up the button.

Button Detection

The two challenges I had were:

  • realizing the best way to trigger an interrupt when the button was pushed was on the RISING or FALLING edge.  Triggering on the HIGH or LOW reading returns many (many) readings.  Yah. Obvious to you.  I get it. (BTW: I thought Jeremy Bloom’s discussion on how interrupts work on the Arduino was excellent…)
  • just getting one interrupt when the button was pressed and the interrupt was set to fire on RISING (or FALLING).  AKA debouncing. The debouncing links shows how to do this when the code does not use a hardware interrupt.  I’m glad it did because I didn’t know how to hardware debounce.  Lucky for us, Jeremy Bloom has a tutorial discussing hardware debouncing.

NewImage

I am using the NTE74HC14 Schmitt Trigger Inverter.  I chose this one because our local hardware shop had it, making it easy for me to pick up.  

NewImage

The pins I used include 7, 14, 2, and 1. Pin 1 is input from the button push and pin 2 is output that goes into a GPIO pin of the Feather M0.

NewImage

 

Firmware

The Controller’s job is to hear a message from the mail box puck.  When it does, it starts sparkling the neopixels.  There is a button on the side of the box to turn off sparkling.  When the battery level of the Mail Box Puck is <= 3.7V, the sparkling looks like red fire to symbolize the Mail Box puck’s battery needs to be recharged.

Feature requirements:

  • Sparkle when a “We’ve got mail” message is received from the mail box puck.
  • Stop sparkling when the button is pushed.
  • Have a robust and attractive enclosure.
  • Be available wherever we are within the house.  In order to do this, the Controller will use a battery.  The enclosure must make it easy to recharge the Controller through the USB port.  The Controller should use minimum battery power.
It is my hope/expectation that the GotMail_Home_V2.ino is readable enough for anyone interested to figure out what is going on.
 
 
 
 
…Thanks for reading this far.  Please find many things to smile about.  I for one, am grateful.

 

 

 

 

 

Moisture Puck – Firmware Evolved with Better Power Management

Tags

Thanks To Those That Went Before

It’s all too easy for me to overlook the efforts by amazing folks.  I find though when I stop and express gratitude, I am much happier.  More at peace.  So for purely selfish reasons, I thank:

  • Ron Sousa  of HDE for excellent 1:1’s in which he walked me through Cortex m0 power management registers and what to look for.  I is a credit to Contextual Electronics to have such amazing folks on staff.
  • Adafruit for products like the Feather line, the  INA219 Current Sensor Breakout.  For their excellent support.  For the way they seem to care about the workers.  For their videos.  I hope more companies become like Adafruit.  
  • Rick for his comments on this blog.  I find them very useful.  The most recent one being hook up a current sensor.  Thank you Rick.  I did this.  Talk about a great thing to do!

Open Source

The Arduino code for the Moisture Puck and the Controller (v3) can be found at this GitHub location.

Overview

It is unacceptable to recharge the battery after 3 days.  The Moisture Puck was burning on average about 25mA.  Given the Feather is powered by a 2000mAh LiPo, the back of the envelope calculation (2000/25/24 = 3.3 days) is “close enough” to what I observed when the Moisture Puck was in the soil sending measurements to the Controller.

The updated Moisture Puck code cuts down the power usage considerably.  For ~ 6 seconds each hour, it draws 32mA.  For the the majority of the rest, it draws 1.2mA.  There are occasional spike of ~5mA.  Averaging the spikes with the 1.2mA, it’s at about 1.45mA for the other 54 seconds of the hour.  So: 10% of the time, the Moisture Puck draws 32mA.  This is when packets are being sent/received to/from the Controller.  The other 90% of the time the Moisture Puck is sleeping, drawing about 1.45mA.  This comes to (.1*32) + (.9*1.45)  = 4.5mA.  Given this calculation, I hope to see the Moisture Puck’s battery last (2000/4.5/24 = 18.5 days….roughly 18 days.  The key to these power management improvements included:

  • Using the rtczero library.
  • Restructuring the code so that the Moisture Puck wakes up at an AM and PM watering time then sends packets.  The rest of the time the m0 and RFM69 are sleeping.
  • Only powering the moisture probe when it is being used.  Prior, the moisture probe’s V+ was wired directly to the Feather M0’s V+.  I moved the V+ wire to the Feather M0’s 12 GPIO pin and set the pin to HIGH when taking a measurement and then low once finished taking the measurement.
While this is a significant improvement, it is still higher than it need be.  I’ll save more power reduction exploration for a later time.

New Moisture Puck Firmware

  • More accurate time of day: MoisturePuck2007_v3.ino/Controller2007_v3.ino take advantage of Adafruit io’s time feed to set the time on the Moisture Puck.  This way, the Moisture Puck has an accurate time without the need of a RTC chip.
  • Less power used:

Less Powered Used

Measuring Current Draw

An essential tool for this exploration is Adafruit’s nifty INA219 Current Sensor Breakout. I modified a USB cable so that I could insert the INA219 into the power side of the circuit over USB.  

NewImage

I hooked up the INA219’s I2C to the Arduino and run the getCurrent.ino sketch (found in Examples that come with the INA219 library) on the Arduino.  I suppose I could have more easily measured current through the battery (by more easily I mean I wouldn’t need to hack up a USB cable).  However, using the USB port for building/debugging is easier.  

Numbers:

  • about 13mA when the Feather m0 was in upload mode.
  • about 32 mA when sending/receiving RFM69 packets
  • about 1.2-1.5 mA when in rtc.standby() and the moisture sensor is not drawing power.
I would think deep sleep would draw less power (around 700µA?) and the 5mA spikes are suspicious.  I assume there are peripherals (e.g.: Flash) that are still on needlessly sucking up power.  For now, I’ll let that go to allow exploration into other areas that I’d like to improve on.

Turn Off the Moisture Sensor

One thing I noticed that was like “oh – right – duh” was the moisture sensor was being powered by the 3.3V pin of the Feather m0.  It was on all the time.  As noted by Chris Ruppel in his “Arduino soil moisture sensor” blog post, only send power to the sensor when actively taking a reading of the soil moisture. Powering only during these short moments helps avoid corrosion caused by the constant flow of electricity between the two pads of the sensor.

Besides corrosion, power consumption is 2.15mA when the moisture sensor is on and 1.45 when off.  The moisture sensor sucks up 700µA!

I attached the v+ of the moisture pin to pin 12 of the Feather and now turn the pin HIGH right before measuring then back to LOW after measuring.  Much better.

MoisturePuck2007_v3.ino

This version of the firmware is – happily – simpler.

  • Controller sets the time from Adafruit.io: A core assumption with this experience is the Moisture Puck knows the correct current time as well as the AM and PM watering times.  Neither Controller nor Moisture Puck have a RTC.  The Controller grabs the current time from Adafruit.io’s time feed.  Once the Controller’s firmware is loaded, it subscribes to Adafruit.io’s time feed.  The Controller waits around until it receives the current hour, minute, and seconds from Adafruit.io.  It then sets it’s time to these values.  The Controller switches to listening for a Moisture Info packet.
  • Controller listens for a Moisture Info packet: Once the time is set, the Controller listens for moisture info packets. 
  • Moisture Puck sends Moisture Info Packet: The Moisture Puck takes moisture readings when the firmware is first loaded and then at the AM and the PM watering hours.  The Moisture Puck sends the Moisture Info packet to the Controller and then waits to receive a Time Info packet.
  • Moisture Puck goes to sleep: Using APIs in the rtczero library, the moisture puck sets a wake up alarm and then goes into a deep sleep.
  • Controller gets a Moisture Info packet:  When the Controller gets a Moisture Info packet, it publishes the values to Adafruit.io.  The Controller then sets up a Time Info packet and sends it to the Moisture Puck.  This way the Moisture Puck knows the correct time.

 

NewImage

 

That’s it for the update.  Please see the GitHub location above to get the code.  Thank you and please find many things to smile about.