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
8.Switch
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
AT+CIOBAUD=xxxx .
xxxx has to be 4800 for Wifi Arduino 85 Board
You can also set your Router SSID and Password by using the following command
AT+CWJAP="SSID","Password"
For more details on AT commands refer the AT command data sheet of ESP8266
Attachments
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 192.168.4.1 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,”YYYY”,”ZZZZZ”
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
%16,”robo”,”aaa111”
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
https://github.com/armtronix/Wifi-Arduino-85/tree/...
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
libraries.zip
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
+ATturn_on
+ATturn_off
+ATstart
+ATstop
are the commands

Participated in the
Home Automation
25 Comments
6 years ago
I'm tryng to flash the esp8266 with code, but the Arduino IDE make an error:
sketch_mar20a.ino: In function 'void setup()':
sketch_mar20a:118: error: 'macToStr' was not declared in this scope
sketch_mar20a:122: error: 'loadConfig' was not declared in this scope
sketch_mar20a:128: error: 'initWiFi' was not declared in this scope
sketch_mar20a.ino: In function 'void btn_handle()':
sketch_mar20a:165: error: 'setOtaFlag' was not declared in this scope
sketch_mar20a.ino: In function 'void loop()':
sketch_mar20a:185: error: 'clearConfig' was not declared in this scope
sketch_mar20a:193: error: 'setOtaFlag' was not declared in this scope
sketch_mar20a:207: error: 'connectMQTT' was not declared in this scope
sketch_mar20a:216: error: 'mqtt_handler' was not declared in this scope
sketch_mar20a:224: error: 'initWiFi' was not declared in this scope
'macToStr' was not declared in this scope
Reply 6 years ago
You will need this https://github.com/armtronix/Wifi-Arduino-85/blob/master/Arduino%20Code/libraries.zip
7 years ago
Awesome !! I've buy a shield by Kickstarter campain. The instructions are very good and complete. Now I want use a computer to send the command to board. If I program the Attiny and connect it to my lan can I use a browser to send or read the board message? Can I write a html page to use this?
Thank's
Giovanni
Reply 7 years ago
yes you should be able to do that .only thing you will need to flash both esp-01 module and esp8266 .will share the code .although you will need to modifify it as per you requirement
8 years ago on Introduction
Wiring schematics are not very clear. Is it possible to upload a fritzing diagram?
Reply 8 years ago
will try to when ever I am free.let me know which part you were not able to understand so that I can clarify you doubt.
Reply 8 years ago
Thanks for a very quick response. I was looking for connectivity between different components starting with the Mains. So mains, power supply, board, switch, IR and bulb/load. PIR is the easiest and I understand that. Not that pictures are not visually clear but it is difficult (for me at least) to figure out which wire is going where. Basically the following image in fritzing so that all the connections are clearer. https://cdn.instructables.com/FQ4/V0HW/IATHCXON/FQ4V0HWIATHCXON.MEDIUM.jpg
Reply 8 years ago on Introduction
have you see this
https://cdn.instructables.com/FCY/30MP/IAHPB9B1/FCY...
this should be clear. 220-240V AC (mains) goes to your SMPS/Mobile charger (5V D--1A) .The 220-240V AC (mains) should also connect to the bulb and relay terminal (NO--Common) in series .The varistor in parallel to the (NO-Common) terminal of the relay
https://cdn.instructables.com/FIC/60WC/IATHDWMN/FIC...
if you see the above fig the attiny gpio b2 is where you will need to connect your PIR sensor Data line .the pir sensor runs at 5V (input) you can tap this from the open header shown in the same figure (left side ).I hope your doubt is clear
Reply 8 years ago on Introduction
Your links are cut off. Can you please post them again. Thanks for all the response.
Reply 8 years ago on Introduction
here are the imgs
8 years ago on Introduction
I suspect using the Arduino IDE and
changing the code to C++ the whole process could be made a lot simpler.
The ESP8266 has 10 times the speed of the fastest ATTiny85 and has 256Kb
memory rather than 4Kb.
All of your program will fit on it and no need for ATTiny
Reply 8 years ago
I agree. but the whole purpose if this board is to keep it simple and make it usable with any uart based module(esp8266,hc05 etc) and if you consider esp8266-01 module you will get some more gpios and adc on this board.
8 years ago
Cool
8 years ago on Introduction
Hi. where did you get Wifi Arduino 85 Board.
Reply 8 years ago on Introduction
You can buy this board on tindie .Go to the below mentioned link
https://goo.gl/e1XV7W
8 years ago
awesome... good job...i think v can play a prank by turning on/off lights or electrical stuff through this...
Reply 8 years ago on Introduction
Thank you for your idea and support
8 years ago on Introduction
awesome :)
Reply 8 years ago
thankyou
8 years ago
What type of Varistor did you use?