This repository contains the source code for a WiFi power controller.
The hardware consists of (most components can be easily substituted and some are excessive for lower current applications):
A pattress box makes a good enclosure.
Be cautious if ordering an ACS712 from Banggood.com, my 20A sensors were delivered with terminals rated for only 10A.
R1 and R2 should be chosen to reduce the 5V output of the ACS712 to the 3.3V range readable by the Analog inputs of the M0 (e.g. R1 should be approximately twice the value of R2).
Written using Arduino using the Wifi101 and ArduinoJson libraries. The Wifi SSID and password should be added to secrets.h. serverAddress
and port
should be updated to the address of the server.
Collects readings from the controllers and stores them in a MySQL database. Also provides a REST API for the client.
To start:
.env
file and set MYSQL_USERNAME
, MYSQL_PASSWORD
and MYSQL_DB
.npm install
npm run dev
controllers
to set the conversion factor. The conversion factor is multiplied with the value read by the controller to give a reading in milliamps. Restart the server after setting altering the database to make the server read the changes.For example if using the 20A ACS712 1A of current results in 100mV of output.
If R1 is 10kΩ and R2 is 20kΩ this translates to 67mV (20/(20+10)*100
) output from the voltage divider.
The input to the M0 is 12-bit so ranges from 0 - 4095 for 0 - 3.3v.
The conversion factor can therefore be calculated as:
c = 3.3 / S * (R1 + R2) / R2 / 4096 * 1000
where S
is the sensitivity of the ACS712 in Volts per Amp.
In this example:
c = 3.3 / 0.1 * (10 + 20) / 20 / 4096 * 1000
c = 12.85
Uses the server's REST API to set schedules and show power usage.
To start:
npm install
npm run serve