Pi Weather Station – Energy Sensor Node

The Energy Sensor Node allows near real time measurement of electrical power consumption.

The hardware and sensor reading code is based on the guide from OpenEnergyMonitor on How to build and Arduino energy monitor – measuring mains current only. They have some excellent information about CT (current transformer) sensors and also sell them in the UK.


As my Pi Weather Station communicates on a Wi-Fi network I  decided to make use of the relatively cheap Adafruit HUZZAH ESP8266 breakout which costs around £10 – much cheaper than an Arduino or Raspberry Pi – for the Energy Sensor Node.  The only downfall of the ESP8266 is that it only has a single ADC channel which can only measure a maximum of 1V.  To overcome this limitation, I opted to use a MCP3008 10-bit 8-channel ADC which communicates to the ESP8266 over SPI and allows me to use the full 3.3v of the system.

The CT Sensor I am using is a YHDC SCT-013-000 100A Non-invasive clip-on CT sensor.  This allows for the measurement of currents up to 100A without needing to alter the wiring in any way.  The sensor “clamps” around the cable and sits just below the electricity meter.

The CT sensor is effectively a transformer that steps down the current to a safe range that can easily be measured using low voltage electronics.  Currents of 100A and micro-controllers do not mix!  The ratio of the sensor I am using is 1:2000 so in this case the maximum output current is 50mA.

To measure the current in the CT sensor the node simply measures the voltage drop across a known resistance, the burden resistance, and converts this to the current power consumption.

To determine the value of the burden resistor I used the information from OpenEngeryMonitor’s page on how to interface CT sensors with an Arduino. I won’t go through all the theory etc. here as it covered extremely well by OpenEnergyMonitor, however, I will show my working on how I chose my burden resistor of 22Ω.

The maximum current I need to sense is 100A as this is the maximum that my sensor can read and the average household supply in the UK is no more than this.  The ADC I am using is running at 3.3v with it’s analog reference voltage (AREF) also set at 3.3v.  The CT sensor has 2000 turns on the secondary coil (the primary being the mains supply cable).

\text{AREF} = 3.3v
\text{Max Primary RMS Current} = 100A
\text{CT Coil Turns} = 2000
\text{Ideal Burden Resistor } \left(\Omega\right) = \frac{\text{AREF} \times \text{CT Coil Turns}}{2\sqrt{\left(2\right)} \times \text{Primary peak current}}
\text{Ideal Burden Resistor } = \frac{3.3V \times 2000}{2\sqrt{\left(2\right)} \times 100A} = 22\Omega

As the current generated in the coil is AC, the burden resistor is set with a positive DC bias to there is always a positive voltage applied to the ADC input. For these I have gone with the recommended pair of 10kΩ resistors and the 10μF capacitor.

All the hardware is connected to an Adafruit Perma-Proto Half-sized Breadboard PCB – these are great little boards for prototyping on and are much easier to solder than normal strip-board or perf-board! This is a photo of the electronics which is now awaiting a custom 3D printed enclosure.

Energy Sensor Node

The completed electronics for the energy sensor node for the PiWeather Station


One of the great things about the ESP8266 Wi-Fi modules is that you can program them using the Arduino IDE and most Arduino IDE’s.  They also have more flash memory and RAM than an Arduino Uno.  I am using the latest staging version of the Arduino core for ESP8266, version 2.0.0-rc1. The GitHub page for the code details installation instructions.

The software for the Energy Sensor Node is based around the Arduino Energy Monitoring Library by OpenEnergyMonitor.  I could not use the code without modification as I am using an external ADC to measure the current, so I wrote my own function based heavily on the EmonLib code.  This code snippet shows the code required to get the current power consumption in Watts:

The code to handle the Wi-Fi is based on the mDNS example provided with the ESP8266 Arduino Core.  The following snippet shows the WiFi handling code.

The full code for the energy monitor will be posted to GitHub along with the software for the other systems  once completed.  I will also add more comments to the code to document what is doing what.

Comments are closed.