How to Build a Control Circuit with Adjustable Working Time via Wi-Fi
June 15, 2016 by Yahya Tawil
In this article, you'll learn how to build a system that can turn DC loads on and off using a mobile application. You'll also learn how to perform this task via immediate actions or via timers set in advance for switching loads on and off.
You can implement this system in environments where you need to set your DC load for a specific time. This will allow you to use our Android application without any need for a hardware interface, keypad, and LCD screen.
Overview of the whole Project
Overview of the whole project.
Arduino UNO or any compatible board 1
ESP8266 Wi-Fi module 1
USB TTL converter cable (optional) 1
Relay SPDT 12V 2
BC337 NPN BJT 2
BS170 MOSFET N Channel 1
1K Ohm resistor 2
10K Ohm resistor 2
1N4007 diode 2
Screw terminals 2
LM317 adjustable voltage regulator 1
0.1uF capacitor 2
Headers, female and male –
Blank PCB board 2
Setting Up Your ESP8266 Breakout Board
The ESP8266 is a low-cost SoC chip with an embedded microcontroller and full TCP/IP protocol stack, which means that it can directly access your Wi-Fi network.
Because this chip has its own MCU, you can put your application code within it or you can use the module just as a Wi-Fi transceiver— like what we are going to do in this project. It will be more efficient to use the same module as a transceiver and a controller, but just for learning purposes, we will communicate with the module using Arduino instead.
The ESP8266 chip comes in different modules. We will use the ESP-01 module. Of course, you can use any other module.
First, you must know that the module works on 3.3V, and the logic-high voltage from the Arduino should be the same to prevent causing damage to our module. This requires a voltage level converter between the Arduino (which works on 5V) and the module. The good news is that only the transfer pin of the Arduino will need this converter since the receive pin will usually recognize the 3.3V logic signals from the ESP8266
One of the simplest ways to do this conversion is to use a design from Sparkfun: You can order a ready-made module.
5V to 3.3V Level Converter
5V to 3.3V level converter
The following figure shows our ESP8266 pinout:
Image source: ESP8266 WiFi Module Quick Start Guide
UTXD UART Transmit Data
URXD UART Receive Data: Input should be 3.3V compatible
CH_PD Power-down: Low input powers the chip down, high input powers it up; tie high for normal operation or the module will not function.
GPIO0 At boot: Must be high to enter flash or normal boot; low enters special boot modes.
GPIO2 At boot: Low causes bootloader to enter flash upload mode; high causes normal boot.
RST Reset; active low
I used an LM317, an adjustable output voltage linear regulator with up to 1.5A output current, for providing a suitable 3.3V power supply for the module.
Note: Don’t use the 3.3V pin from the Arduino while the 3.3V voltage regulator used in Arduino can’t source the requested current for the module, especially for peak power consumption while transmitting.
ESP8266 BreakOut Board Diagram
ESP8266 breakout board diagram
I used the BS170 (instead of the BSS138) for the logic-level converter; both work fine.
ESP8266 BreakOut Board
ESP8266 breakout board
Now you can connect your module with your USB-TTL converter cable and try the module. For further details, I recommend reading some starters guides like ESP8266 WiFi Module Quick Start Guide.
USB TTL converter cable
USB-TTL converter cable
Setting Up Relay Breakout Board
Relay BreakOut Board Diagram
Relay breakout board diagram
I used a BC337 NPN BJT to control the coil of relay with a 1K Ohm base resistor. I also used the 1n4007 diode as protection from reverse voltage of the coil.
I chose to make the normally closed (NC) connection with ground. While off is the normal state for me, you can reverse the connection if you like.
For More Details: How to Build a Control Circuit with Adjustable Working Time via Wi-Fi