{"id":237786,"date":"2021-01-07T21:44:37","date_gmt":"2021-01-07T20:44:37","guid":{"rendered":"https:\/\/emariete.com\/?p=237786"},"modified":"2021-01-07T21:44:37","modified_gmt":"2021-01-07T20:44:37","slug":"connect-control-leds-ws2812b-esp8266-espeasy","status":"publish","type":"post","link":"https:\/\/emariete.com\/en\/conectar-controlar-leds-ws2812b-esp8266-espeasy\/","title":{"rendered":"Connecting and controlling WS2812B LEDs to ESP8266 with ESPEasy"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do you want to connect WS2812 LEDs to a <strong>ESP8266 with ESP Easy<\/strong>? In this tutorial I will show you how to do it <strong>easily<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The WS2812 LEDs (<strong>also called NeoPixels<\/strong>) are fantastic and give us incredible possibilities and flexibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The WS2812 <strong>are presented both individually and in strips<\/strong>The RGB strip lights up in one colour at a time, but whereas a normal RGB strip lights up in one colour, in this case we can control each LED independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are LEDs that can be connected in parallel, connecting as many as we want with only three wires. <strong>we can control them one at a time<\/strong>. We can switch some on and others off, set each one to the colour we want and regulate their intensity independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These LEDs are called RGB LEDs because they are <strong>each of them has the three basic colours<\/strong> (red, green and blue). This means that we can achieve many, many colours by combining these three basic colours (including the <strong>white, if we light the three colours together<\/strong> with the same intensity).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, <strong>powered at 5 volts<\/strong>This makes assembly much easier, as no additional power supplies are required. <strong>We can use the same power supply of a NodeMCU or Wemos D1 Min<\/strong>i or put a separate mobile phone charger to power them (or another larger power supply if there are many LEDs).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just one thing to keep in mind: each colour of each LED, switched on at 100%, consumes 20mA. Each LED has three colours. This means that <strong>one LED can consume 60mA<\/strong> if we turn on all three colours at full power at the same time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we put a strip of 10 WS2812 LEDs it will consume a maximum of 600mA. <strong>Keep this in mind when thinking about the feeder you will use.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mobile phone power supplies usually provide between 500 and 2000mA, check how much is yours and <strong>calculate how many LEDs you can connect<\/strong> to your feeder so as not to exceed its capacity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At the end of this article you have a video tutorial with <strong>specific and detailed instructions for connection and configuration of LEDs<\/strong>. Although the video is very good for the practical part, I recommend that you first read the article because it has <strong>a lot of information<\/strong> that will help you to get the most out of your LEDs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-diagrama-con-las-conexiones-del-nodemcu-a-los-leds-ws2812-neopixel\">Diagram with connections from NodeMCU to WS2812 LEDs (Neopixel)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As I said, the connection couldn't be easier. <strong>Just three cables and you're off and running!<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this example I have used three WS2812B LEDs, but one of the great advantages of this type of LED is that you can use as many as you want. <strong>However, be aware of the power consumption, each LED can consume up to 60 mA.<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp-1024x576.png\" alt=\"\" class=\"wp-image-237165\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp-1024x576.png 1024w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp-300x169.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp-768x432.png 768w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/NodeMCU-WS2812_bb-transp.png 1080w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-configuraci-n-espeasy\">ESPEasy configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have made the connections, you have to <strong>configure ESPEasy<\/strong> to recognise the devices and <strong>include a few simple rules<\/strong> to behave the way we want them to behave.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>I'll give you the example of the <a href=\"https:\/\/emariete.com\/en\/carbon-gas-co2-meter\/\">eMariete's homemade CO\u2082 meter<\/a>but you can use it in exactly the same way with any other project.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, we will have to do the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Activating the ESPEasy rules engine<\/li><li>Add a rule so that when the ESP8266 is switched on, it is switched on with the LEDs off.<\/li><li>Add a rule to change the colour of the LEDS depending on the CO2 level.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You do not need to register the LEDs as a device in the \"Devices\" tab.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-activar-el-motor-de-reglas-de-espeasy\">Activating the ESPEasy rules engine<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The first thing you should do is&nbsp;<strong>activate the ESPEasy rules engine<\/strong>if you have not already done so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, go to the \"<em><strong>Tools<\/strong><\/em>(Tools) and click on the button \" \".<em><strong>Advanced<\/strong><\/em>\"(Advanced):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Configuracion-Avanzada-ESPEasy.png\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"620\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Configuracion-Avanzada-ESPEasy.png\" alt=\"\" class=\"wp-image-237091\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Configuracion-Avanzada-ESPEasy.png 859w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Configuracion-Avanzada-ESPEasy-300x217.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Configuracion-Avanzada-ESPEasy-768x554.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The ESPEasy advanced configuration options window will open.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There you have to activate the options \"<em><strong>Rules<\/strong><\/em>\"(Rules) and \"<em><strong>Old Engine<\/strong><\/em>\"(Old Engine):<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Habilitar-Reglas-ESPEasy.png\"><img loading=\"lazy\" decoding=\"async\" width=\"876\" height=\"313\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Habilitar-Reglas-ESPEasy.png\" alt=\"\" class=\"wp-image-237092\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Habilitar-Reglas-ESPEasy.png 876w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Habilitar-Reglas-ESPEasy-300x107.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Habilitar-Reglas-ESPEasy-768x274.png 768w\" sizes=\"auto, (max-width: 876px) 100vw, 876px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-adir-una-regla-para-que-cuando-se-encienda-lo-haga-con-los-leds-apagados\">Add a rule so that when it is switched on, the LEDs are switched off.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now you have to write the rules, <strong>in the \"Rules\" tab<\/strong> (Rules). This tab will not appear until you enable the rules engine, as you have seen in the previous point:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Editar-Reglas-ESPEasy.png\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"742\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Editar-Reglas-ESPEasy.png\" alt=\"\" class=\"wp-image-237093\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Editar-Reglas-ESPEasy.png 815w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Editar-Reglas-ESPEasy-300x273.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2020\/12\/Editar-Reglas-ESPEasy-768x699.png 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the rules editor that appears in ESPEasy, you write the following rules<strong>&nbsp;(I recommend you copy and paste, to avoid mistakes and leave comments - lines starting with \/\/ - which ESPEasy will ignore).<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will need to&nbsp;<strong>replace Senseair#PPM with the device name and value you have chosen<\/strong>&nbsp;(in the \"Devices\" tab). In this screenshot the device name is CO2, so instead of Senseair#PPM we would write CO2#PPM:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Devices-Senseair.png\"><img loading=\"lazy\" decoding=\"async\" width=\"968\" height=\"525\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Devices-Senseair.png\" alt=\"\" class=\"wp-image-237173\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Devices-Senseair.png 968w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Devices-Senseair-300x163.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Devices-Senseair-768x417.png 768w\" sizes=\"auto, (max-width: 968px) 100vw, 968px\" \/><\/a><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">On System#Boot do\n  NeoPixelAll,0,0,0,0 \/\/ LEDS OFF\nEndOn<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The NeoPixelAll,0,0,0 line instructs ESPEasy to <strong>turn off all LEDS<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What this line really tells you is to put the <strong>Red to 0<\/strong>the <strong>Green to 0<\/strong> and the <strong>Blue to 0<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As the line is <em>NeoPixelAll,0,0,0,0<\/em> between \"<em>a block<\/em>\"formed by the line <strong>On System#Boot do<\/strong> y <strong>EndOn<\/strong>, <strong>we tell ESPEasy to run it when the NodeMCU starts up<\/strong> (anything you put inside that block will be run <strong>each time<\/strong> the NodeMCU is switched on).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-adir-una-regla-para-que-cambie-el-color-de-los-leds-dependiendo-del-nivel-de-co2\">Add a rule to change the colour of the LEDS depending on the CO2 level.<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now add this other block to the rules:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">On SenseairCO2#PPM do\n  if [SenseairCO2#PPM]&gt;2000\n    NeoPixelAll,32,0,0,0 \/\/ RED LEDS\n  do if [SenseairCO2#PPM] &gt; 1500\n    NeoPixelAll,16,9,0 \/\/ ORANGE LEDS\n  Else\n    NeoPixelAll,0,32,0 \/\/ GREEN LEDS\n  Endif\nendon<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This block instructs ESPEasy to <strong>each time it receives a new value <\/strong>from the SenseairCO2 sensor (<em>On SenseairCO2#PPM do<\/em>), check the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if the value of SenseairCO2#PPM is greater than 2000 and, <strong>if so<\/strong>If the LEDs in the strip are not on, turn on all the LEDs in the strip with the following values: <strong>Red at 32<\/strong>the <strong>Green to 0<\/strong> and the <strong>Blue to 0<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>if not complied with<\/strong> the above (that the value of SenseairCO2#PPM is greater than <strong>2000<\/strong>), it will check if the value is greater than 1500 and, if it is met, turn on all LEDs in the strip with the following values: <strong>Red to 16<\/strong>the <strong>Green to 9<\/strong> and the <strong>Blue to 0<\/strong> (a yellow\/orange).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>if not complied with<\/strong> the above (that the value of SenseairCO2#PPM is greater than <strong>1500<\/strong>), and without further checks, it will light all the LEDs in the strip with the following values: <strong>Red a <\/strong>0, the <strong>Green to 32<\/strong> and the <strong>Blue to 0<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the line <em>endon <\/em>ends the block of checks that started with <em>On SenseairCO2#PPM do<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The final result<\/strong>should be similar to this one:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Reglas.png\"><img loading=\"lazy\" decoding=\"async\" width=\"914\" height=\"756\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Reglas.png\" alt=\"\" class=\"wp-image-237174\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Reglas.png 914w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Reglas-300x248.png 300w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/01\/ESPEasy-Reglas-768x635.png 768w\" sizes=\"auto, (max-width: 914px) 100vw, 914px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"gb-headline gb-headline-564984b9 gb-headline-text\">Control the switching on and off of the LEDs with a switch and have them flash on and off at certain times and that, and that, and that, and that....<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The possibilities of the ESP-Easy rules are enormous, and <strong>allow us to do almost anything<\/strong>\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What if you wanted the LEDs to be switched on at the same time? <strong>flashing <\/strong>and that they were also <strong>switched off between certain hours<\/strong>for example, so that they do not disturb, and furthermore <strong>control with a switch (or a push button) whether or not to turn them on or off.<\/strong> (bonus: and that in addition <strong>if we have an OLED screen connected, it will also switch off.<\/strong>?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We could use this variation of the rules from the previous point in which we would include some timers to create the intermittency and some extra checks of the hours and a Switch that we would connect (between pin D7 and GND, in this case):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>On Rules#Timer=1 do\n  if [Switch#State]=1 and [var#1]=0 \/\/ If the switch is on and it is not sleep time\n    if [co2#co2]&gt;1000\n      NeoPixelAll,32,0,0,0 \/\/ RED LEDS\n    if [co2#co2]&gt;750\n      NeoPixelAll,16,9,0 \/\/ LEDS ORANGE\n    Elseif [co2#co2]&gt;400\n      NeoPixelAll,0,32,0 \/\/ GREEN LEDS\n    Else\n      NeoPixelAll,0,0,0,0 \/\/ OFF LEDS\n    Endif\n  Endif\n  looptimerset_ms,2,100 \/\/on 100ms every 2 secs\nEndon\n\nOn rules#Timer=2 do\n  NeoPixelAll,0,0,0,0 \/\/led off\n  looptimerset_ms,2,0\n  timerset,1,2\nendon\n\nOn System#Boot do\n  NeoPixelAll,0,0,0,0 \/\/ LEDS OFF!\n  Let,1,0 \/\/ If set to 1 = sleep time, LEDs off!\n  timerSet,1,2 \/\/ change the 2 to 60sec and the LEDs will turn on with the first measurement\nEndOn\n\non Switch#State do\n  if [Switch#State]=0\n    oledframedcmd,display,off\n    NeoPixelAll,0,0,0,0 \/\/ OFF LEDs\n  else\n    oledframedcmd,display,on\n    Let,1,0,0 \/\/ If 0 = no sleep time, LEDs on!\n  endif\nendon\n\n\non Clock#Time=All,22:00 do\n  Let,1,1 \/\/ If set to 1 = bedtime, leds off!\n  NeoPixelAll,0,0,0,0\n  oledframedcmd,display,off\nendon\n\non Clock#Time=All,08:00 do\n  Let,1,0 \/\/ If 0 = no sleep time, leds on!\n  oledframedcmd,display,on\nendon<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the LEDs and OLED display would remain off every day from 22:00 to 08:00.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can \"<em>cancel<\/em>\" that <em>SLEEP TIME<\/em> switching off and on again from the switch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All you have to do is connect the switch (on pin D7 in this example, although you could use other pins), add it as a new device of type \"Switch\":<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Add-Device-Switch.png\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"446\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Add-Device-Switch.png\" alt=\"\" class=\"wp-image-238452\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Add-Device-Switch.png 744w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Add-Device-Switch-300x180.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">and configure it:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP-Easy-Device-Switch.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"836\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP-Easy-Device-Switch.jpg\" alt=\"\" class=\"wp-image-238451\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP-Easy-Device-Switch.jpg 787w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP-Easy-Device-Switch-282x300.jpg 282w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP-Easy-Device-Switch-768x816.jpg 768w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer, you can use a push button instead of a switch. You would only have to change the type of button and say that it is a low-level active push button (which is activated when pin D7 is tied to GND):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Switch-Button-Type.png\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"88\" src=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Switch-Button-Type.png\" alt=\"\" class=\"wp-image-238453\" srcset=\"https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Switch-Button-Type.png 602w, https:\/\/emariete.com\/wp-content\/uploads\/2021\/05\/ESP_Easy-Switch-Button-Type-300x44.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Many <strong>thanks to user Joselu70 <\/strong>for participating in the development of these rules \ud83d\ude09.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-adir-una-regla-para-hacer-un-sem-foro-de-leds\">Adding a ruler to make an LED traffic light<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With the WS2812 LEDs it is possible to create, for example, a <strong>traffic light effect<\/strong>in which, with <strong>a three LED strip<\/strong>The first LED of the strip, placed vertically, can be switched on at <strong>green<\/strong>the second in <strong>orange <\/strong>and the <strong>third <\/strong>in red, depending on the CO2 level or any other value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command to send for <strong>switch on a specific LED <\/strong>of the strip is:<em> <\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>NeoPixel, NumeroLed, RedQuantity, <em>Quantity<\/em>DeVerde, <em>Quantity<\/em>DeAzul<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Being <em>NumeroLed<\/em> the position of the LED we want to control in the strip, and the amount of red, green and blue in the strip. <strong>number between 0 (off) and 255 (on at 100% intensity)<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For <strong>the first LED lights red<\/strong> (at 50% intensity, for example, as 100% is too strong for my taste) we would use the command: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>NeoPixel,1,128,0,0,0<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For <strong>the second LED lights up amber<\/strong> (at 50% intensity), we could do this by adding a 25% of red plus a 12% of green. To achieve this we would use the command: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>NeoPixel,2,64,32,0<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For <strong>the third LED lights up green<\/strong> (at 50% intensity), we would use the command: <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>NeoPixel,3,0,0,64,0<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The rule <\/strong>we should include would be this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">On SenseairCO2#PPM do\n  if [SenseairCO2#PPM]&gt;900\n    NeoPixelAll,0,0,0 \/\/ TURN OFF THE LEDs\n    NeoPixel,1,128,0,0,0 \/\/ TURN ON THE FIRST LED IN RED\n  Elseif [SenseairCO2#PPM] &gt; 800\n    NeoPixelAll,0,0,0,0 \/\/ TURN OFF THE LEDs\n    <em>NeoPixel,2,64,32,0<\/em> \/\/ WE TURN THE SECOND LED ORANGE\n  Else\n    NeoPixelAll,0,0,0,0 \/\/ WE TURN OFF THE LEDs\n    <em>NeoPixel,3,0,0,64,0<\/em> \/\/ WE TURN THE THIRD LED GREEN\n  Endif\nendon<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I have chosen the CO2 levels so that the traffic light will turn red when 900 ppm is exceeded (<strong>in accordance with RITE IDA 2 for classrooms, suitable for school classrooms<\/strong>). Feel free to replace the 900 and 700 values with the ones that suit you best.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on which <strong>distance <\/strong>and the brightness of the room, you can adjust the intensity of the LEDs (one of these LEDs switched on to the maximum value of 255, you will see the LEDs in the room). <strong>much<\/strong>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you will see before turning on each LED <strong>first we switch off the entire strip<\/strong>using the command <em>NeoPixelAll,0,0,0,0<\/em> because, if we did not do so, when changing colour (e.g. from green to orange), both LEDs would remain lit.<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img decoding=\"async\" src=\"https:\/\/ae01.alicdn.com\/kf\/HTB1RjX0adfvK1RjSspfq6zzXFXa3.jpg_350x350.jpg\" alt=\"\"\/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"has-normal-font-size wp-block-paragraph\">This type of LEDS is<strong> perfect for making traffic lights and other indicators<\/strong>. Better than strips because <strong>can be used together or can be separated individually<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Much better than LED strips, which give much less flexibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/s.click.aliexpress.com\/e\/_AkZSYj\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Click on the image or here to see where I buy them.<\/a>.<\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-video-tutorial-paso-a-paso\">Step-by-step video tutorial<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Although the assembly and configuration is very simple, in the following video you have <strong>specific and detailed instructions for connection and configuration of LEDs<\/strong> from minute 21:35 onwards.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In it you will find <strong>explanations, details and tips of all kinds<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Press play and <strong>go to minute 21:35<\/strong>which is where the detailed explanation of LEDs begins.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"3D Printed Box for our Home CO2 Meter with Wifi\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/foqyzhyPn8I?start=1295&#038;feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n<div class=\"essb_break_scroll\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Easily connect and control LEDs with your ESP8266 with ESP Easy.<\/p>","protected":false},"author":1,"featured_media":237788,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","_lmt_disableupdate":"yes","_lmt_disable":"no","footnotes":""},"categories":[12,16,17],"tags":[26,28,41],"class_list":["post-237786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-co2-easy","category-medidor-co2","category-proyectos-arduino","tag-espeasy","tag-esp8266","tag-nodemcu"],"modified_by":"Mariete","uagb_featured_image_src":{"full":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy.png",1080,608,false],"thumbnail":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy-150x150.png",150,150,true],"medium":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy-300x169.png",300,169,true],"medium_large":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy-768x432.png",768,432,true],"large":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy-1024x576.png",1024,576,true],"1536x1536":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy.png",1080,608,false],"2048x2048":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy.png",1080,608,false],"trp-custom-language-flag":["https:\/\/emariete.com\/wp-content\/uploads\/2021\/02\/NeoPixel-WS2812-ESPEasy.png",18,10,false]},"uagb_author_info":{"display_name":"Mariete","author_link":"https:\/\/emariete.com\/en\/author\/admin_xlyz052h\/"},"uagb_comment_info":0,"uagb_excerpt":"Conecta y controla LEDs con tu ESP8266 con ESP Easy f\u00e1cilmente.","_links":{"self":[{"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/posts\/237786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/comments?post=237786"}],"version-history":[{"count":0,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/posts\/237786\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/media\/237788"}],"wp:attachment":[{"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/media?parent=237786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/categories?post=237786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emariete.com\/en\/wp-json\/wp\/v2\/tags?post=237786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}