Arduino IoT Cloud 2021 - Getting Started with Arduino & ESP32

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we're getting started with the arduino iot cloud we'll learn how to build a thing connect it to a device and build a dashboard to control our arduino through the cloud we'll also use the arduino iot cloud with an esp32 we have our head in the cloud today so welcome to the workshop well hello and welcome to the workshop and today we are going to be working up in the cloud specifically the arduino iot cloud the arduino iot cloud is a product that lets you use arduino boards and some third-party boards as well and control them through the cloud so we can build our own internet of things devices using arduino coding that we're very familiar with now the arduino iot cloud has been around for a little while but it recently underwent a big change in the way that things work on the cloud and the way that plans work as far as joining the cloud and pricing in that has all been reworked so you've probably seen a few videos or read a few articles about the iot cloud i just want to let you know if those videos and articles were made before 2021 chances are they are a little out of date and not exactly correct now one of the advantages about the updates that arduino has made recently is that they've changed the pricing structure on the cloud there is still a free plan and a number of paid plans and in the free plan you can now use third-party boards which you weren't able to do previously so we don't have to restrict ourselves to arduino boards we can also use devices like esp32s and i'll be showing you that a little later on in this video now i'm going to be using the cloud with my account my account is a paid account however everything i'm doing today is applicable on the free account i'm not going to be using any paid account features so you can sign up for the cloud for free and follow along in the experiments so before we get started let's go and examine exactly what the arduino iot cloud is this is an iot application platform created and maintained by arduino it supports several arduino processors as well as some third-party microcontrollers some arduino processors permit over-the-air updates allowing you to update your code over the internet without a direct connection to the microcontroller the cloud has a mobile app as well that is available for both android and ios an advanced feature of the cloud is an api that allows you to create web and desktop applications to control your microcontroller the api has a software development kit for javascript python and go the arduino iot cloud also supports web hooks and this will allow integration with other existing iot services your historical variable data can be retained in the cloud the length of time it is retained depends upon which cloud plan you have signed up for you'll work with the arduino iot cloud using an online web editor the web editor allows you to create sketches and also has a library manager that is equivalent of the library manager on the desktop ide you'll be using that web editor to build a thing the basic unit in an arduino iot cloud application you'll connect devices to your thing devices being microcontrollers and you will connect your thing to your network in this case being your local wi-fi in most cases you can add io devices to your microcontroller and control them through variables added to your thing you can also create a dashboard in order to control and read data from your thing the arduino iot cloud allows you to connect a compatible microcontroller to the cloud you can control that microcontroller with an online dashboard you can also use a mobile dashboard as well you can also use a second microcontroller to control the first one and you can do this with or without a dashboard you can control existing iot connected devices and you can use iot controllers from amazon to interact with your microcontroller to start working with the iot cloud first you'll connect the microcontroller up to your local workstation you'll then connect to the cloud and the cloud itself will also connect to the microcontroller if your microcontroller supports over-the-air updates you can remove the connection directly to the controller and just do your updates through the cloud in order for all of this work you'll have to install an arduino agent on your workstation this agent is available for linux windows or mac the purpose of the agent is to interface the usb port on your workstation with the web editor you can use the cloud with a number of compatible microcontrollers this will include the arduino nano 33 iot the arduino nano rp2040 connect most of the arduino mkr series of boards from the arduino pro series the portentia h7 as well as the expressive esp32 nesp8266 boards you'll also need to set up a user account in order to use the iot cloud you can start with a free account and if you want more features there are a number of low-cost paid accounts that you can subscribe to as well so let's set up an account and start working with the arduino iot cloud now in order to use the arduino iot cloud you're going to need to create an account and arduino has four different levels of account you can start with the free account and i would suggest that just so that you can start getting used to the iot cloud after that you can move over to another one of these accounts and they have the entry level account at 299 us a month the maker level account at 699 a month and that's the plan that i'm currently on and the maker plus plan which is 23.99 a month now let's see what the differences are between all of these plans now the total number of sketches that you can create is unlimited for all of the plans but the sketch storage will vary it's unlimited for all of the paid plans but it is limited to 100 megabytes for the free plan and 100 megabytes is pretty generous the compilation time refers to the fact that you're going to be compiling your sketches using the arduino web ide and therefore you're going to be compiling online again you're limited to 200 seconds of compile time a day for the free plan and it's unlimited for the other plans but in order to put that in perspective i've been doing a number of experiments with the cloud and i've yet to use 200 seconds in one day so that's a pretty high limit now the number of things you can build is the restriction that you'll have to look at if you want to update to a bigger plan you're only allowed to build two things with the free plan and that can certainly be enough in order to get your interest going however for practical applications you're probably going to want to build a number of things and the number of things increases depending upon which plan you are using another thing is the number of variables that you're allowed to use in each one of your things on the free plan you're allowed to use five variables and five variables is actually not a bad number now these are cloud connected variables on the other plans you can go to 10 variables with the next plan up and the two higher plans have an unlimited number of variables you have an unlimited number of dashboards with all of the plans now dashboard sharing allows you to permit you to share your dashboard with other arduino users i probably won't be doing that anyway but it is included on my plan the api is not available on the free plan it's a more advanced feature and we won't be discussing it today anyway with the other plans you're limited to the number of requests per second you can make to the api web hooks allow you to hook other existing iot services to the arduino cloud and use them with your device and this is available in all the plans over-the-air updates which is a cool feature we've already discussed that allows you to update the code without connecting directly to the arduino is not available on the free plan but it's available on the other plans the amount of time you retain data is also differs between the different plans you'll retain it for one day on your free plan and it goes up to one year on the top plan over here all of the plans now have esp32 and esp8266 support and they all allow you to use the mobile app and so you'll have to select the plan and once you do we can start using the arduino iot cloud now one other task that you're going to need to perform before you can start working with the arduino iot cloud is to install the arduino create agent onto your workstation now the create agent is a small program that runs in the background and it provides an interface between your local usb port and the web-based utilities in the arduino iot cloud and of course you're going to need to be able to do that if you have a microcontroller connected to your computer via usb now there is an agent available for all of the major operating systems for linux for windows and for mac i'm on a linux machine and the installation is pretty well the same on all three of them you download the component you extract the file and you run the installation program it's as simple as that now once the agent has been installed it's going to put a little icon onto your taskbar and here's mine over here an arduino icon it gives me the version of the agent it allows me to go directly to arduino creator to open a debug console i can also pause or quit the agent also during the installation it'll modify your startup a bit so let's let's go take a look at mine here's my startup applications and as you can see the arduino create agent has already installed itself in there so that it will start up every time that i reboot my workstation and again for windows and for mac it will perform a similar function so once you have this agent installed and you have an account we are ready to use the arduino iot cloud now for our first experiments with the arduino iot cloud we are going to start with the basics i'm going to take an arduino nano 33 iot i'm going to attach an led and a temperature sensor to it and we'll see how we can control the led from our cloud console and how we can read the temperature data back to the cloud console and we're going to take this step by step so that you can grasp all of the basic concepts of working with the cloud now if you don't happen to have an arduino nano 33 iot you can use another cloud compatible arduino device and it'll work pretty much the same and that goes true for most of the experiments that we're going to be doing today you could substitute a different controller and get the same results so let's go and see how we hook it up and then i'll show you how we can build our first thing for our first experiment i'm going to be using an arduino nano 33 iot connect board however any board compatible with the arduino cloud would work so for example you could also use an arduino nano rp2040 connect i'm also using a dht22 temperature and humidity sensor you could use a dht11 sensor if you don't have a dht22 you will have to modify the code slightly you'll need an led and a dropping resistor for that led we'll start by connecting the anode of our led to one side of the dropping resistor and we'll connect the other side of that resistor to data pin d8 we'll connect the led's cathode to one of the ground connections on the microcontroller next we'll connect the data output from the temperature sensor to data pin d7 we'll connect the ground connection on the temperature sensor to the arduino's ground and finally the vcc on the temperature sensor will be connected to the 3.3 volt output from the arduino and this completes our wiring so now that we've created an account on the arduino iot cloud and we've added the arduino connect agent to our workstation we are ready to create our first thing now i've cleaned everything out of my console in order to let you see what it looks like the very first time that you come on to the iot cloud and you get an option to create your first thing you also get an option over here to go and build dashboards and we'll be doing that in a little while devices let you set up and configure microcontrollers in order to control them through the cloud and integrations let you work with apis now if you have the free plan this will not be available to you and we won't be looking at apis today so i'm going to go back to things and create our first thing so i'll click the create thing button and the thing editor comes up and you'll notice that it has a setup tab a sketch tab and a serial monitor tab it's got a title which is currently untitled and we've got a section for variables devices and networks so let's go and give this a title first of all and now that we've titled it we can look at the other things now devices are the devices that we are going to connect to the microcontrollers and so i have my arduino nano 33 iot connected right now to my usb port so i'm going to select the device over here and i get a choice of either arduino devices or third-party devices i'm going to set an arduino device because that's what i've got and it should go and detect my device hopefully and there it is it's figured out that i have an arduino nano 33 iot i'll have to hit the configure button now now we have to give it a name and it's going to suggest a name it usually seems to be a female name but i'll give it a different name and you'll notice that i've used dashes in my names you cannot use spaces in a device name and so i'll hit next over here and it's going to try to configure my device for the arduino iot cloud now it needs to dump a bit of code onto it so it can take a few minutes because it has to go and grab the code from the internet but it does happen pretty quickly as you can see and now we are done so now we have a device over here now we can start adding some variables now variables are the cloud variables the variables that we exchange between our device and the cloud so we have on our board of course an led and a temperature and humidity sensor set up we're going to start working with the led right now just to get a feel for this and then we'll come back to the temperature and humidity sensor so hit add variable and we'll give our variable a name now you can name it anything you like i'm naming mine red led because i have a red led obviously if yours was yellow you might choose a different name now we need a type of a variable and there are many many different types that we can choose from including a number of types you haven't seen before such as acceleration angle area etc now there are some of these so-called fancy variable types available that would work with our led there's one called light for example however i have found that with the mobile app that the dashboards don't work properly unless you use a more standard variable type now that's probably just a bug that will be resolved eventually but for now i'm going to just observe that and use a boolean which is a standard variable type and it will do the job because all i want to do is either have my led on or off and so this boolean will represent the state of the led whether it is on or off now you also need to set permissions for your variables and you can give it two different types of permission read and write or read only we need read and write because this is an led and we need to be able to write to it generally when you have an output you're going to have to set it to read and write even though we can't read back from it we need to be able to write for a sensor such as our temperature and humidity sensor we could set that up as read-only because we don't have to send it any data but in this particular case read and write is the correct choice the update policy says when is the variable going to be updated is it going to be updated every time something changes or is it going to be updated periodically such as once a second or once every minute or something we're going to do it on change because we want to build a dashboard that will allow us to control the state of this led with something like a switch and so this is set correctly we're going to add our variable okay now we've added the variable and you notice the network button is now available to us as well and this is the network our wi-fi that we're going to need to configure so let's click on that and we'll have to give it the name and we'll have to give it a password and we will save that okay so i've got my network configured i've got my device configured and variables configured now we can move over to the sketch tab and the sketch tab will give us a sketch that we're going to need to upload to our arduino or our connected device in order to make everything work and you'll notice there's already a lot of things in the sketch now we can edit it here or we can click a button here for the full editor i'm going to stay here and i'll show you the full editor a little bit later on now up in the declaration section you'll notice that it's already mentioned that there's a boolean called red led and we don't need to declare it in this sketch because it's been declared in the cloud we also include in every one of these sketches a file called thing properties and these are the unique properties for our thing now we've got in our setup it's already set up a serial monitor for us it's initialize the thing properties and it's initialized and connected to the cloud we've also set some debugging levels over here now the loop is continuously running something called our arduino cloud update and needs to do that to stay connected to the cloud you can also add extra code to your loop and you'll notice it's made a function here on red led change and that's because we set up a variable that is set to activate on change so whenever it changes this function will be called and we can do something and in our case that's going to be either turn on or off the led so we're need to going to add a bit of code over here in order to make all of this work now of course we have an led that's connected to data pin 8 so we need to let it know about that okay so i've got an integer called my led that represents the pin i'm connected to now down here in the setup i'm going to need to set that up as an output with a pin mode command we've got a little error over here let's fix that you'll notice it did try to put the bracket in the closing bracket for me i accidentally over typed it so i've got a pin mode command and so now our led is set up we're not going to do anything in the loop but we do want to do something when the led changes so before we do anything let's just do a serial print out of what the value of the boolean is okay and we're going to print our boolean value which is called red led and again it put the brackets there but it doesn't put the ending semicolon on there and now we need to actually build some code that will make the led turn on or off and an if statement would do that for us so if it's a red led let's do something then okay so if it is actually existing then we'll turn the led on by sending that pin high and over here we can throw in an else statement and i've got something a little off over here okay fix my spelling errors and so as you can see i've got an if it's a red led i'll turn by l and that should be an ed hi else it's the digital right for my led low and so that looks reasonable over here we can actually go and verify to see if that works and it's going to do a verification you'll notice in the bottom of the screen you get some indication about what's going on so let's just see if i made any syntax errors and we're good and so now i can upload this to by arduino okay it's on the arduino i can head over here to the serial monitor and we'll see that the serial monitors come back and told me i'm connected to the arduino iot cloud so that's great now what i need to do is be able to control the thing i did and for that we're going to need to create a dashboard so let's go into dashboards and we'll build a dashboard now we come up with a blank dashboard called untitled and it also comes up in view mode we have to put this into edit mode in order to do something with it so let's put it in edit mode now you'll notice we get an add button and we can edit the title of this so let's give it a we'll give it a title and we can add widgets to it now widgets are controls we can add to our dashboard and the very first one over here looks like it might be a good one to use it's a switch and we can use that to switch our led on and off so we get the editor for this switch now the name over here is simply going to be what it depl displays on the top so i'm going to just call this led because it's an led control and we need to link the switch to a variable to a cloud variable so we'll link it to a variable we'll look at our things we only have one thing and the only variable available right now is one we created red led and it tells us it's a boolean its last result was false etc and so we'll link that variable to our switch and so now this switch is linked to that variable and it will control it and we can say done and there we go we've got our dashboard created and we can work with the dashboard either at edit mode or view mode so we can look at it over here and we can look at it over there and so now that we've got our dashboard and our code let's go and see if this is actually working all right so as you can see i've got my led connected over here to my microcontroller i've got my dashboard which i just noticed i spelt bass board but i suppose i could correct that if i wanted to but anyway let's see if the switch works i'm going to turn this on and our led comes on and if i turn it off the led goes off now i've also got the mobile app open over here and if i use it i can turn the led on and i can turn the led off and notice that my dashboard or dashboard is also corresponding to what i'm doing on the mobile so when i work the mobile it is also working on the regular dashboard and the reverse is true as well if i go and click this over here you'll see the mobile one corresponds and so you can have your dashboard open on multiple devices and cl and work with it and it will always reflect the current state no matter what device you're on and so there we've built our first thing with the arduino iot cloud now let's go and see if we can modify this to include the temperature and humidity sensor all right now that we have our red led working with our thing let's add the temperature and humidity sensor to it so i'm back in my thing editor i'm going to add some more variables to represent temperature and humidity we'll start with the temperature and i gave it a name over here and as for the variable type again i want to use one of the basic variable types for this and so a floating point number looks like it would be a good thing to use so i'm going to use a float and i'm going to call it board temp now in this particular case it only has to be read only because i'm just reading this value back but we will do this on change and i'm going to leave the threshold empty over here right now instead of that as it is so that's my variable and i'll make another one exactly like it for the humidity okay so now i've got my two variables defined over here let's go and take care of them now in the sketch because as you can see the sketch has now been modified now the sketch has been modified you can see it's added some floats etc over here that i've just defined it's down in this section over here it hasn't really done too much more because basically it was already set up now i'm going to go into the full editor right now though because i'm going to need to include a library in order to work with the dht22 so let's open the full editor and the full editor as you can see has a lot of features it looks in many respects just like the editor on the dashboard at least it has a lot of the same features and here's our code in it over here and you can also see the other files that are included with these projects the thing properties file the secret file is the one which has my username and password for the lan and a readme file which is kind of neat because basically it has just given me the format for a readme that i could edit right now and include with my file so that's a pretty nice little feature so at any rate we need to add a library over here because our dht needs to work with a library so if we go to libraries over here we get a complete library manager and we can search for our library let's search for dht and we got the dht sensor library over here now you can go and hit more info that will open up the page on github that actually tells you all about the library itself you can go down and see some examples for this library what i'm going to do is just included and the include button will let you include it there's an arrow beside the include button and you can also even include earlier versions of the library if you wish so that's a nice handy feature so i'm just going to say include and it's included the library now as you can see it's added some code over here i'm just gonna move that because i like it to be in a different spot we'll put that down over here with this include okay it's included a dht sensor for me now i need to do a little bit of typing in order to make this sensor actually work first of all we have to define the dht pin okay and we've got it connected to i pin number seven and we also need to define the type okay and i've defined mine as a dht22 now if you're using a dht11 you would obviously want to change that particular line and then we're going to go actually create an object and i'll need to put a semicolon in the end of that okay so now we've defined an object called dht and we've defined it with the pin and the dht type okay let's go down into the setup and the setup we need to initialize it so we'll do that somewhere here and we'll do a d8t begin although i didn't put a comma there didn't i there we go dht.begin should initialize everything and we're going to go modify our code in the loop over here because we want to discontinually read the dht sensor now the dft sensors are older capacitive style sensors and they can only update their data about every two seconds we're going to start a loop with a delay and we'll put a two second delay in to start everything off so we give the sensor time to stabilize and then we're going to assign some variables over here so remember our two cloud variables are board temp and board humid so okay dht read temperature just make that a little prettier and we'll do the same thing for the humidity okay there we go so now we can go up here we can save it and we can upload that to our board oh and i got an error where is my a is not declared in this scope and i don't even know how the letter a got in there somewhere in my cutting and pasting no doubt let's give that another try and it's done uploading okay so now we've got a code uploaded we will have to go into our dashboard next and modify that in order to read it so let's go back to the iot cloud i'll leave the page we can go to our dashboards go to my first dashboard and let's go and add some things in order to let us monitor the temperature so let's go down over here and we've got a gauge over here that'll probably be pretty good for temperature so the name i'm going to change it to temp i'm going to link a variable to that one and i can already have board temp and board humidity available for it board temp is what we want we'll link that variable and the maximum a minimum over here the maximum is a hundred which is a little high for the temperature in celsius i'm going to make that 40. and there we go we have a temperature gauge and as you can see it's already up and working it's reading the temperature here in the workshop let's do the same thing for humidity let's go and add another one we could use a gauge but why not percentage because that's how humidity is generally displayed anyway give it a different label we'll link another variable to it board humid we'll link that variable and it's done and there we go and our dashboard is all running and working you'll notice you can use a dashboard in the edit mode or in the view mode it doesn't matter and it still works with the led switch it still has my temperature and my humidity displayed on the dashboard so we have built a thing that is both able to control an led and to read back temperature and humidity now in our first experiment we took an arduino nano 33 iot and we built a thing and we used a dashboard to control that thing but in our next experiment we won't be using a dashboard instead we are going to build two things and i'm going to build them out of arduino nano connect boards but you could use different boards in fact they don't even have to be the same board as long as they're boards that are compatible with the cloud now we're going to put an led and a push button on each board and use the push button on one board to control the led on the other and while that may be simple it illustrates a very important concept and remember these two boards don't have to be on the same wi-fi network although they're both on the same wi-fi network in my office here in montreal right now i could have one of them here in montreal and use it to control another board that's in mumbai or melbourne or minneapolis it doesn't really matter as long as they're both connected to the internet so this is a very powerful technique so let's go and hook up a couple of rp2040 connect boards and we'll see how we can use them to control each other through the arduino iot cloud now here's our hookup remember you're going to need to duplicate this hookup you'll need an arduino nano rp2040 connect board or another cloud compatible arduino board we'll need a momentary contact push button switch an led any color that you like and a dropping resistor for that led i use 220 ohms but anything in the 150 to 330 ohm range will work we'll start by connecting data pin d7 to one side of the resistor and then we'll connect the other side of the resistor to the anode of the led we'll connect the led's cathode to a ground point we'll connect data pin 2 to one side of the push button and the other side of the push button will be connected to ground and this completes our circuit again remember you will need to build two of these circuits for this experiment now the example that we're working with today is actually one that arduino has posted to their website and i have a link to that article in the article on the dronebotworkshop.com website that accompanies this video now you should know that they have one tiny error in their article and i'll point that out as we go along but otherwise it's a great article and you can follow along to repeat this experiment yourself so what i did to start is i took my two arduino nano rp 2040 boards and i registered them both as devices by just going into the device tab and doing add device and here they are and i've named them device one and device 2 as they have named them in the original article and then we created a couple of things one for each device there's remote light 1 and remote light 2. let's go into remote light 1 first now on remote light one i've connected it to device one i've obviously added my network credentials and then i've added a couple of variables one called switch one which is an integer and one called switch two which is a boolean now there was no real reason to use a boolean for one and an integer for the other they're both interchangeable and i think they just did this in order to illustrate that you could use one or the other variable these variables were set up pretty well in the standard fashion now let's go into device number two into thing number two excuse me and i'll show you something with the variables they also have the same variables but the thing is these variables are actually synchronized and i'll show you how you do that if you were to add a variable right now there is a link here that says think with other things if you hit that link you'll see all of the different variables that you have available in all your different things and you can click on one of these variables and have your variable sync with it so the state of that variable and the other thing will match the state of the variable on your thing and so that's what we've done is we've created a couple of synchronized variables within our things now i'm going to go back into remote light 1 and we'll go and we'll take a look at the code there so let's go into the sketch over here and we'll open that in the full editor so we can see it a bit better okay here we are in the full editor and i'll show you the modifications that had to be made to the sketch that was generated for our thing now the first modification and this is true for both of the sketches is we have integers that represent both the led and the push button pins and we've got them connected to the button on pin 2 and the led on pin 7. then in setup we have to initialize those and you'll note that we use a pin mode command and that the button pin is initialized with an input pull up and that way we didn't need to wire a pull up resistor to our push button the led of course is just an output then we'll go into the loop and in the loop what we do is create an integer called button state now we're looking at device number one so if the button state is low which means the button has been pushed what we do is we invert the current value of this cloud variable that we have called switch one so if switch one was for example at a one it would be a zero if it was at a zero it would be a one etc etc and then we put a small delay in there just as a debounce so that takes the status of our switch now there are two things over here that were generated by the thing when we generated it two functions on switch one change and on switch to change now this is actually where they had the error on the original arduino article they had put everything into the switch one change on device number one you need to put it on the switch to change because you're monitoring switch number two on the other device so on switch 2 if switch 2 is high then we'll put the led high else we'll put it low so that just drives the led now if we go back and close this right now and yes we'll say we can close this and if we go back to our things and go to remote light number two we will see basically the identical sketch over here the only difference at the end over here first of all we're looking at the button state on switch two and not the button state on switch one like we did in the first one and this is on switch one change not on switch two chains like it was on the other one of course we're dealing with switch one it says switch two but otherwise they're very very similar sketches and so once you've loaded the sketches to the two devices you're actually finished the project because we don't have a dashboard for this these two things are going to just talk to one another so let's go and take a look at them doing that right now okay here's our demonstration i've got it set up with device one and device two and you will notice that i'm powering both of my devices using these usb power banks so we are not connected to a computer in any fashion the only connection we're making is through the wi-fi connection on the arduino rp2040 connect boards now i also want you to keep in mind that the only requirement is that both of these devices are connected to a network that connects to the internet now in this case of course they're both connected to my home lan but they could be very well connected to two different networks in two different parts of the world as long as they're both on the internet that should function correctly so as you can see it's basically a push button led on each one i'll hit the push button on device 1 and device 2's led toggles on and if i hit the push button again i can turn it off and the same thing goes with the push button here i can do this and turn on the led on device one and i can toggle it off by pressing it again and so what we've done is we've illustrated that we can control both of these two devices through the arduino iot cloud now remember if you were to do anything such as delete one of the things associated with one of these devices this would stop working because it is making use of the cloud to pass the status information about the two different variables and so this is a great demo it's simplistic but i think you can see a lot of applications for this now in the experiments that we've run so far we've been using arduino compatible boards made by arduino but we don't have to restrict ourselves to arduino boards because the arduino iot cloud also has support for a number of third-party boards including the esp8266 and the esp32 so for this experiment we're going to create a thing using an esp32 for our hookup we'll need an esp32 module and pretty well any esp32 module will do just make certain you have a pin out diagram of your module as it may not be identical to the one that i used we'll also need a potentiometer any linear taper pot of 5k or over will suffice i used a 10k pot we'll need an led i used the yellow one this time but you could use any color you like and a dropping a resistor for that led any value from 150 to 330 ohms should work good i used a 220 ohm resistor we'll begin by connecting the gpio2 output to one side of the resistor and then we'll connect the other side of the resistor to the anode of the led we'll connect the led's cathode to one of the ground terminals on the esp32 module we'll connect the 3.3 volt output of the esp-32 to one side of the potentiometer we'll connect the gpio pin 34 to the wiper of the pot and the other side of the pot will be connected to ground and this completes our wiring so now that we've wired up our esp32 we'll need to create a thing for it so let's create a new thing and we'll give our thing a title and that's a pretty creative title over there and now let's set up variables and the led we're going to use a boolean again because we're just representing whether it's on or whether it's off and it's read and write and we do it on chain so we'll add our variable and there we go and we need a second variable for the potentiometer and for that i think an integer would be a good choice and it needs to be read only we're not going to write to this and we'll set this up here and so now we've got our two variables now we have to add our device our esp32 and that's where things are a bit different than what we've seen before so we'll select device and we'll set up a new device and it's going to be a third-party device and it's an esp32 which you'll notice has a little mark beside it that says it's still an experimental phase and we're going to pick the wr rover because that's the type of esp32 that i have and i'll continue that and we'll give it a name which is good enough over here and now we come to a different part we need to create a secret key and it's been created for us we'll need to keep this key because this key is going to be used in setting up our wi-fi i've just copied that to my clipboard let's just make certain it's there now under normal circumstances you probably shouldn't show the world your secret key but in this particular case it's only for a demo that i'm probably going to take down right after i film it so it's not a problem i've saved my secret key and i can continue and now i'm all set and i have a new device over here the esp32 board and now we go into our network setup and here's where things are a bit different you will notice in the network setup that we have a place for the secret key and so i can paste that secret key that i had before into here and then for the name and ssid it's just as it is before and we'll save that and so now we've got our thing set up let's go and take a look at our sketch that goes with the thing and then we'll build a dashboard to control our esp32 device all right so now that we've constructed our thing let's take a look at the code for the thing and i've opened it up in the full editor so you can see it better i've also entered all the code so you don't have to spend time watching me type it in now of course the thing has created a lot of the code for us and all we need to do is add a couple of extra entries in order to make everything work and the first entries are up here in the declarations it's just some integers we've defined for the two pins we're using the pin for the led on gpio2 and the pin for the potentiometer on pin 34. then we go into the setup and in the setup we need to set the led up as an output since we'll be using gpio pin 34 as an analog input we don't need to do anything with it in this setup then we go into the loop and that is where we use the gpio pin we assign the value of the cloud variable esp32 pot to an analog read of the potentiometer now remember that the esp32 uses a 12 bit a to d converter as opposed to the 10 bit one that you're used to in the arduino uno so we're going to expect values of zero to 4095 for esp32 pod we add a small delay after that to avoid bombarding everything with data so every half a second we'll take a reading over here and then we have the function that the thing has created for us for the led change and this is pretty well identical to what we saw in the first experiment we take a look at the cloud boolean esp32 led if it is true then we send the pin high to turn the led on else we send it off and so that's the code now let's go and build ourselves a dashboard for our project so i'm going to go into the dashboards and i'm going to build a dashboard and we're going to go into edit mode of course and we'll give our dashboard a title how's that and we're gonna add a few things now for the led is what seems to be appropriate as we did before so let's just give it a name and we will link the variables so we'll click the variable and we'll look at the esp32 thing and there's an esp32 led available for us and so we're going to link that variable to it and that is done now let's add something for the potentiometer and there's a number of different things we can choose including some of the ones we've seen before but i'm going to use a value over here and for the value i'm going to again change this to to label it and then i'm going to link my variable and again in the esp32 i'm going to find an esp32 pot variable and i'm going to link that variable to it right now and we've actually got a value in there and we are done right now and here's our dashboard so let's go and do a quick demo of this all right you can see my demonstration hooked up on this breadboard the potentiometer there's a yellow led over here it's a little hard to see because the breadboard itself is kind of yellow and of course the esp32 module and so now if you look on our dashboard we're getting a value for the pot let's go and turn it all the way to one end and we've got a value of 4095 which is what one would expect from a 12-bit analog to digital converter and we'll turn it down to the other end and the values are dropping and they drop all the way down to zero and so we can read our pot values on our dashboard quite easily and now we'll give the switch a try and as we expected the yellow led came on you'll also notice another led came on over here on the module and that's because my esp32 module has a built-in led on gpio2 and a lot of esp32 modules have that so as you can see we can control an esp32 device through the iot cloud using a dashboard all right well this concludes our look at the arduino iot cloud for today and i'll be doing more experiments with the arduino iot cloud in the future and if you want to catch those experiments the best way to do that is to subscribe to the channel and you just need to hit that little subscribe button and when you do also click on the bell notification and as long as you've got notifications enabled in your youtube account you will get notified every time i make a new video now if you want to learn more about the iot cloud or grab some of the code that i use today there is as always an article that accompanies this video on the dronebotworkshop.com website and there's a link to that article right below the video when you're on the website you can sign up for the newsletter if you haven't already and occasionally you'll be getting some email from me it's not sales mail by any means it's just my way of letting you know what is going on here in the workshop and finally if you want to discuss your experiences on the arduino iot cloud the dronebot workshop forums is the place to go and there's a link to the forum below this video so if you haven't signed up yet please go and do that it's free and there's a lot of great people on the forum who can help you out with your projects now of course the arduino iot cloud isn't the only game in town there are other things such as blink that also performs similar functions and may have some advantages over the cloud especially in the number of devices they support and we'll be talking about blink in a future video but until then please take care of yourself please stay safe and we'll see you again very soon here in the dronebot workshop goodbye for now [Music] you
Info
Channel: DroneBot Workshop
Views: 69,803
Rating: 4.9517627 out of 5
Keywords: arduino iot cloud tutorial, arduino tutorial, esp32 tutorial, internet of things
Id: UFCmTZUoZ1M
Channel Id: undefined
Length: 51min 59sec (3119 seconds)
Published: Sun Aug 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.