Introduction: Arduino IOT Automation With ESP8266

Picture of Arduino IOT Automation With ESP8266

This is a IoT automation project. not like others which only fetch the sensor data to the internet. i used there technique to control the devices by reading to that web api using wifi module esp8266. with this technique we can monitor , control the devices from anywhere in the world. today i,m controlling a led , just like hello world program for IoT world.

you can read my new IoT instructables using Raspberry pi and arduino here:

Step 1: Overview

Picture of Overview

I,m back with my new instructable. There are many instructables about IoT and home automation.

but most of them is all about writing the sensor data to the web, making weather stations etc. but i wanted to control devices using internet just like people do it with GSM using sms command.

So, finally i did it with the help of esp8266 our loving wifi module and world's best board arduino uno. we just need to modify the data using web api and arduino will react on that. here it will turn board led on and off.

Step 2: Material Needed

Note:- Watch the above video of complete developed IoT Automation device. Thank you.

We need the following things:-

1. Arduino uno

2. ESP8266 wifi module

3. Wi-Fi router (cell phone hotspot will be perfect )

Step 3: Connecting Things

Picture of Connecting Things

you can check the pinout in the pics. RST, ch_pd should be connected to Vcc i.e. 3.3V for normal operation. it is only a precaution as module works great without doing this also.

ESP8266 is a 3.3V device so needs to be plugged into the 3.3v pin of arduino or seperate supply. i have used arduino supply and it works perfect.

the Rx and Tx of the esp8266 should be connected to Tx and Rx of arduino. I,m using software serial port here pin 3 as Rx and 2 as Tx. leaving my hardware uart for debugging purpose. esp8266 pins are not tolerable to 5v so kindly use level shifter. however i,m using it directly and found no issue but it is good to be safe than sorry.

default baud rate of esp8266 is 115200. you need to change this below the hardware uart baud rate. i,m using 57600.

change this using AT+UART_DEF=57600,8,1,0,0 command.

Step 4: Programming

Picture of Programming

Find the attached ino file for programming the arduino. // updated firmware has been uploaded with better reception and resolving timing issues with thingspeak api server. // Special thanks to Bookwormzero aka Neil for finding the timing issue. good job done.

i,m using arduino to read the api and act according to the data received. we can use any internet enabled device to control the arduino pins. here i,m turning board led on and off by writing H for high and L for low to the web api. this can be done from anywhere in the world with the internet.

Updated section:-

Following commands are used to operate Thingspeak channel.

  • Update Channel Feed - GET


  • Update Channel Feed - POST


api_key= your api key

field1= value you want to post

  • Get a Channel Feed


  • Get a Channel Field Feed


  • Get Status Updates


Update channel feed- GET request can be used to write data to field1 by typing the URL in any browser with internet connectivity. This act as our remote control i.e. any internet enabled device.

Now to control the things we need to read the field1 data by using our arduino and use it as a command for predefined tasks. E.g i used “H” for making board led high and “L” for making it low.

To read the value of field1 we will send “ Get a channel Field Feed- GET request using arduino and ESP8266.

I assume here that you worked before with esp8266. When we send GET request, web api send some data in return in string format which can be read using uart of esp8266. Just look for +IPD at serial as it is transmitted if there is something available to read.

In returned string you will get the field 1 data. Check out the string below:-

{"channel":{"id":85291,"name":"IoT testing","description":"Home Automation cum controller","field1":"test led","field2":"fan","field3":"tv","field4":"light","created_at":"2016-02-07T13:01:17Z","updated_at":"2016-02-23T14:34:38Z","last_entry_id":695},"feeds":[{"created_at":"2016-02-23T14:34:38Z","entry_id":695,"field1":"L"}]}

bold part is the main data we need to use. To get it right i used a trick here. as we don't need the whole string i looked for " feeds " word as starting point as it is unique in whole string comes only once. and stored the remaing string in a character array. L is the 66th character after Feeds. so array storing this value should be array[65].

use this value to trigger any function you want.

