Welcome to Zeroohm Arduino Training series. In this series of Arduino Training, Zeroohm will focus its efforts on helping the community learn more about Arduino fundamentals and basics starting with basic control of LED's, motors, sensors and utilizing of wirless communication. We hope that you find this useful, Please, leave a comment for any questions or comments or reviews!
We provide all our trainings for groups from schools, universities, public sector and private sector in Abu Dhabi, Dubai, Sharjah, Fujirah, RAK or anywhere in UAE. Please,click here to contact us directly for any training inquires.
We will make LED (On and Off) by using the NodeMCU chip, then we will explain the programming commands. Before starting this lesson, and going through the first project of Internet of Things (IoT), we will take a look on the NodeMCU chip.
NodeMCU Mini is an ESP8266 WiFi micro controller that works at 80MHz and at 3.3V logic. This microcontroller contains a Tensilica chip core as well as a full WiFi stack. You can program the microcontroller using the Arduino IDE for an easy-to-run Internet of Things core or using the Lua script language. We have ship with NodeMCU 0.9.5 build 20150704 and powered by Lua 5.1.4, so we can use the Lua language directly to DIY the IOT project. We wired up a high-quality SiLabs CP2104 USB-Serial chip that can upload code at a blistering 921600 baud for fast development time. It also has auto-reset, so no noodling with pins and reset button pressings are needed.
Now we will divide the first project for two parts: the first part will be LED (on and off) and the second part will be the same project but with PWM property.
Now let’s have a look at the hardware overview of the entire circuit shown in the image. Connect them as shown in Figure 1:
We also connect the ( LED ) at pin (D4 ) from NodeMCU board like as shown in Figure 1.
The Code and explanation:
Copy this code to your ESPlorer software and save it with " ESPlorer_LED" name or any other name (no problem at this point), then upload the code.
if x==0 then
We note that the time function has 4 arguments:
-The first argument (0) refers to the number of the function and it takes one number from 0 to 6 and arrangement is not required.
-The second argument (1000): refers to the time period in m/s unit.
-The third argument (1): It should take one of two values 0 or 1. 1 means that the command will execute every (1000 m/s), but if it takes 0 value this means that it executes one time after (1000 m/s) without repeating.
-Fourth argument (function): It refers to the command that will execute it. In our example, the command that will be executed is: (Hello World) statement.
tmr.alarm( 0, 2000, 1, function()
print( "green" )
tmr.alarm( 4 ,5000 ,0, function()
print( "black" )
tmr.alarm( 2, 300, 1, function()
print( "white" )
- The first time function has 0 specific number which means that it will show (Green) statement every 2 seconds.
- The second time function has 4 specific numbers which means that it will show (Black) after 5 seconds once without repeating.
- The third time function has 2 specific numbers which means that it will show (White) every 300m/s continuously.
To run the program that was saved at ESP8266 properly, it is preferable to name all the files with (.init.lua) and save each code file at a new folder with same name of our project.
Let's have a look at Figure 2 which explains the steps:
Figure 2. The proper way to name the files in the ESP8266.
Part II (ON/OFF LED with PWM property):
Connect the circuit as shown in Figure 3:
Copy this code to your ESPlorer software again and save it as " ESPlorer_LED". or any other name. Next, upload the code, or do similar to the steps in the previous note regarding naming a file.
for x=0,2,1 do
for c=0,1023,1 do
for c=1023,0,-1 do
-The first argument (led) refers to the pin that we will use it to execute the PWM property. In our project we use pin (D4) to refer for led.
-The second argument (1000) refers to the frequency of the PWM. The possible value that will take it is only from 0 to 1000.
-The third argument (0) refers to the duty cycle value. The possible value that can take is from 0 to 1023. Those values control the lighting strongly.
for x=0, 9, 1 do
print( "Arabic" )
- The first argument value refers to the initial value of the (for function).
- The second argument value refers to the final value of the (for function). The function will stop here.
- The third argument value indicates the amount of increase after every for loop.
We hope that you have enjoyed this project. Also we hope that it was beneficial.