Introduction: Wifi Switch Board or Smart Plug With Esp8266, Attiny 85 & PIR Sensor With Android App

The Wifi Arduino 85 is a small board with ESP8266 -01 module, Attiny85 micro controller and a relay. It Also has and additional header for connecting an external relay or to connect sensors like PIR, IR etc depending on your application. If you are a tinkerer you will also be able to connect a HC-05/06 Bluetooth module and convert this board to a Bluetooth Arduino 85 board.

I am going to make a Swith board using the following ingredients

1.Wifi Arduino 85 Board (comes with ESP8266 -01 module)

2.Mobile Charger (5V 1A DC )

3.PIR Sensor

4.Plastic Gang Box(4"X7")

5.Varistor (270V AC)

6.Three Pin Socket

7.Three Pin Plug


9.Double sided tape

Apart from this you will need a blade to cut the plastic box and a screwdriver

Lets start building it ...

Step 1: Firmware Update of Esp8266-01

First of all arrange your esp and FTDI (USB-UART) and connect them as shown figure (note: external 3V3 is better for your esp8266 instead of using the 3V3 from FTDI chip )
The esp8266 firmware flasher and binary can be downloaded here or from this instruct able.

You can use this firmware v0.9.5 AT Firmware.bin .Use a low numbered COM port 6 or less, you can change this in the device manager if needed .You will find in windows handling comports above COM10 is slightly different so a lot of software will trouble you.

Power on the esp8266 and run the flash tool, load the binary file .You change the COM port to match your USB-UART number, leave the second number (offset) at 0x0000 )
Hit download, should see this, I've always gotten this last warning "Leaving...Failed to leave Flash mode"

connecting ....

Erasing flash...

Writing at 0x00000000... (0 %)

Writing at 0x00000400... (0 %)

Writing at 0x00000800... (0 %)

Writing at 0x0007e800... (99 %)

Writing at 0x0007ec00... (99 %)

Leaving... Failed to leave Flash mode

If you are using the module provided with Wifi Arduino 85 Board this step is not required

Step 2: ESP8266 -01 AT Command Using Putty or Real Term

This step not required for the module provided with Wifi Arduino 85 unless you need to connect it to your home router manually

After flashing the ESP8266 settings will likely reset to 9600n81,Turn the module off , remove GPIO 0 from GND make it floating or HIGH , and restart the module .
Open a serial terminal tool like putty or real term as shown in figure.

First set the Baud rate in the serial terminal to 9600 then the port number of the USB-UART module which you can get from device manager in windows then press Change and after that press Open. You can see figure for details.

After that come to Send tab as shown in figure type the at command

AT+GMR and press Send.

Please note +CR, +LF should be selected if everything is fine you should get the firmware version details on the black window .

You can try other commands like AT which will give you OK as response.

You can change the baud rate by using the


xxxx has to be 4800 for Wifi Arduino 85 Board

You can also set your Router SSID and Password by using the following command


For more details on AT commands refer the AT command data sheet of ESP8266

Step 3: Setting Up Wifi Arduino 85 Board

One of the figures shows the in system programming pins of Wifi Arduino 85 and you can use it to program the Attiny 85 IC by removing the jumpers .In the same figure is the Arduino programming pin and is described in detail in the figure next to it .For more details on Arduino programming you can refer this instructable

Once you plug the module on to its header it will look as shown in figure.Once that is done you can power it up using a 12-7 V DC power supply or a 5V -5.3V DC Max .The figure shows the point where one needs to connect the power supply .Please do not apply voltage above recommended voltage specially on the 5V input side as on one of the jumper setting shown in figure will be directly connected to the microcontroller.

If you have coded the Attiny 85 with one of our code once you power the board the green led on the Wifi Arduino 85 should turn ON and the Red colour Led on the ESP8266 module also should turn on .There is also a blue colour led on the ESP8266 module which will start blinking, these indications mean every thing is up and good to go. After some time the blue colour led will stop blinking this means that the board has initialized .After that go to Wifi connection on your Android phone, select AI-THINKER_986B1A( Refer Figure) .After it connects( Please remember to turn off your G,2G,3G internet connection) go to Wifi Arduino app( Refer Figure) on your android mobile open it and then type in the IP text box and 333 in the port text box and then press connect .

