HackerBox 0120: Current Affairs
by HackerBoxes in Circuits > Electronics
966 Views, 3 Favorites, 0 Comments
HackerBox 0120: Current Affairs
Welcome to HackerBox 0120. Explore electrical current measurement and power monitoring. Start with the basics of current flow, voltage, and root mean square (RMS) representations. Assemble the Current Affairs Power Monitor device based on the Wi-Fi enabled ESP8266 microcontroller. Configure the Arduino IDE to program the Power Monitor. Leverage SCT-013 current transformers and ADS1115 analog-to-digital convertors to measure current flow into an electrical load. Experiment with the ESP32-based SONOFF Mini R4 Extreme smart switch. Configure a DIY smart switch based on the ESP-01S Wi-Fi Relay Module. Consider integration of monitoring and control devices with home automation solutions such as ESPHome, Home Assistant, and Tasmota. Take a glimpse into the development of UNIX and the C Programming Language at Bell Labs and the amazing technical contributions made by Ken Thompson, Dennis Ritchie, and Brian Kernighan.
There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we'd really appreciate it if you can take a few minutes to read the FAQ.
Supplies
This Instructable contains information for getting started with HackerBox 0120. The full box contents are listed on the product page for HackerBox 0120 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month, you can subscribe at HackerBoxes.com and join the party. Subscription members save at least $15 every month and automatically receive each new HackerBox shipped immediately off the production line.
A soldering iron, solder, and basic assembly tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Workshops for tools and supplies along with a wide array of introductory activities and experiments.
The most import thing you will need is a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.
WEAR SAFETY GLASSES WHEN SOLDERING, WHEN TRIMMING WIRE LEADS, OR WHEN CUTTING, DRILLING, ETC.
Go With the Flow
"No man ever steps in the same river twice, for it's not the same river and he's not the same man." -Heraclitus
Water current flowing through a pipe or a river is measured by how much water moves past in a unit of time. For example, gallons-per-hour, or liters-per-second.
Similarly, electric current flowing through a conductor is measured by how many electrons flow past in a unit of time. For example, electrons-per-second. Since electrons are tiny, they are usually counted in the unit coulombs. One coulomb is approximately 6,242,000,000,000,000,000 electrons (a boatload). The standard unit for electric current is the Ampere (Amp or A). The flow of one coulomb per second is called 1 Amp of current.
Continuing with the very apt water analogy, potential (V in Volts) is like water pressure, which can be from a pump or an elevation (such as a hill or water tower). Resistance (R in Ohms) is like a constriction or narrow section of pipe. And of course, the electrical current (I in Amps) is like water current (volume per time). These three quantities are related to one another by Ohm's Law: V = I x R.
Root Mean Square
To measure Alternating Current (AC), we will need to concern ourselves with the notion of Root Mean Square (RMS) values. If you're interested, please do review the mathematical details, but all that is not entirely necessary. Our microcontroller-based measurements will be discrete (not continuous) so we can stick with the most useful basics...
A sinusoidal wave can be viewed on an oscilloscope, but if we just want to know it's "value" (for example, the 120V of an American electrical receptacle) we are looking for a single number, not a complicated picture. To represent a value for something that changes over time, it's generally useful to know the average (mean) value. For example, we might mention the average temperature in Milwaukee during August, the average value of AMD stock last week, or the average voltage in the wall electrical receptacle.
Great, so what is the average voltage in the electrical receptacle? Well... The average is ZERO because as much of the wave is positive as it is negative. If we sampled the voltage many times and averaged those values, we'd end up with a number close to zero. So does zero imply nothing? Of course not. Instead of "normal average" (mean) values, we will use RMS values.
First, the sampled values are squared, which makes them all positive, then the mean of those values is calculated, and then a square root is taken to "undo" the initial squaring.
RMS values are most useful because the RMS of an alternating electric current (AC) equals the value of constant direct current (DC) that would dissipate the same power into a resistor (or any resistive load).
Split Core Current Transformer
A current transformer (CT) typically consists of a ring-shaped core, as shown in the drawing above. A conductor carrying the primary current is passed through the ring forming the single-turn primary for the current transformer. The secondary winding of the transformer is formed by many turns of wire wrapped onto the core. Current passing through the single-turn primary is coupled onto the secondary coil by an induced magnetic field B. The current induced in the secondary may be sensed by external circuitry to determine the current flowing through the primary.
The image above shows the SCT-013 Current Transformer (datasheet), available in 5A, 10A, 15A, 20A, and 100A versions. We will be working with the 10A version which maps a 10A max input to a 1V max output.
SAFETY FIRST
The easiest and safest way to use a Current Transformer (CT) is in conjunction with a simple extension cord as shown in the photo above. Carefully pull apart the two conductors of the extension cord taking GREAT CAUTION to not cut or nick the insulation. Open the split core transformer and snap it around EITHER ONE of the two conductors (only one, not both).
Now, an electrical device can be plugged into the extension cord to measure how much current it draws without ever having to expose any high voltage conductors.
Electrical devices that generate heat are useful options for demonstration since they draw significant current. A clothing iron or hot water kettle are good examples. Plus it never hurts to enjoy a cup of tea.
VIDEO
Andreas Spiess' video on Measuring Mains Voltage, Current, and Power features some great technical information. However, it plays fast and loose with some safety considerations that should be taken cautiously and with a grain of salt if you aren't already extremely comfortable working with line voltages.
ESP8266 D1 Mini
We'll be working with the ESP8266 D1 Mini Microcontroller (MCU) Module to measure the output of the current transformers. The ESP8266 D1 Mini features built-in 2.4GHz Wi-Fi support, an antenna, a USB-C port, and an onboard USB interface chip.
BEFORE SOLDERING the module, let's make sure we can program it and test some things out...
Configure the development tools:
- Download an install the Arduino IDE Software
- Start the IDE
- Open File > Preferences from the menu bar
- Add https://arduino.esp8266.com/stable/package_esp8266com_index.json into the box labeled Additional Board Manager URLs. The box can have multiple URLs, just separate them with commas.
- Open Tools > Board > Boards Manager
- Find and select esp8266
- Click the install button
- Don’t forget to select your ESP8266 board from Tools > Board menu after installation.
- Select Tools > Board > ESP8266 Boards > LOLIN(WEMOS) D1 mini (clone)
Compile and upload a first program:
- Open File > Examples > Basics > Blink
- Connect the MCU module to the computer using a USB-C cable
- Hit the arrow icon to compile and upload the Blink sketch
- The blue LED on the MCU module (next to antenna) should blink slowly
- Experiment with the delay values in the sketch to demonstrate different LED timing patterns
Assemble the Current Affairs Power Monitor
Gather these four items:
- Current Affairs Power Monitor PCB
- ESP8266 D1 Mini Module
- ADS1115 Analog-to-Digital Converter Module
- Two PJ-320A 3.5mm Sockets
Assemble them together as shown in the image above. Note the orientation of the two modules. Also note that there are four separate input circuit banks and that the ADS and two 3.5mm jacks are populated into the top bank (labeled J1 and J2). Each of the four input circuit banks has a set of address selection jumpers on the rear of the PCB. While using only one ADS module, the address selection jumpers can be ignored.
ADS1115 ANALOG-DIGITAL-CONVERTOR (ADC) MODULE
The ADS1115 (datasheet) has an I2C interface and features four single-ended input channels, which can also be configured as two differential input channels. Since our input signals are +/- 1V, we'll be using the input channels in differential mode to capture both the positive and negative portions of the input signal.
The ADS1115 incorporates a programmable gain amplifier (PGA). When the PGA is set to 4X gain, the 16 bit sampling resolution represents 0.03125mV per bit.
FIRMWARE
Grab the attached HB0120_SerialOut.ino sketch file.
Open the sketch in the Arduino IDE.
Use the IDE's Library Manager to search for, and install, the library: Adafruit ADS1X15.
Compile and upload the sketch to the Power Monitor target.
Open the Serial Monitor to see an indication that the ADS module at address 0x48 was initialized.
The Serial Monitor will then display a series of measurements from CT sensors attached at J1 and J2.
ADDITIONAL SENSOR CHANNELS
We are experimenting here with two CT sensor channels. However, the Current Affairs Power Monitor can support up to eight channels.
To add one, two, or three additional input circuit banks, each will require and ADS1115 Analog-to-Digital Converter Module and two PJ-320A 3.5mm jacks. Also, the respective address selection jumpers must be set as discussed below.
Additional SCT-013 Current Transformers need also be obtained. Higher current versions of the CTs may be desired depending upon the circuits being monitored. These will require updating the corresponding scaling values within the current sensing function of the firmware.
ADDRESS SELECTION JUMPERS
The top input circuit bank (labeled J1 and J2) does not require an address jumper to be closed. For the ADS1115 chip, I2C address 0x48 is selected by connecting ADDR to GND. Leaving all of the jumpers open accomplishes this as well since ADDR has a pull down resistor on the ADS1115 module.
The second input circuit bank (labeled J3 and J4) requires the 3V3 jumper to be closed selecting I2C address 0x49.
The third input circuit bank (labeled J5 and J6) requires the SDA jumper to be closed selecting I2C address 0x4A.
The fourth input circuit bank (labeled J7 and J8) requires the SCL jumper to be closed selecting I2C address 0x4B.
Downloads
Whole Home Power Monitoring
CT sensors can be integrated with various common home automation platforms. When the CT sensors are placed onto the main split-phase supply lines or onto specific feeder outputs within a breaker panel, whole home power monitoring may be achieved. As mentioned repeatedly in the example videos below, a licensed electrician should be consulted to open up and add CT sensors into an electrical breaker panel...
DIY Whole Home Power Monitoring with ESPHome & Home Assistant
Build your own CT Clamp Power and Energy Monitor with ESPHome
SONOFF Mini R4 Extreme
Smart switch devices may be connected to electrical mains power. As already discussed, mains power can be deadly dangerous. You should understand the implications of connecting devices to mains power. Do not ever work on a device while it is connected to the mains power source. Do not attempt to adjust, modify, or program a device while it is connected to a mains power source. If you lack the experience or comfort to safely work with mains power, please have someone with the proper expertise join in to help you out.
For a general overview of smart switch technology, check out the Box Guide from HackerBox 0054: Smart Home
The SONOFF Mini R4 Extreme is super tiny to fit easily into various mounting boxes, making installation quick and hassle-free. It features a powerful ESP32 chip, delivering faster response times, more stable connectivity, and enhanced processing power. Designed for reliable and long-lasting performance, it ensures seamless smart home automation and smooth device control. Flexible external switch compatibility supports multiple switch types such as momentary switches, door exit switches, SPDT switches, latching switches, and even dry contact sensors for versatile control options. The Mini R4 acts as a smart switch and gateway for “eWeLink-Remote”and can enable local/remote control via eWeLink-Remote signals, enhancing any smart home network.
VIDEOS
SONOFF MiniR4 Extreme - Smallest Smart Relay
SONOFF MINI Extreme Wi-Fi Smart Switch Wiring & Pairing Tutorial
ESP-01S Wi-Fi Relay Module
The ESP8266 ESP-01S Wi-Fi Relay Module uses the GPIO0 pin of the ESP-01S to control a relay. The relay control provides a simple DIY "smart switch" that can be controlled from a computer, smart phone, or home automation system.
This video shows how to program the ESP8266 on the ESP-01S using the Arduino IDE. It demonstrates using a dedicated USB programmer board that the ESP-01 module can be plugged on to. This works identically to using a regular USB serial adapter (such as the CH340G) wired up as shown in the diagram.
This video demonstrates use of the ESP-01S Relay Module to wirelessly control the relay as a smart switch.
This project demonstrates use of the ESP-01S Relay Module to convert any traditional wired doorbell into a smart doorbell. It does not require working with any high voltage circuits since traditional doorbells generally operate with a transformer that provides a low-voltage DC power supply.
Bell Labs, Thompson, Kernighan, and Ritchie
VIDEO: Pushing the Limits of Technology
In the 1960s at Bell Labs, Ken Thompson and Dennis Ritchie worked on the Multics operating system. While writing Multics, Thompson created a video game called Space Travel. Later, Bell Labs withdrew from the Multics project. In order to go on playing the game, Thompson found an old PDP-7 machine and rewrote Space Travel on it. Eventually, the tools developed by Thompson became the Unix operating system. Working on a PDP-7, a team of Bell Labs researchers led by Thompson and Ritchie developed a hierarchical file system, the concepts of computer processes and device files, a command-line interpreter, pipes for easy inter-process communication, and some small utility programs. In 1970, Brian Kernighan suggested the name "Unix", in a pun on the name "Multics". After initial work on Unix, Thompson decided that Unix needed a system programming language and created B, a precursor to Ritchie's C. Throughout the 1970s, Thompson and Ritchie collaborated on the Unix operating system. They were so prolific on that it has been explained, "The names of Ritchie and Thompson may safely be assumed to attach to almost everything not otherwise attributed." (Wikipedia)
HACKADAY: Unix Tell All Book From Kernighan Hits The Shelves
Hack All the Things
We hope you are enjoying this month's HackerBox adventures into electronics, computer technology, and hacker culture. We aim to curate a challenging and rewarding experience of learning through experimentation and exploration. Thank you for joining us on this journey.
Reach out and share your success in the comments below. Email support@hackerboxes.com anytime with questions or whenever you need some help.
Hungry for more? Surf over to HackerBoxes.com and join us as a monthly HackerBox subscription member. You'll get a cool box of hackable gear delivered right to your mailbox every month and you'll enjoy a generous member discount.
Please consider sharing this free Instructable with others who may be interested in learning about these subjects. Word of mouth advertising is the greatest compliment that we can receive. We sincerely appreciate your support.