Note:- change the array[65] to array[i-13] for better reception and resolving issues related to identify the field value.

//change esp8266 baud rate to 57600 or lower before use as hardware baud rate is 115200. software serial should be lower than hardware.


dd007 (author)2017-12-14

Bro...u r d man I was searching for...I'm also doing d same stuff like ur project..but I use IR sensor additionally.. to automatically on and to change d code for that

surbhi14 (author)2016-12-23

nice tutorial...please mention what should i write in apikey?

abhiV4 (author)surbhi142016-12-23

Nothing. You only need api key when you publish the data. As you are reading the data you don't need it.

ShankarB8 (author)abhiV42017-11-26

projects websites

spandana12345 (author)2017-03-23

i just downloaded the code u have given and updated my api key,ssid and password but i dont know y my serial monitor is showing like this:





can u plz help me out sir

RichenaldA (author)2017-03-05

sir, please include a wiring diagram of your project. thank you

krishnenduk2 (author)2017-02-06

dude cant download the pdf.why???

TomV85 (author)2016-12-21

Thank you for writing this code.

abhiV4 (author)TomV852016-12-21

My pleasure

handy23 (author)2016-11-21

nice project sir but i still dont understand why do u change the array[65] to array[i-13]? why do u minus the array[i] with 13?

abhiV4 (author)handy232016-11-21

Coz length of returning string isn't fixed. It may be c[64] for me and 65 for you. But string after that byte is of fixed length. I.e 13 more characters. So just minus 13 from length if the string and you will get that controlling byte every time. And this works for everyone. I hope your doubts are clear now.

abhiV4 (author)2016-11-12

Jais33. Did you made thingspeak channel public?
Without doing so you will not get any fata.

JaiS33 (author)abhiV42016-11-14

yus the channel is public

JaiS33 (author)2016-11-12


we followed the instructions but it says IPD Found but it does not display the json response as in your cannot find the feeds basically


Serial.println("Into If");

Serial.println("found feeds:");


it does not enter this code fragement------it does not print "into if" or "found feeds"....directly jumps to the else part....

here is the link our code :

JaiS33 (author)2016-11-05


we followed the instructions but it says IPD Found but it does not display the json response as in your cannot find the feeds basically


Serial.println("Into If");

Serial.println("found feeds:");


it does not enter this code fragement------it does not print "into if" or "found feeds"....directly jumps to the else part....

here is the link our code :

NATARAJS2 (author)2016-10-31

I AM UPDATE UR ABOVE CODE i am only change wifi detail ,api key & channel num but output came

connected to Thing speak API

+IPD found



+IPD found



+IPD found



NATARAJS2 (author)2016-10-31

please give your whats app num

abhiV4 (author)2016-10-31

Json is not a file. It's a string format. I'm filtering this returned string to get the desired data. You have updated the code wrong.

NATARAJS2 made it! (author)2016-10-31

my arduino code

abhiV4 (author)NATARAJS22016-10-31

your code is not correct. http request url is wrong. and every command sent by Serial to wifi should be followed by "\r\n" ... download my code above and just replace API KEY, wifi details and thingspeak channel number. don't edit anything else.

NATARAJS2 (author)2016-10-31

i am only create channel. but did not update any codes for json files.if we must want json files or not.if

NATARAJS2 (author)2016-10-31


NATARAJS2 (author)2016-10-31

i will show my code

NATARAJS2 (author)2016-10-30

please put your arduino code here

NATARAJS2 (author)NATARAJS22016-10-30

the return string not come ,the return values are

+IPD found



+IPD found



+IPD found



NATARAJS2 (author)NATARAJS22016-10-30

please help me

abhiV4 (author)NATARAJS22016-10-30

Show me your code.

GabrielC115 (author)2016-08-31

Sketch uses 7,808 bytes (24%) of program storage space. Maximum is 32,256 bytes.

Global variables use 683 bytes (33%) of dynamic memory, leaving 1,365 bytes for local variables. Maximum is 2,048 bytes.

