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):
- Adafruit Feather M0 WiFi
- ACS712 Current sensor
- Relay Module
- USB power supply
- 2 Resistors
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:
- Create a MySQL database, username and password
- Create a
.env
file and setMYSQL_USERNAME
,MYSQL_PASSWORD
andMYSQL_DB
. - run
npm install
- run
npm run dev
- After a controller connects edit the
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:
- run
npm install
- run
npm run serve