ESP8266 Relay Smart Socket with iOS App Remote Control

es8266-thumbESP8266 is a family of inexpensive full TCP/IP stack Wi-Fi chips and microcontrollers that can be programmed using Arduino IDE. It can work as a standalone microcontroller or interfaced with an Arduino microcontroller via AT commands. I decided to try it out by itself on a simple relay project with an ESP-01 module. The program is a simple web server that can be used by a client to turn a power socket on and off using a 5V relay module.

Parts

1 x ESP8266 (ESP-01) Serial WIFI Wireless Transceiver Module
1 x 220V AC to 5V DC (700mA) Converter
1 x AMS1117 5V to 3.3V (800mA) Converter
1 x 2N2222A TO-92 NPN Transistor
1 x 5V 1 Channel Relay Module
1 x FT232RL 3.3V 5V FTDI USB to TTL Serial Adapter + USB cable
2 x 470uF Capacitors
1 x 100uF Capacitor
1 x 10nF Capacitor
1 x 10k Resistor
1 x 47k Resistor

To program the ESP module it is very important to use a 3.3V adapter, if you have a 5V adapter you need to use logic level shifting. The one I used has a convenient jumper to switch between 3.3V and 5V operation. I used the 220V AC to 5V DC converter for relay operation and AMS1117 to convert 5V to 3.3V for ESP-01 operation. The 2N2222A NPN transistor is used to ground the input pin of the relay to turn it on or off. The GPIO 2 pin of ESP-01 is connected to the transistor base via a 47k resistor. The CH_PD and RST pins of the ESP-01 are connected to VCC via 10k resistor.

ESP modules use a lot of power so you need to make sure you have a proper power supply. Peeks are also an issue and it can be difficult to make the circuit stable. Relay, wiring and connections emit a lot of noise into the system and ESP-01 is very prone to resets. To make the system more stable I used the 2 x 470uF capacitors (on 5V and 3.3V rails not visible in the image below because they are located below the board) and 100uF and 10nF between the VCC and GND pins very close to the ESP module. I actually soldered the 100uF capacitor on top of the ESP pins and the 10nF is also not visible in the image because it is below the board.

iOS Remote Control App

 

Relay operation

iOS Remote Control App on GitHub: https://github.com/lukagabric/ESP8266Light_iOS

ESP-01 Arduino Sketch on GitHub: https://github.com/lukagabric/ESP8266Light_Arduino

  • esp8266_relay_app
  • esp8266_sim2
  • esp8266_sim1
  • IMG_2934
  • IMG_2933
  • IMG_2932

 

References for wiring and Arduino tutorial:

http://www.esp8266.com/wiki/doku.php?id=getting-started-with-the-esp8266

If you liked this blog post I’d appreciate if you followed me on Twitter

Related Post

Remember to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInEmail this to someone

4 thoughts on “ESP8266 Relay Smart Socket with iOS App Remote Control

  1. Hi Luka, thanks for sharing this. I’m planning to build one myself. One question though is why bother with 5V. I was thinking if I use a 220V to 3.3 step down converter (like an HLK-PM03) which outputs 3.3V I could omit the AMS1117, correct? On depending whether the 5V relay would still switch at 3V.

    Cheers, Paul

      1. Dear Luka.
        I have uploaded your light code without any error, in the app you are entering 192.168.0.12:8081 but my esp8266 default ip is 192.168.4.1. the port you have enterer in the code is 8081 I tried both in my app it is not connecting.
        I have entered const char *ssid = “iphone”;
        const char *password = “12345678”;
        when I check in wireless ican see iphone & also able to connect to esrp8266 with the password but it says no internet connection.
        Please help I don’t no where iam going wrong.

  2. Dear Luka.
    Please can you tell me where is the software for iOS Remote Control App(light)for Arduino ide to be uploaded to ESP8266.i have your app on my iPhone.

Leave a Reply

Your email address will not be published. Required fields are marked *