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

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.

<p>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:</p><p>AT+CIPCLOSE</p><p>AT+CIPCLOSE</p><p>AT+CIPCLOSE</p><p>AT+CIPCLOSE</p><p>can u plz help me out sir</p>
<p>sir, please include a wiring diagram of your project. thank you</p>
dude cant download the pdf.why???
<p>nice tutorial...please mention what should i write in apikey?</p>
Nothing. You only need api key when you publish the data. As you are reading the data you don't need it.
<p>Thank you for writing this code.</p>
My pleasure
<p>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? </p>
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.
Jais33. Did you made thingspeak channel public?<br>Without doing so you will not get any fata.
<p>yus the channel is public</p>
<p>hello!</p><p>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<br>if(ser.find(&quot;feeds&quot;))</p><p>{</p><p>Serial.println(&quot;Into If&quot;);</p><p>Serial.println(&quot;found feeds:&quot;);</p><p>......</p><p>it does not enter this code fragement------it does not print &quot;into if&quot; or &quot;found feeds&quot;....directly jumps to the else part....</p><p>here is the link our code : https://drive.google.com/open?id=0B1LVsm7Be4BoaTJXdWw1THNsbUU</p>
<p>hello!</p><p>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<br>if(ser.find(&quot;feeds&quot;))</p><p> {</p><p> Serial.println(&quot;Into If&quot;);</p><p> Serial.println(&quot;found feeds:&quot;);</p><p>......</p><p>it does not enter this code fragement------it does not print &quot;into if&quot; or &quot;found feeds&quot;....directly jumps to the else part....</p><p>here is the link our code : https://drive.google.com/open?id=0B1LVsm7Be4BoaTJXdWw1THNsbUU</p>
<p>I AM UPDATE UR ABOVE CODE i am only change wifi detail ,api key &amp; channel num but output came</p><p>connected to Thing speak API</p><p>+IPD found</p><p>0</p><p>D</p><p>+IPD found</p><p>0</p><p>D</p><p>+IPD found</p><p>0</p><p>D</p>
<p>please give your whats app num</p>
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.
<p>my arduino code</p>
<p>your code is not correct. http request url is wrong. and every command sent by Serial to wifi should be followed by &quot;\r\n&quot; ... download my code above and just replace API KEY, wifi details and thingspeak channel number. don't edit anything else.</p>
<p>i am only create channel. but did not update any codes for json files.if we must want json files or not.if </p>
<p>i will show my code</p>
please put your arduino code here
<p>the return string not come ,the return values are</p><p>+IPD found</p><p>0</p><p>T</p><p>+IPD found</p><p>0</p><p>T</p><p>+IPD found</p><p>0</p><p>T</p>
<p>please help me</p>
Show me your code.
<p>Sketch uses 7,808 bytes (24%) of program storage space. Maximum is 32,256 bytes.</p><p>Global variables use 683 bytes (33%) of dynamic memory, leaving 1,365 bytes for local variables. Maximum is 2,048 bytes.</p><p>avrdude: ser_open(): can't open device &quot;\\.\COM3&quot;: Access is denied.</p><p>Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.</p>
<p>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 &gt; port. </p>
<p>i am lost at this page, please help</p>
<p>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</p>
<p>on which website you are trying to put the data?</p>
<p>Alternative: you can flash the ESP with NodeMCU (nodemcu.com) and program Lua (lua.org) 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.</p>
<p>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 ?</p>
<p>i don't have such code. as i never programmed esp before. sorry</p>
<p>my new IoT project with pi. soon i will publish here.</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/_QSDNzlw1cU" width="500"></iframe></p>
<p>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?</p>
<p>Sorry i was thinking that people will understand by reading Firmware. but i updated everything in detail now. please have a look.</p>
<p>Good instructable, I built this and it works , after a little modification to the code.</p><p>Well done, keep up the good work. </p>
<p>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. </p>
<p>Hi, checkout this instructable, it helped me understand Thingspeak.</p><p><a href="https://www.instructables.com/id/ESP8266-Weather-Station-with-Arduino-2-Software/?ALLSTEPS" rel="nofollow">https://www.instructables.com/id/ESP8266-Weather-St...</a></p><p>Back to this instructable, I used ESP8266 User Program from firatdeveci.com to set my wlan as default, as the arduino is sometimes 'sketchy' as to whether it will connect or not.</p><p>I also connected TX from ESP to pin 10, RX from ESP to pin 11, with a baud rate of 57600.</p><p>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. </p><p>I can supply the updated code is required.</p>
<p>c[66] and c[65] was not so reliable. i also modified that to c[i-13]. and that works perfect for me.</p>
<p>Slight mod to code, but it works as described. Useful instructable. well done.</p>
<p>thanx buddy</p>
<p><strong>Can you please provide clear circuit diagram.</strong></p>
<p>I am a newbie. Looks great. Where is the code?</p>
I have attached the.ino file named iot_api_read.ino . Just download it.
<p>hello,nice project,</p><p>please share some clear wiring diagram.</p><p>and can i control gipo pins via apache server hosted on RPi?</p>
<p>Sorry buddy. i,m newbie to Rpi. still trying to figure it out.</p>
hello,<br>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:<br>https://www.instructables.com/id/Web-Controlled-8-Channel-Powerstrip/?ALLSTEPS<br>wanted to create something similar with arduino + ESP8266<br><br>i hope it helps :)<br><br>Happy coding
<p>If you only need two IO pins, you can program ESP2866 directly with Arduino IDE, negating the need to have an Arduino board as well as the ESP8266. It would involve either a serial level converter or a USB to serial adaptor that does 3v3 levels. Plus also a 3v3 PSU or regulator, but still quite compact and low cost.</p>
<p>Actually i,m not programming esp8266. i don't even know how to do so. i,m using arduino as a standalone controller which is connected to internet through esp8266. So i can control the pins of arduino from anywhere also by writing data to web i can also monitor sensor values, status of devices and much more. </p>

About This Instructable




Bio: I,m an Electronics Engineer. Love to make things work. Believe in Learn by Making it.
More by abhiV4:Wireless Power Transfer Prototype Raspberry Pi Tutorial Arduino Buck-Boost Converter 
Add instructable to: