This small, battery powered, On/Off Remote uses a FET power switch circuit to turn it off completely when it is not being used. Its LiPo battery will last more than 6 months before it needs to be recharged via the on-board charger. It can be programmed to match the control requirements of your remote device and can be built to connect via WiFi, Bluetooth Classic, Bluetooth Low Energy (BLE), Radio/LoRa or SMS.
Even the few mAs drawn by a Bluetooth Low Energy (BLE) board will flatten the battery in a few weeks, if the board is left powered up continually. WiFi, SMS, Bluetooth Classic and Radio/LoRa draw much more current. Having the FET power switch means you don't have to be concerned about how much power is drawn by the microprocessor when it is remotely connecting to your device as this current draw is only for a brief period of time and then the FET power switch disconnects the battery from the board.
There are two sketches included in this project. One just send an On or Off command depending on which push button is pressed. The other sketch connects to and controls my Retro-fitted Existing Light Switch with Remote Control, via WiFi. This project also discusses what is needed for other types of remote devices and other types of wireless connections (Bluetooth, BLE, Radio and SMS)
This project uses a number of SMD devices, but mounts them first on small daughter boards so that they are easy to add to the Vero board construction. The soldering of the SMD to the daughter boards is fiddly, but readily done using the tips included here.
Step 1: Why This Project?
While the Retro-fitted Existing Light Switch with Remote Control can be controlled via your Android mobile, I usually don't keep my mobile by me at night and in any case don't want to be fumbling about in the dark trying to turning it on and selecting an app just to turn the light on.
The On/Off Remote described here can stay on my bedside table continually and the On and Off buttons each have a distinctive shape so I can use it by feel, in the dark. The single red LED lights up when you press a button and goes out once the operation has been completed successfully. The LED indicator will flash rapidly if there is a connection problem. It flashes slowly when the battery needs recharging and flashes irregularly while the it is being charged.
Step 2: Parts List
Cost ~US$65 as at 20th Dec 2017, excluding shipping and a small plastic enclosure OR ~US$55 if you already have the USB cable and power supply.
Adafruit Feather HUZZAH with ESP8266 WiFi – ~US$17 https://www.adafruit.com/product/2821
Lithium Ion Battery - 3.7v 2000mAh – ~US13 https://www.adafruit.com/product/2011
Two momentary push buttons, normally open, different shapes – ~AUD$10 e.g. https://www.jaycar.com.au/ip67-rated-dome-pushbut... and https://www.jaycar.com.au/ip67-rated-dome-pushbut...
Vero board (>83mm x >55mm) – ~AUD$5 e.g. https://www.adafruit.com/product/2011
USB A to Micro B cable – ~US$4 https://www.adafruit.com/product/2011 (3 foot long) OR~US$3 https://www.adafruit.com/product/2011 (6 inches long) OR ~US$2 https://www.sparkfun.com/products/13244 (6 inches long) OR ~US$5 https://www.sparkfun.com/products/10215 (6 foot long) OR similar
Arduino IDE V1.8.5 and a computer to run it on.
For a plastic box I used one from Jaycar UB5 (blue) 83mm x 54mm x 31mm ~A$4
Step 3: The FET Power Switch Circuit
The FET power switch circuit is shown above. A pdf version is here. The pin numbers / names shown on the circuit refer to the Adafruit Feather HUZZAH with ESP8266 WiFi board pins. Pins 12,13,14,15, BAT and ADC pins are used. Wire them to the corresponding points shown on the circuit above.
The FDS4465 P-FET is normally held off via the 100K resistor connected to the LiPo battery. In this state the leakage current is <10uA (actually measured <10nA). This leakage current is far less then the self-discharge current of the LiPo battery.
When the gate of U1 (BSS138) is driven high, the gate of the P-FET is driven low and the power FET turns on and connects the battery to the BAT lead.
The gate of U1 can be driven high by four sources, two push buttons (diode OR'd) and two inputs (diode OR'd)
When Switch 1 (or Switch 2) is connected, momentarily, to the battery plus lead, SW_COMMON, then the gate of U1 is pulled high, via one of the BAT54W diodes, and the power FET is turned on, powering up the microprocessor. At the same time, the associated capacitor, C3 (or C2) is shorted out. When the push button is released it takes some time for the capacitor to charge up again, about 0.5sec. In the meantime the gate of U1 is held high by the voltage developed across R2 // R4 by the capacitor charging current. (The circuit shows C3 and C2 as ceramic 7XR capacitors which have the lowest leakage, but in the construction I used 16V Tag Tantalum capacitors which where easier to solder and still had low leakage compared to the LiPo self-discharge.)
This keeps the power FET on allowing the microprocessor time to power-up, reset and apply a HIGH to one of the POWER CONTROL inputs. A HIGH on either of these inputs will keep the gate of U1 high and keep the power FET turned ON.
As well as holding the gate of U1 high, the charging capacitor also turns on one of the output fets U$7G$1 (or U$7G$2), grounding that microprocessor input. When the microprocessor starts up it checks the level of these inputs to determine which (if any) push button was pressed.
The check of the inputs and applying HIGH to the POWER_CONTROL pin needs to be done within 0.5 sec of the power being applied to the microprocessor. That is before the capacitor has charged up enough to turn off U1, the power FET and the output fet.
There are two other small parts to this circuit. A voltage divider on the BAT line to sense the battery voltage for the microprocessor's ADC input and a LED plus resistor that the microprocessor can drive as an indication.
Off Leakage Current for the Fet Power Switch
The Off current for this circuit is via the P-Fet, FDS4465, its gate switching Fet, BSS138 (via the 100K resistor) and via the leakage in the two capacitors C3, C2. For the lowest leakage use the 7XR capacitors shown on the schematic, instead of the Tag Tantalum's used in this construction.
At 25deg C -- the leakage will increase as the temperature increases
FDS4465 data sheet shows 1uA for 20V across it. So for a 4V battery, say 0.2uA
BSS138 data sheet show 100nA for 60V across it. So for 4V, say 7nA
7XR ceramic capacitors 2000 ohms-Farads => 2000/10uF = 200M ohms => 20nA at 4V so for two capacitors 40nA
So total calculated OFF leakage is ~250nA at 25deg C, using ceramic 7XR capacitors.
Using 10uF 16V tag tantalum capacitors, data suggests 0.5uA each for a total OFF leakage ~1.2uA at 25deg C
For this construction, using the 10uF 16V tag tantalum, I put a 100K resistor in the battery return and measured ~1mV (averaging out the noise) across the 100K resistor with the FET switch OFF, i.e. ~10nA leakage
Step 4: Construction
Construction consists of soldering the surface mount components onto the DIP adaptors, wiring up the FET Power Circuit on vero board, wiring up to the Adafruit Feather board and mounting in a box.
Soldering the SMDs
There are 4 types of SMD's used in this project. An 8pin SOIC-8 power P-FET on an 8 pin DIP header and a 6pin dual BSS138 fet, a 3 pin single BSS138 fet and two common cathode 3 pin dual Schottky diodes on 6pin DIP adaptors. The 6pin dual BSS138 is not a very good fit on the 6pin adaptor but it works.
To solder the SMD component to the adaptor, apply flux (flux pen or flux paste) to all the pads and position the SMD on the adaptor. The flux helps to keep it in place. Then holding the SMD down with a tooth pick take a small blob of solder on the soldering iron tip and roughly solder one pin. Once one pin is soldered, solder all the others. Don't worry about bridging pins with solder, you will fix that up later. Then go back and properly solder the first pin with more flux and solder. Finally clean the soldering iron tip of all free solder and wipe it across the pins to wick up the excess solder and remove any solder bridges.
Constructing the FET Power Circuit
Above is the vero board layout and the connecting wires and I/O connections and leads. I used a style of vero board that just had un-connected lands on the back to hold the components in-place for wiring.
Step 5: Wiring to the Adafruit Feather Board and Mounting in Box
For this project, the communication is via WiFi and I used an Adafruit Feather HUZZAH with ESP8266 WiFi board (see below for other options). The pin labels on the FET Power circuit refer to this board loaded with the Arduino sketch below.
The Adafruit board is screwed to the side of the plastic box (after removing one of the corner pegs). The LiPo 2000mAhr battery is mounted to the lid of the box with heavy duty double sided tape (Scotch Permanent Clear Mounting tape). The vero board just sits in the box and a piece of thin cardboard under the vero board covers up the wiring with a hole in the cardboard for the led to show through.
The Adafruit board is mounted flush against one end of the plastic box and a small slot allows access for the USB cable to charge the LiPo battery via the on-board charging IC. When not in use, i.e. most of the time, this slot is covered with a small sticker to keep the box dust tight.
Step 6: On/Off Remote Programming -- Programming the Feather HUZZAH ESP8266
To program the shield follow the instructions given in Adafruit's guide (pdf) for programming with the Arduino IDE. This project was compiled using the ESP8266 version 2.3.0. Other versions will have their own set of bugs and may not work with this code.
After installing the ESP8266 board support, close and re-open the Arduino IDE and you can now select “Adafruit HUZZAH ESP8266” from the Tools → Board menu.
You also need to install the latest version of pfodESP8266WiFiBufferedClient library. This library works with ESP8266.com IDE plug-in V2.3. (If you have previously installed the pfodESP2866WiFi library, delete that library directory completely.)
a) Download this pfodESP8266WiFiBufferedClient.zip file to your computer, move it to your desktop or some other folder you can easily find
b) Then use Arduino 1.8.5 IDE menu option Sketch → Import Library → Add Library to install it. (If Arduino does not let you install it because the library already exists then find and delete the older pfodESP8266BufferedClient folder and then import this one)
c) Stop and restart the Arduino IDE and under File->Examples you should now see pfodESP8266BufferedClient.
Setting the Network ssid and password and IP and port
After you have installed the pfodESP8266BufferedClient library, open the Arduino IDE and copy the sketch, Wifi_OnOff_sample.ino or Wifi_OnOff.ino, into the IDE. The Wifi_OnOff.ino works with my my Retro-fitted Existing Light Switch with Remote Control project via the Wifi2BLE bridge.
The Wifi_OnOff_sample.ino contains two strings, TURN_LIGHT_ON and TURN_LIGHT_OFF, that you can replace with the On/Off commands needed for your device.
Before you program the module, you need to set your network's ssid and password and the IP/port of the WiFi device you want to control and modify the processMsg method to suit your device's commands
Edit these three lines near the top of Wifi_OnOff_sample.ino to set your networks ssid, password and the ip and port of the device you want to connect to.
char ssid = "**** ***";
char password = "**** *****";
char staticIP = "10.1.1.180";
int portNo = 4989;
Changing the processMsg() method to suit your device
For your own device, you need to determine the commands needed to turn your device on and off. For WiFi connections, open a Terminal program (TeraTerm (Windows) or CoolTerm (Mac)) turn on the logging and connect to you device's IP/port and record the commands to turn the device on and off. In the simplest case, your device will have one command to turn it on and another to turn it off.
The sketch, Wifi_OnOff_sample.ino, contains two strings, TURN_LIGHT_ON and TURN_LIGHT_OFF, that you can replace with the On/Off commands needed for your device.
Then program the modified sketch into your Feather HUZZAH ESP8266.
Programming the Feather HUZZAH ESP8266
To program the Feather HUZZAH ESP8266, unplug the LiPo battery and plug in the USB cable. Click on Tools → Board → Port and select the USB COM port for your board. Then program the Feather HUZZAH ESP8266. It should automatically go into program mode. (Also see ESP8266 Programming Tips (espcomm failed) ) Then open the Arduino IDE Tools → Serial Monitor
You should see the debug output that says the unit is CHARGING and the led should flash irregularly. Pressing any push button should stop the flashing.
Then, while holding a push button down, press the Adafruit board's Reset push button. The board will then try and connect to your WiFi network and then to the host and port you specified. Then it will send the command string you coded, depending on the button you pressed, and then turn off the led and FET power switch. If there are any connection or message errors then the On/Off Remote's led will flash quickly for 15sec before shutting down and the Serial Monitor will display a message indicating where the problem occurred.
Charging the Battery
Once the programming is complete you can plug in the LiPo battery and connect the USB cable to a supply to charge it. The led will flash irregularly and the yellow charge indicator on the Adafruit board will light brightly.
Since the programmed charge rate on this board is only 100mA it will take some time to charge the 2000mAhr battery (perhaps 20hrs). When the charge is complete the yellow charge light will go out. Remove the USB cable and then press any push button to turn the FET power circuit off.
Step 7: Bluetooth Classic, Bluetooth Low Energy (BLE), Radio/LoRa or SMS Options
The project above connects via WiFi to turn the remote device On/Off, however it can be readily modified to connect via other means, by replacing the Adafruit Feather HUZZAH with ESP8266 WiFi with one the following boards. The sketch will also need to be modified to work with the respective wireless connection.
- For Bluetooth Classic use Adafruit Feather 32u4 Basic Proto and SparkFun Bluetooth Modem - BlueSMiRF Silver or Gold
- For Bluetooth Low Energy (BLE) use Adafruit Feather nRF52 Bluefruit LE – nRF52832
- For Radio/LoRa use one of the Adafruit Feather Radio boards like Adafruit Feather 32u4 RFM96 LoRa Radio - 433MHz – RadioFruit
- For SMS use Adafruit Feather 32u4 FONA
This On/Off Remote uses a FET Power switch to disconnect the battery when not in use. This provides a very long battery life even for high current wireless connections like WiFi and SMS. The example design here uses WiFi but can readily modified to connect via Bluetooth, BLE, Radio/LoRa or SMS. The Feather boards used have an built-in LiPo battery charger for easy recharging. A single led indicator lets you know when the action is successfully completed or if there is a connection error or if the battery needs recharging. The dissimilar push buttons make it easy to use in the dark.