Arduino Lab Manual
Arduino Lab Manual
LAB MANUAL(R-20)
Prepared by
Mr.G.Harish, M.Tech, (Ph.D)
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.
Value = V*4096/5;
This formula also applies to 3.3V if we use an ESP8266 board, which usually only has 3.3V power.
Value = V*4096/3.3;
Adafruit_MCP4725 dac;
void setup() {
Serial.begin(9600);
Serial.println("Hello!");
dac.begin(0x60);
}
void loop() {
// put your main code here, to run repeatedly:
dac.setVoltage(4* 4096/ 4.9, false); //Change the 1 value according to your
desired voltage output
}
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. Then connect MCP4725 I2C DAC i.e SCL-D1, SDA-D2 and connect output to
either an LED or an voltmeter.
6. Now click on upload button and wait to complete the uploading process.
7. Check the analog output in the voltmeter connected.
Result: Using 8-bit DAC i.e MCP4725 and Node MCU, analog output is displayed in Voltmeter.
Pinout
The 28BYJ-48 stepper motor has five wires. The pinout is as follows:
The 28BYJ-48 has two coils, each of which has a center tap. These two center taps are connected
internally and brought out as the 5th wire (red wire). Together, one end of the coil and the center tap
form a Phase. Thus, 28BYJ-48 has a total of four phases.
The red wire is always pulled HIGH, so when the other lead is pulled LOW, the phase is energized.
The stepper motor rotates only when the phases are energized in a logical sequence known as a step
sequence.
Because the 28BYJ-48 stepper motor consumes a significant amount of power, it cannot be controlled
directly by a microcontroller such as Node MCU. To control the motor, a driver IC such as the
ULN2003 is required; therefore, this motor typically comes with a ULN2003-based driver board.
The ULN2003, known for its high current and high voltage capability, provides a higher current gain
than a single transistor and allows a microcontroller’s low voltage low current output to drive a high
current stepper motor.
The ULN2003 consists of an array of seven Darlington transistor pairs, each of which can drive a
load of up to 500mA and 50V. This board utilizes four of the seven pairs.
Procedure:
Program:
//Includes the Arduino Stepper Library
#include <Stepper.h>
void setup() {
// Nothing to do (Stepper Library sets pins as outputs)
}
void loop() {
// Rotate CW slowly at 5 RPM
myStepper.setSpeed(10);
myStepper.step(stepsPerRevolution);
Below we have included all the steps that you will need to follow to connect the ADXL345
accelerometer to an Node MCU.
• Wire the GND pin of the ADXl345 to the GND Pin on the Arduino.
• Wire the VCC pin of the ADXL345 to the 3v3 Pin on the Arduino.
• Wire the SCL pin of the ADXL345 to the D1 Pin on the Node MCU.
• Wire the SDA pin of the ADXL345 to the D2 Pin on the Node MCU.
Procedure:
1. First, include all the required libraries header files to support the functionality of the sensor. Here
we are also using wire library for I2C communication.
Program:
#include <Wire.h>
#include <Adafruit_Sensor.h> // Adafruit sensor library
#include <Adafruit_ADXL345_U.h> // ADXL345 library
void setup() {
Serial.begin(9600);
if(!accel.begin()) // if ASXL345 sensor not found
{
Serial.println("ADXL345 not detected");
while(1);
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
Serial.print("X: ");
Serial.print(event.acceleration.x);
Serial.print(" ");
Serial.print("Y: ");
Serial.print(event.acceleration.y);
Serial.print(" ");
Serial.print("Z: ");
Serial.print(event.acceleration.z);
Serial.println(" ");
Output:
Result: Accelerometer ADXL 345 interfaced successfully, and readings were shown
on serial monitor.