ESP8266 IoT Control and Monitor Using Arduino, MQTT, and Cayenne

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi I'm Cisco with AK robotic and I'm here to talk to you about how to monitor and control any device over the Internet in other videos we've shown you how to get started with Internet connected projects one question that usually comes up is how to repeat the process by using the Internet to access the projects remotely a great way to achieve this is by using a third-party service today we're going to be using my devices Cayenne the world's first drag-and-drop Internet of Things project builder we'll be connecting our favorite Wi-Fi enabled microcontroller the esp8266 to their online dashboard using the arduino ide this will allow us to work with their wonderful graphical interface to monitor temperature and humidity and to control an LED let's get started the first thing we'll need is to go to the Arduino website click on the software tab and download the latest version of the IDE for your operating system unzip the file far up the application and we'll want to install libraries that will allow us to connect to the Cayenne platform because we're using the esp8266 we'll need to go to the my devices github page and click on clone or download and download set we'll leave the link to this library in the description of the video now we can go back to the arduino ide go to the sketch menu include library and add the zip library we can then navigate to the location of the file and double click on it you'll see a confirmation message that tells you that the library was added to your project the last step is to go to the my devices cayenne website and sign up for an account using the link near the bottom in the interest of time we've gone ahead and created an account of our own and as you'll see when you first log in you'll be presented with different options for adding hardware to the platform for the esp8266 we'll go ahead and select the bring your own thing option will be presented with a few bits of information but for our purposes we're going to be using the MQTT username the mqtt password and the client ID we'll go back to the arduino ide and the first thing we'll do is include the library that we installed previously next we'll be defining five character arrays to hold the different credentials that we're going to need both to connect to our Wi-Fi network and also to connect to the Cayenne platform the first alcohol SSID and I'll just use our local Wi-Fi network name here next I'll add the password to the Wi-Fi network and then I will be adding the three different fields from the Cayenne plat the first one I'll name username and I'll set it to a string containing the MQTT username from the website then it'll be the mqtt password and lastly the client ID thanks to the client library setup is really easy we only need a single line of code calling the begin method of the kind object we'll add all the different parameters that we defined above will be the user name the mqtt password the client ID the SSID and the Wi-Fi password the first thing we'll do in the dashboard is setup a button to control an LED so let's go ahead and set up pin number two to be an output if you remember from our other videos then two is tied to the blue LED on the little ESP 12v module on our development board the logic of that LED is inverted so I'll be using the video write function to set it off then in our loop function we can call the loop method of the kyon object that's available through their library lastly we'll be using a helper function that's called Cayenne in in order to receive a command from the website and turn the LED on Anna it can take one parameter to specify a channel I'll be choosing zero in order to send the command from the website through that channel onto the board we can then use the digital write function one more time get the value from the website and we're going to be formatting it as an integer it's going to be a digital value so it'll be either 1 or 0 and remember because the logic is inverted we'll need to be inverting the command from the website itself we're ready to upload the code but if you want to find out a little bit more information we can add two additional lines for debugging purposes we can define a constant called km debug and also we can define a constant cayenne print and we can set it to the serial object go ahead and save the code and I'll just go on my desktop and name it my devices mqtt I'll select my board and port for what I'm using this case is the silicon labs USB to UART port and the node MCU 1.0 board make sure your board is connected to the USB port and we can upload the code if everything goes smoothly the website will present you with a new that work for your device it looks like this and if you want to change the name for it you can click on the gear icon configure and we can assign the name esp8266 MQTT now we can use the left 4 menu to add a new widget it will be of type custom widgets button and we'll name it LED it will be of type digital actuator the units will be either 0 or 1 and it'll be on channel 0 as we configure that one on our arduino ide we'll choose the little light bulb icon now if we click on the button the LED should be on at the same time that the button is highlighted we click it again the LED should turn off so at this point you might be wondering what MQTT is all about and we'll leave you a link in the description of the video so that you can find out more information but will tell you that it's a communication protocol for devices that want to talk to one another over a network in the past within using HTTP for communicating between devices on a network but there are a few advantages of using MQTT particularly on devices that need to run on low power and also consume as little memory as possible it's a very lightweight protocol and also it uses a publish/subscribe pattern so that devices such as the esp8266 can take advantage the last thing i want to say about mqtt is that there is a device called a broker that's needed on the network in our case we're using the km platform as our MQTT broker in the background Cayenne is handling all the message queues that are being transmitted and received by the different devices that we connect to it now let's add a sensor to our dashboard on Cayenne we'll be using the dht22 sensor so we'll need to add additional libraries to our arduino ide this case we can go directly through the sketch menu include library and manage libraries we can search for DHT install the first library and we'll need a second library also by the wonderful folks from Adafruit that's called unified sensor the easiest way to find it is by typing in the word unified followed by our EQ after installing them we can go ahead and include it using the BHT edge header and then we can create an object that will call DHT of class DHT and it will take two parameters the first will be the pin that we're using for the sensor in our case is b2 and the second is the type of sensor that we're using in our case is dht22 in our loop function we can use that DHT object to read the temperature and humidity from the sensor a lot of reminder for myself that this is in Fahrenheit lastly we can use the virtual write method from the client object to send the values up to the dashboard this method takes in 4 parameters the first is the channel and we're already using 0 for our LED so I'll use one next it will be the actual value in my case the first one that I want to send out this is the temperature the last two parameters will allow us to tell the dashboard what type of sensor and what units to use we can repeat that same line for the humidity change the channel 2 number 2 the value the type of sensor and the unit we're now ready to save the code and upload it to our board [Music] if everything goes according to plan you can go back to your dashboard and observe your two new measurements the temperature in Fahrenheit and the humidity in percentage you can even blow on the sensors and see your measurement change a very neat feature that we found on the Cayenne platform is the ability to very easily set up triggers without writing any additional code under three no ID to do that will first add the two channels to our dashboard by clicking the little plus sign on the top right corner let's rename the channels to something more meaningful and let's rename the temperature as well go to the user menu triggers and alerts click on new trigger and we can drag our device right next to the f-word click on select trigger and use either the temperature on the humidity - let's say turn on the LED let's choose humidity and we want to say that if the sensor reading is above 50% then we want to turn on the LED so we want to drag the device right next to the then word select the LED and by default is going to be selected as on go ahead and give it a name we'll call it humidity greater than 50% save it go back to the device and if we simply blow the sensor and there you have it you could also set up another trigger for when the humidity goes below 50% the LED should turn off we would like to thank my devices for sponsoring this tutorial and if you like our videos don't forget to Like subscribe or leave us a comment until next time
Info
Channel: ACROBOTIC
Views: 75,803
Rating: undefined out of 5
Keywords: ESP32, ESP8266, Arduino, IDE, NodeMcu, Tutorials, Makers, Learn, Guide, IoT, Internet Of Things, Raspberry Pi, Wireless, Communication, Weather, Creative, Sensor, Python, Programming, C++, Beginner, Electronics, DIY, MicroPython, 3d Printing, CAD, Fusion 360, Education, Tutorial, Intro, Introduction, Web, Developer, HTML, Datalogger, Project, Sensors, Data, Visualization, Webserver, Server, Client, App, WebApp, Wemos, Robot, Robotics, Robots, Easy, Adafruit, Sparkfun, OS X, Windows, Linux, Embedded, Kickstarter, RC, Fun, Build, Engineering
Id: 6YAnqHTm7_o
Channel Id: undefined
Length: 14min 24sec (864 seconds)
Published: Tue May 09 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.