In this project, you'll clamp the current transformer (CT) around one of the hot or neutral wires in the extension cord. You'll then connect this extension cord to the HVAC unit in order to measure the current it consumes. The CT outputs an AC signal whose RMS voltage is proportional to the amount of current going through the wire (specifically, 1 V corresponds to 30 A). You will create a simple bias circuit so that this voltage is always positive, and you'll feed the signal into the Swan for analog to digital conversion. The firmware on the Swan samples the signal and computes the current. These measurements are periodically coalesced into Notes that get sent to the Notecard, where they'll eventually be synced to Notehub.
The CT's output signal is delivered via a TRRS connector. You'll plug this connector into the TRRS breakout, but first, you must solder on the row of headers that come with the breakout. Once you're done soldering, plug the breakout into the breadboard and connect the CT:
The output of the current transformer is an AC signal whose voltage swings between negative and positive values. The ADC on the Swan requires a positive voltage, so you'll need to bias the signal such that it doesn't swing negative. To accomplish this, you'll build a simple bias circuit, which is described in detail here. Note that the "burden resistor" mentioned in that document comes pre-installed in the CT linked above; you do not need to add an external burden resistor. Additionally, the document uses an Arduino, which operates at 5 V, but the Swan operates at 3.3 V. This doesn't affect the design of the circuit, but you should mentally substitute 3.3 V wherever you see 5 V.
Using a jumper wire, the resistors, and the capacitor, build the circuit shown below:
The firmware periodically reads the voltage from the CT and computes the current implied by that voltage, after accounting for the DC bias. Once 10 measurements have been taken, they're put into a Note in the Notefilemeasurements.qo. You can change the number of measurements per Note by using the macro MEASUREMENTS_PER_NOTE. The time between measurements defaults to 15 seconds, but this can be changed using the environment variableseconds_between_measurements. For example, if you set seconds_between_measurements to 60, a measurement will be taken every minute.
Data from Notehub to the Notecard is synced every 5 minutes, and data from the Notecard to Notehub is synced every 10 minutes. You can change these values with the macros INBOUND_MINS and OUTBOUND_MINS, respectively. These values are passed directly to the hub.set command that gets issued when the Swan starts up.
The environment variable percentage_change_threshold can be set to trigger an immediate sync of measurements.qo Notes from the Notecard to Notehub under certain conditions. Specifically, the firmware keeps track of the average value from the last measurements.qo Note. If the percentage change (positive or negative) from that average to the next Note's average exceeds percentage_change_threshold, the Note gets synced immediately to Notehub, ignoring OUTBOUND_MINS. By default, the threshold is set to 50%. When setting this variable, the value must be a positive number (e.g. 60, 200, etc.).
Click the PlatformIO icon on the left side of VS Code, then click Pick a folder, and select the the firmware directory, 49-hvac-current-monitor/firmware.
In the file explorer, open hvac_current_monitor/hvac_current_monitor.ino and uncomment this line: // #define PRODUCT_UID "com.my-company.my-name:my-project". Replace com.my-company.my-name:my-project with the ProductUID of the Notehub project you created in Notehub Setup.
Click the PlatformIO icon again, and under the Project Tasks menu, click Build to build the firmware image.
Prepare the Swan to receive the firmware image via DFU by following these instructions from the Swan Quickstart.
Under the Project Tasks menu, click Upload to upload the firmware image to the MCU.
From here, you can view logs from the firmware over serial with a terminal emulator (e.g. minicom). On Linux, the serial device will be something like /dev/ttyACM0. Use a baud rate of 115200 and 8-N-1 for the serial parameters.
With all the circuitry in place, plug your HVAC unit into the extension cord and connect the extension cord to an outlet. Turn on the HVAC unit. You should begin to see Notes come into Notehub on your project's Events tab.
If you double-click on one of these events and navigate to the Body tab, you can see the contents of the Note in detail. Take a look at this example:
The length parameter indicates how many valid measurements are in the measurements array. This is necessary because the array may contain trailing 0 values that aren't actually valid measurements. This can happen if an environment variable is modified before a full batch of measurements is assembled. The measurements array's unit is amps. seconds_between_measurements is a snapshot of what the seconds_between_measurements environment variable was when these measurements were taken, so you know the time spacing between each measurement.