Arduino IOT Automation With ESP8266

97,450

508

51

About: I,m an Electronics Engineer. Love to make things work. Believe in Learn by Making it.

Intro: 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:

https://www.instructables.com/id/IoT-Raspberry-Pi-A...

Step 1: 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

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

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

GET https://api.thingspeak.com/update?api_key=your_api_key&field1=value

  • Update Channel Feed - POST

POST https://api.thingspeak.com/update.json

api_key= your api key

field1= value you want to post

  • Get a Channel Feed

GET https://api.thingspeak.com/channels/your_channel_no/feeds.json?results=1

  • Get a Channel Field Feed

GET https://api.thingspeak.com/channels/your_channel_no/fields/1.json?results=1

  • Get Status Updates

GET https://api.thingspeak.com/channels/your_channel_no/status.json

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.

2 People Made This Project!

Recommendations

  • Optics Contest

    Optics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Plastics Contest

    Plastics Contest

51 Discussions

0
None
spandana12345

1 year ago

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:

AT+CIPCLOSE

AT+CIPCLOSE

AT+CIPCLOSE

AT+CIPCLOSE

can u plz help me out sir

1 reply
0
None
asad bukharispandana12345

Reply 5 weeks ago

Where to download the code? Can you plz tell me. Because the upper download link requires the upgrade.

0
None
apurnakv

Question 4 months ago on Step 4

All I get is AT+CIPCLOSE, why? I checked the string length, it is 65.

0
None
latedevil

7 months ago

Sir, thank you so much for the code.

And please provide a wiring diagram for the proper connection of wifi module and Arduino.

0
None
dd007

10 months ago

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 off...how to change d code for that

0
None
surbhi14

1 year ago

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

2 replies
0
None
abhiV4surbhi14

Reply 1 year ago

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

0
None
RichenaldA

1 year ago

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

0
None
krishnenduk2

1 year ago

dude cant download the pdf.why???

0
None
handy23

1 year ago

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?

1 reply
0
None
abhiV4handy23

Reply 1 year ago

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.

0
None
abhiV4

1 year ago

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

1 reply
0
None
JaiS33abhiV4

Reply 1 year ago

yus the channel is public

0
None
JaiS33

1 year ago

hello!

we followed the instructions but it says IPD Found but it does not display the json response as in your video.......it cannot find the feeds basically
if(ser.find("feeds"))

{

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 : https://drive.google.com/open?id=0B1LVsm7Be4BoaTJXdWw1THNsbUU

0
None
JaiS33

1 year ago

hello!

we followed the instructions but it says IPD Found but it does not display the json response as in your video.......it cannot find the feeds basically
if(ser.find("feeds"))

{

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 : https://drive.google.com/open?id=0B1LVsm7Be4BoaTJXdWw1THNsbUU

0
None
NATARAJS2

1 year ago

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

0

D

+IPD found

0

D

+IPD found

0

D

0
None
NATARAJS2

1 year ago

please give your whats app num