ESP32 Tutorial 47 - WS2812 CheerLights using MQTT over Internet | SunFounder's ESP32 IoT kit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we can select a different color red. Hi. welcome  to video tutorial from Robojax in this video we   are going to have a Cher light using esp32  from SunFounder so this led the color can be   changed remotely from anywhere in the world  by other people and you can have this with   a battery connected somewhere in your room and  you don't feel alone as is connected via Wi-Fi   to the global Network this light will change  simultaneously for all subscribers and you feel   connected esp32 starter kit from SunFounder this  is the best esp32 learning kit from SunFounder it   has this esp32 microcontroller which has built in  Wi-Fi and Bluetooth this board can do everything   Arduino Uno can do or many other Arduinos can do  plus extra more features because we have Wi-Fi and   Bluetooth the possibilities are endless you can  get connected to the cloud or do the control or   read information or values via your mobile device  or your desktop or over the cloud from a far location it comes with a camera extension  kit where you can stream the video over   Wi-Fi either through the cloud or to your  network and also it comes with micro SD   card where can save images on the micro SD  card or you can write from the device any   information log the information on the device  and read it back you can power the board using   this included 18650 lithium battery and it has  built in charger where you can connect micro USB   and charge the battery the kit comes with 320  pieces of component that you can learn tons of projects this esp32 has built in Wi-Fi and  Bluetooth so we can get connected to the   internet and one of the feature of the internet  is M uh mqtt and where instruction goes and waits   somewhere and we can just subscribe to a certain  list or a job or a feed and then we can pull it up   that feed could be a text or information but uh  in this case the feed name would be Cher up and   so the feed has a name and then we have a text  or a value the value would be the value of color   and we will use our subscription to pull that  information from that feed which will tell us the   color should be red green or blue and other users  can change the color and when once they change   the color we will see the color reflect here and  all subscribers will get the same colors so we   are going to use esp32 as you can see I've just  connected it with the battery this beautifully   you can just maybe print a 3D print box for this  so it will be very nice and place it somewhere   and just allow this portion so you could connect  it via box just leave a hole for this micro USB   connector so you can connect it and charge your  battery and this light as you can see right now   somebody changed it from Green from red to uh this  white color and you will not feel alone and you   have connection with um all other people around  the world that are using the same CheerAlights applied come to this page docs.SunFounder.com then click on esp32 starter C kit main on the   left side click on Arduino user scroll down until  you see 8.5 cheerLights so this is a documentation   page where we are synchronizing the so the  cheerLights is a Global Network of synchronized   lights so they will be turned on and off all  together and to join the CheerLights group and in Discord we need our esp32 board with esp32  extension board jumper wires and our WS 2812   LED lights which we already familiar with  this code also needs installing Library   which I'm going to show you I'm going  to show you also the wiring and here is   a code I'm going to explain the code to you  then there's some explanation and to connect   with a global CheerLights applied device  we will go to this Discord server now let   me click on this here it says 43 people are  online and 562 members let's have a display name it Sunfounder are you a human yes here before even sending or doing  anything we are here on this page that   was asked to install the app which I did  not install but we have to verify our email I got this email to verify the email and let's connect click to continue when you use esp32 with SunFounder esp32 camera  extension module like this it comes also with a   battery on the package and it comes a built-in  charger so you can connect it and charge it and   disconnect and later on you can use it with a lot  of power so you can power up your application very   easily WF uh 2812 we are connecting pen one  to the ground and VCC to 5 Vols the red and   uh black and then the yellow or data to pen 14  as it's shown here let me show you here so we   have three wires the red is connected to 5 Vols  black is connected to the ground you can also   connect it here I've left this 5 volts for LCD and  then the yellow is connected to 14 as mentioned here I'm opening Arduino IDE let's open our project by clicking  on file open on the left side click on   downloads then esp32 stter kit main on the  right side double click to open it double   click on C double click on codes and scroll down  to iot 5 Cher app lights double click select and open this is our code so we need to install this   public client right click and copy it  let's go to the library right click   and paste it let's see if we can find it  and the one which says by neck or click install so the library was installed  we need also add a fruit new pixel   we have already installed it  in previous lesson but let's check new pixel add fruit here add a fruit new  pixel this is the one install and it says it has the following dependencies if  you want to use it for other uh purpose tiny USB   and all this will be available you can select  install all or without dependencies like let's   install it without dependency so the library is  installed and this is a header for Wi-Fi and this   was public client which we just installed at  a root for RGB LED for ws2812 and let's type   here your WiFi SS ID for example if your Wi-Fi is  book uh if you type capital B it will not work so   it's case sensitive and then type your password  this is a mqtt server that is holding the cherup   light and this is a unique identifier here it  says and these are the colors that have been   defined as color name of type string up to here  and we have these RGB colors combination of these   uh colors red pink green so this is R this is G  this is B I've already explained it and then RGB   LED we're connecting it to pin 13 8 is the eight  is the number of LED that we have and then from   add FR new pixel we are creating an object and  then passing all the values to it initializing   the serial monitor initialize the serial monitor  set up the Wi-Fi this is a function which is at   the bottom of the code and let me show you setup  Wi-Fi comes here 10 seconds uh 10 milliseconds   delay and print this and connect it to SSID it  prints the SSID name and this is initializing   the Wi-Fi and and making the connection this y  Loop is checking if the connection is not there   we will print continue it will print continuous  dots and this will once it's connected it will   print the IP on the serial monitor now we can  we come back here and it goes to the client   and goes to mqtt server of Port 1883 to pull up  the data and then it goes to set call back now now and we have a callback uh function here which   uh checks the message for us uh  this is part of this public client Library so this will check the um text it  will check the message and see what it is   and it sends whatever the character  that we receive on the serial Monitor   and also gets the character and uh sets  it as a temporary message and print Ln now if now it checks it if it if the topic is  equal Cher lights then it prints this message   on the screen the text and actual message whatever  it was it will be printed on the screen now here   is the thing this message will go to set color  this is a function let me show you set color   set color is here so the message that is received  either red green or blue it will come here and we   have a for Loop inside this for Loop we have  a function and we have another for Loop this   for Loop looks at the index we we're defining  a variable called index color of zero and it   checks if index color is smaller than 12 then  it will increment it because it's 0 1 2 3 it   goes up to 11 and then we check if the color  that we receive so we check this index color   it goes inside this color name this is an array  let me go back here color name so the color that   we have which should be one of these and these  have been indexed this is position 0 1 2 3 and so for so this number index color become one 2 3  and it goes inside this array and pulls up the   color if the color exists for example it might  be some random color not not readable it will   be ignored if it is available this check checks  if it is available then we use this for Loop to   set the color for all the pixels so it goes  from zero to number of LEDs one smaller than   number of LEDs which is eight so we go from 0  to 7 and increment and set the pixel which we   learned about this in the uh previous in the  lesson that we talked about this uh LED and   it says the set the color and displays it now  was set up Wi-Fi we talked about the Callback   the call back that reads the message and print  everything and then here this is called reconnect,   reconnect is for the case when the uh Wi-Fi  is not connected or power is disrupted so   you can power up and reconnect back to Wii  this was the set color which I explained   and inside the loop it checks if client  is not connected this means not it runs   the reconnect and then it says client Loop it  goes to the client Loop which is part of the library now let's see how we can select the esp32  board we can click here under the select board and   type here esp32 D as soon as you type Dev you  will see Dev board you can select it and click   okay so the board have been selected now we have  to select the port the other way to select the   board is Click On Tools board esp32 and select  the esp32 dev module now we have to select the   port if I click here it shows two port and I don't  know which one belongs to my device sometimes you   will see you will not see the number properly  so the best way to be sure the right click on   the start menu go to the device manager and you  will see here the ports if I click on this Arrow   it will show me the ports one is USB serial  ch340 one the other is USB serial device and   here now it's connected if I disconnect this one  of them disappear the one that disappeared is my board so six stays and it disappeared if I connect it so it is my comport ch340 now it is my  comport port and I can select it or I can   click on tool port and here you will see it you  can select whichever you want ours is come it now   we have successfully selected the board and the  port and this is very important it must be done first and here is the demonstration  now let me open the serial monitor now now there is nothing as  you can see and we have to be able   to send the text or some information so  the color is changed and this is working so uh just put forward slash and then cheerLights like this just type it and after  that press enter once you press enter you can   have get color and set color let me show  you right now as you can see let me turn   off the light so you can see the color it is  my color and this this color is now global I   missed the opportunity so we can say get color  and it says red the color the current color is   R everybody can see it and if I want to set  color click here and we will see the color   and let's say cion I'm clicking and the color  of my L and all other subscribers across the   globe has changed now and on the same time  on the serial monitor it says message cion   so this text was the text that we have  received here let me show you the color so you can see both of these together message arrived on topic and here it says message arrived on topic is is this one and  then chare applied message so the topic first it   prints the topic which is Cher applies and then  dot this Dot and then message and the message   and after that we get the text cion so serial  print character message so this is printing   this icon and then we go to this and here is  changing color to and then again the message   so we got this message that was printed on this  serial monitor is set now to the message temp   and it is printed in here cheer light on this  cord and serial monitor is open at the moment   the color is green and when once I enter here it  gives me these two options I'm just repeating it   this time with a Serial monitor so if I press get  color it will get me the latest color which I set   uh but I don't know it might change immediately by  somebody else but let's set color and let's select   magenta and the color has changed to magenta  and also as you can see uh the serial monitor   is connected and show the color uh because this  e the USB is at the moment the USB is connected   of course if you can run it without USB but  the serial monitor Works only when USB is connected my battery is there and it's working my that
Info
Channel: Robojax
Views: 868
Rating: undefined out of 5
Keywords: robojax, sun, founder, sunfounder, course, tutorial, kit, learn, learning, step by step, esp32, arduino, iot, wifi, mqtt, cheerLights, community, world, feel, code, wiring, connect, PubSubClient, Adafruit_NeoPixel, Broker
Id: DFznGiD61g4
Channel Id: undefined
Length: 21min 11sec (1271 seconds)
Published: Sun Dec 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.