Once you do that you will be able to see the following figure .The description of the app are mention on the figure please try it out. An immediate test to is to press the on/off toggle Relay button .You will be able to hear the relay tick sound every time you press it.

You can download the Arduino,Android App source code and the Android App apk from this Github.

Beta Development

You can try to directly connect Wifi Arduino board to your router by first connecting your android phone to the board and then through the app sending the following command


XX represents number of ”YYYY”,”ZZZZZ” (including quots)+1

YYYY represents your wifi router SSID

ZZZZZ represents Wifi Password of your router

Example: Lets say my SSID is robo and wifi password is aaa111

Then the command would be


And after sending it you need to wait for at approximately 4 min then you can access your wifi router and gen the ip of this device and connect it directly through the router .Please note this is still not a perfect program and fails some time mostly due to lengthy string of ssid and password

A snap shot of the way it can be sent is show below

Step 4: Connecting an AC Load & PIR Sensor ,Assembling It in a Box

The type of box used is called a Gang Box(shown in figure) .It can be cut using a blade(refer Fig) ,that is how I have made the basic cutout on the box for the physical switch(Red colour), the three pin AC socket, and the PIR Sensor.

The Power Supply for the Wifi Arduino 85 Board is a mobile charger (5V DC, 1000mA) ,just opened the casing and soldered some wires .The two board(Charger ,Wifi Arduino 85) are fixed inside the box using double sided tape .

The relay on the board requires a 5V DC input to the coil and 220V AC 5A load bearing output .You will have access to both NC(Normally closed ) and NO ( Normally open)terminal of the relay

Most of us generally use the NO terminal .One of the fig will show you how one can connect a load to the board. Please note to prevent the EMI from disturbing the controller and Wifi module and to increase the relat life we have provided a varistor(270V AC) which you will need to connect across NO and Common point of the relay (in case you are using NC then across NC and Common) and incase you are connecting inductive loads please make sure you use appropriate snubber circuit across your load.

On the board you will be able to find an open GPIO pin directly from the Attiny 85 controller (refer fig) .Which can be used either as input(default code it is set as input ) or output. You will be able to connect sensors like PIR to it .In addition we have also provided a VCC and Ground pin on the same header .The VCC pin will be at the same voltage level as that of the Attiny 85 microcontroller which depends on the previously mentioned jumper selection of VCC voltage to the controller .These things are clearly shown in the figure .If you wish to connect an external relay you will be able to connect it through a transistor circuit using the Attiny 85 gpio and by changing the Attiny 85 code.In this instructable I have connected it to a PIR sensor.As the PIR sensor runs at 5V ,this voltage is tapped from one of the headers.

You can watch the complete video over here

I hope you will make one on your own and make it better then me. If you have any doubts/question please let me know .

I thank you for reading my instructabe (Hope you liked it ).The wifi arduino 85 schematic(user manual) is available on our Github you can build it on your own.

Step 5: Controlling Smart Switch Using HTTP and MQTT Commands

Download the code from the github

for esp-01

Wifi-Arduino-85-Switch-Esp-01 use this firmware

for attiny85

Wifi-Arduino-85-Switch-Attiny85 use this firmware

and lib for esp

Http commands

http://Your ip address/gpio?state_sw=%2BATturn_on //to turn on

http://Your ip address/gpio?state_sw=%2BATturn_off // to turn off

http://Your ip address/gpio?state_sensor=1 //to enable sensor mode

http://Your ip address /gpio?state_sensor=0 // to disable sensor mode

To configure your ssid/password watch this video (it is similar)


and to burn firmware to esp,attiny85 using arduino refer these



for mqtt commands





are the commands

Home Automation

Participated in the
Home Automation