Control an A.C Light Bulb over the Internet Using ESP8266 WiFi Module

Control an A.C Light Bulb over the Internet Using ESP8266 WiFi Module

In this article, we’ll look at how to control the A.C bulb in your home over the internet using an ESP8266 WiFi module

You’ll need the following items

Hardware

  • ESP8266 esp-01 WiFi module, get it here
  • FTDI USB-TTL converter, get it here
  • Jumper cables, get them here
  • 5V DC/240V A.C 10A single channel relay, get it here

Software

  • Download the CH340 driver for the USB-TTL converter here
  • Download the latest Arduino IDE here

Introducing the ESP8266 WiFi Module

The ESP8266 WiFi Module is SOC with TCP/IP protocol stack that can give any micro-controller access to your WiFi network. The module is capable of connecting to any WiFi network and can be used as an access point for other devices to connect to. The module is simply hooked to your Arduino and you get the same WiFi capability as any other WiFi shield such as The Arduino WiFi shield. AT commands can be used to instruct the module as it comes pre-programmed in its firmware. The ESP8266 module is an extremely cost effective board capable of carrying out simple and complex projects and with a huge, and ever growing, community. With a flash memory of 1MB The module can be used in your IOT (Internet Of Things) solutions.

ESP8266 WiFi module
ESP8266 WiFi module
ESP8266 WiFi module pinout
ESP8266 WiFi module pinout

Note: Operating voltage is 3.3v, do not exceed 3.3v. It is recommeded to get an external power supply as the Arduino 3.3v supplies just 25mA instead of 170mA required by the module .

IMPLEMENTATION

STEP 1: INSTALL REQUIRED LIBRARIES

  • Start your Arduino IDE
  • Go to File > Preferences and add the link http://arduino.esp8266.com/stable/package_esp8266com_index.json to the Additional Boards Manager URL.
ESP8266 Arduino IDE
ESP8266 Arduino IDE

 

  • Go to Tools –> Board –> Boards manager
ESP8266 Arduino IDE
ESP8266 Arduino IDE

 

  • You should now have ESP8266 as an option there since you’ve added it to the Additional Boards. Select it and press Install

    ESP8266 Arduino IDE
    ESP8266 Arduino IDE

 

  • Wait for it…

    ESP8266 Arduino IDE
    ESP8266 Arduino IDE

 

  • Now, You have the ESP8266 boards configure. Choose the board you have, “Generic ESP8266 Module”

    ESP8266 Arduino IDE
    ESP8266 Arduino IDE

 

  • Choose the ESP8266 port and you’re done!

    ESP8266 Arduino IDE
    ESP8266 Arduino IDE

STEP 2: ESP8266 TO FTDI CIRCUIT CONNECTION

ESP8266 TO FTDI AND RELAY CIRCUIT
ESP8266 TO FTDI AND RELAY CIRCUIT
  • Restart your Arduino IDE
  • Now go to the File > Examples  > ESP8266WiFi menu and load the “WiFiWebServer” sketch into an editor window.
  • Replace the placeholders values in the script for “ssid” and “password” with the SSID and password for your WiFi network.
  • Then hit the upload button

RESULTS

  • If all goes well, you should see “Uploading..” and after a while “Done uploading…”
  • Now go ahead and open the Serial Monitor, remove the jumper between the GPIO_0 pin and GNDHowever if all is still going well you should see something like this,
    Connecting to Wireless Network
    .......
    WiFi connected
    Server started
    192.168.1.224

which tells you that the board has connected to the network, and rather crucially, what the board’s IP address ended up as when it negotiated its connection to the DHCP server.

Now you can just go to your browser and use the endpoint http://192.168.224/gpio/1 to pull GPIO_2 high, and turn the BULB on, or http://192.168.224/gpio/0 to pull GPIO_2 low, and turn the BULB off. If you’re still connected to the Serial Console you should see something like this scroll by if you attempt to turn the LED on,

new client
GET /gpio/1 HTTP/1.1
Client disconnected
new client
GET /favicon.ico HTTP/1.1
invalid request

Here you can safely ignore the invalid request error message — that’s just your browser asking for the icon that accompanies the web pages its retrieving, it doesn’t necessarily expect a response.

Congratulations, you’ve learnt how to control the bulb in your home over the internet.

Wanna do more?

Build a movement detector and monitor the status from your web browser using the PIR motion sensor, get it here

Feel free to leave any comment. Thank you.

 

 

Leave a Reply

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