avrdude: ser_open(): can't open device "\\.\COM3": Access is denied.

Problem uploading to board. See for suggestions.

abhiV4 (author)GabrielC1152016-09-01

you have selected the wrong COM port. Or your COM port is attached with any other software. Make sure you have selected the correct COM port . To find out if you are using arduino nano than look for COM port created by ch340g, and if using arduino uno then look for COM port along with the name COM ( Arduino uno/ genuino). Then select your port in arduino ide under tools > port.

GabrielC115 (author)2016-08-31

i am lost at this page, please help

sandeeps121 (author)2016-08-25

hi, im using raspberry pi 3 i want to send my webcam data to website every 2 mins i dont want to store the data on pi what should i do to achive this please help me asap

abhiV4 (author)sandeeps1212016-08-25

on which website you are trying to put the data?

KoenV4 (author)2016-02-23

Alternative: you can flash the ESP with NodeMCU ( and program Lua ( against it. For a few euro's more you buy an ESP-12 that offers much more ports an can be powered with a standard power supply. No Arduino required.

csifreeman (author)KoenV42016-03-11

Following this way , do we have a lua code to update a DDNS server such as the no-ip so we can control the ESP from anywhere ?

abhiV4 (author)csifreeman2016-03-12

i don't have such code. as i never programmed esp before. sorry

abhiV4 (author)2016-03-08

my new IoT project with pi. soon i will publish here.

ihart (author)2016-02-23

It seems like something is missing here. Can you show how you use Thingspeak to get the web to be able to control this Arduino?

abhiV4 (author)ihart2016-02-23

Sorry i was thinking that people will understand by reading Firmware. but i updated everything in detail now. please have a look.

BookwormZero (author)abhiV42016-03-03

Good instructable, I built this and it works , after a little modification to the code.

Well done, keep up the good work.

abhiV4 (author)BookwormZero2016-03-04

web api of thingspeak is not returning the data continuously as we got data for in few attempts which makes it slow and not reliable. if you did something with that then please tell me. i need it.

BookwormZero (author)ihart2016-03-03

Hi, checkout this instructable, it helped me understand Thingspeak.

Back to this instructable, I used ESP8266 User Program from to set my wlan as default, as the arduino is sometimes 'sketchy' as to whether it will connect or not.

I also connected TX from ESP to pin 10, RX from ESP to pin 11, with a baud rate of 57600.

I modified the code slightly, i noticed that references to char 65 were wrong and it should be char 66, eg. (c[66] this works for me , the LED is triggered as expected, then after several reads from thingspeak it turns off again.

I can supply the updated code is required.

abhiV4 (author)BookwormZero2016-03-04

c[66] and c[65] was not so reliable. i also modified that to c[i-13]. and that works perfect for me.

BookwormZero made it! (author)2016-03-03

Slight mod to code, but it works as described. Useful instructable. well done.

abhiV4 (author)BookwormZero2016-03-04

thanx buddy

yash thaker (author)2016-02-28

Can you please provide clear circuit diagram.

AlanF11 (author)2016-02-24

I am a newbie. Looks great. Where is the code?

abhiV4 (author)AlanF112016-02-24

I have attached the.ino file named iot_api_read.ino . Just download it.

mlakhwani (author)2016-02-23

hello,nice project,

please share some clear wiring diagram.

and can i control gipo pins via apache server hosted on RPi?

abhiV4 (author)mlakhwani2016-02-23

Sorry buddy. i,m newbie to Rpi. still trying to figure it out.

mlakhwani (author)abhiV42016-02-24

that's great for a start, i just made a 8 channel power strip controlled by ok google command on my android by following this tutorial:
wanted to create something similar with arduino + ESP8266

i hope it helps :)

Happy coding

About This Instructable




Bio: I,m an Electronics Engineer. Love to make things work. Believe in Learn by Making it.
More by abhiV4:Arduino - PV MPPT Solar ChargerWireless Power Transfer PrototypeRaspberry Pi Tutorial
Add instructable to: