Embedded IOT LAB MANUAL - FOR MECH
Embedded IOT LAB MANUAL - FOR MECH
LAB MANUAL(R-XX)
Prepared by
XXXXXXXXX
Associate Professor
List of Experiments
To program the Arduino we need an Integrated Development Environment (IDE) called “Arduino”.
This is an official and open source IDE introduced byArduino.cc and it is used for writing,
compiling and uploading the code to an Arduino. In this article I will discuss on the detailed
introduction to Arduino IDE. Where I will uncover all the parts of its interface and how to use it.
First we have to download and install this IDE. Here is the Download link –
https://www.arduino.cc/en/main/software. Arduino IDE is available for Windows, MAC, Linux,
Linux ARM (Raspberry PI). After download, install it and you are done. Now let’s explore this
IDE.
As mentioned earlier this is an open source IDE which makes the coding very easy that even a
common person with no high technical knowledge can make codes for it. This IDE is available for
Windows, MAC, Linux operating systems and it runs on the JAVA platform. It is based on
“Processing” programming environment and comes with many inbuilt functions and command
which makes the software very easy to use.
At the top name of the sketch and version of Arduino is displayed. Then we have the Menu bar just
below that. In the menu bar we have five options. Let’s see them one by one.
1. File
In this menu we have these options.
2. Edit
This section is used for editing the code text such as copy, paste, select all, find, copy as HTML etc.
3. Sketch
This is used for compiling, uploading, exporting the compiled code as binary file, to see the sketch
folder.
4. Tools
This is mainly used to select the Arduino type and port, burning bootloader to the new
microcontroller. There are also some other option are available whichare serial monitor and serial
plotter. More of that is explained later.
5. Help
This is help desk of the software.
Short-cut Buttons In Arduino IDE
There are some important shortcut buttons are also available just under the menu bar. Which are
verify (compile), upload, new, open, save and serialmonitor.
Verify
Button with right check mark is for verify the code we have just written. If we written the code
without any logical or syntax or any errors, it will compilesuccessfully. Just in case we have written
something wrong, it will give an error message in output pane about what and where the error is.
Shortcut key forverify is “CTRL+R”.
Here is the code and output serial data. First we have initiated the serial communication by using
Serial.begin command and giving it the baud rate. Baudrate is the rate at which data is transmitted
or received. We can choose other baud rates also which are valid and the other device is compatible
with.
Then we have printed the two string using Serial.println() command and given one second delay
between them. This printing process will run infinitely till Arduino is powered because we have put
the code in “void loop” function.
You can include only those libraries which are available in your Ardiuno’s “Library” folder.
If any library is not present in your library folder then you can add it by downloading it from
internet. Or you can do it within your Arduino IDE by going to Tool>Manage Library and search
the library name and click install.Shortcut for library manager is “CTRL+SHIFT+I”.
Click on the Icon to open the Arduino window as shown in the figure
Open the File and click on the Preferences as shown in the figure
Now open the tools in that select Board: “Arduino/Genuino Uno” and click on the Boards
Manager as shown in the figure
The Boards Manager window opens, scroll the window page to bottom till you see the module
with the name ESP8266. Once we get it, select that module and select version and click on the
Install button. When it is installed it shows Installed in the module as shown in the figure and then
close the window.
To run the esp8266 with Arduino we have to select the Board: “Arduino/Genuino Uno” and then
change it to NodeMCU 1.0 (ESP-12E Module) or other esp8266 modules depending on what you
have .This can be done by scrolling down, as shown in the figure
Now Let’s connect the ESP8266 module to your computer through USB cable as shown in the
figure. When module is connected to the USB, COM port is detected eg: here COM5 is shown in the
figure.
The Blink example will open on a new window , click on tools to select the port: “COM” based on
which esp8266 module is connected to your respected COM port of the computer. To select COM
port refer previous steps.
In case you need to add the libraries to the Arduino follow the example path is shown in the figure
i.e C:\Users\Armtronix\Documents\Arduino\libraries. Enter into the libraries folder then paste the
file in that as shown.
The wake pin is used to wake up the chip from deep sleep mode.
The code reads the analog value from the LM35 connected to the A0 pin of the NodeMCU
board. Then it converts the analog value to voltage using the formula: voltage = sensorValue * (3.3 /
1023.0). Finally, it converts the voltage to temperature using the formula: temperature = (voltage -
0.5) * 100. The calculated temperature is then sent to the serial port and displayed on the serial
monitor.
Procedure:
1. Connect the LM35 to the NodeMCU board:
Connect the VCC pin of the LM35 to the 3.3V pin of the NodeMCU.
Connect the GND pin of the LM35 to the GND pin of the NodeMCU.
Connect the OUT pin of the LM35 to one of the Analog pins of the NodeMCU (for
example, A0).
2. Upload the code to the NodeMCU board using the Arduino IDE:
3. Make sure to open the serial monitor to see the temperature values.
4. You may also want to adjust the formula for converting voltage to temperature according to the
specific model of LM35 you are using.
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
Output :
Result: The measured Analog Signal from Temperature Sensor is displayed in serial monitor.
Program:
const int ledPin = D2;
void setup() {
void loop() {
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle < 255; dutyCycle++)
{
// changing the LED brightness with PWM
analogWrite(ledPin, dutyCycle);
delay(1);
}
1. To generate a single character on a hyperterminal using Node MCU, you can use the
Serial.write() function. The Serial.begin() function should also be used to initialize the serial
communication at a specific baud rate.
2. You also want to make sure that the board is connected to the computer via USB and the Serial
monitor is open on the computer, or a Serial Terminal software is connected to the board.
3. This code initializes the serial communication with a baud rate of 9600 in the setup function. In
the loop function, it uses the Serial.write() function to send the ASCII value of the character "A"
(which is 65) to the serial port. The delay function is used to wait for 1 second before sending
the character again.
4. Note that you need to upload this code to the Node MCU board and open the HyperTerminal
with the same baud rate (9600) and the same serial port that you are connected to the board.
Once you upload the code, you should see the character "A" repeating on the HyperTerminal
every second.
Procedure:
1. Open Arduino IDE software.
2. Now write the program in Sketch area in Arduino.
3. Save the program and click on the verify button.
4. Now connect the Node MCU to the host computer. Verify the COM port in Tools
menu.
5. Select the board as ESP8266 Node MCU in tools options. Now click on verify
button wait to Complete the compilation process.
6. Now click on upload button wait to Complete the uploading process.
7. Check the ouput in serial monitor.
Program:
void setup() {
Output :
Result: A single character is generated using Node MCU and output is displayed in
serial monitor.
void setup() {
Serial.begin(9600); // start serial communication at 9600 baud
}
void loop() {
Serial.print("Hello World "); // send "Hello World" over the serial connection
}
Theory:
1. To drive a given string on Hyper Terminal, you can use the built-in Serial.print() or
Serial.println() function in the Arduino IDE.
2. You can use the Serial.print() function to send a string "Hello World" over the serial
connection.
3. The Serial.begin(9600) function sets the baud rate at which the data is transmitted over the
serial connection, in this case 9600 baud.
4. You can use a Serial Terminal application (like Arduino IDE Serial Monitor, Putty, etc.) to
view the string sent from the Node MCU.
5. Alternatively, you can use the Serial.println() function to send the string and add a new line
after the string.
Procedure:
1. Open Arduino IDE software.
2. Now write the program in Sketch area in Arduino.
3. Save the program and click on the verify button.
4. Now connect the Node MCU to the host computer. Verify the COM port in Tools
menu.
5. Select the board as ESP8266 Node MCU in tools options. Now click on verify
button wait to complete the compilation process.
6. Now click on upload button and wait to complete the uploading process.
7. Check the ouput in serial monitor.
Output:
Program:
void setup()
{
Serial.begin(9600); // start serial communication at 9600 baud
}
void loop()
{
if (Serial.available() > 0)
{ // check if data is available on the serial port
char incomingByte = Serial.read(); // read the incoming data
Serial.print(incomingByte); // echo the incoming data back to the sender
}
}
Output:
Result: A Full Duplex link is established using Node MCU and output is displayed in serial monitor.