0% found this document useful (0 votes)
353 views41 pages

Arduino Lab Manual

The document provides instructions for experiments using an Arduino board for a lab course. It includes a list of 8 experiments covering topics like reading analog sensors, generating PWM signals, driving displays and motors. It also provides details on setting up the Arduino IDE and includes an introduction to the IDE interface and features.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
353 views41 pages

Arduino Lab Manual

The document provides instructions for experiments using an Arduino board for a lab course. It includes a list of 8 experiments covering topics like reading analog sensors, generating PWM signals, driving displays and motors. It also provides details on setting up the Arduino IDE and includes an introduction to the IDE interface and features.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 41

ARDUINO BASED PROGRAMMING

LAB MANUAL(R-20)

Prepared by
Mr.G.Harish, M.Tech, (Ph.D)
Associate Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING.


ARDUINO BASED PROGRAMMING LAB

III Year - II Semester

List of Experiments

1. Measure Analog signal from Temperature Sensor


2. Generate PWM output
3. Drive single character generation on Hyper Terminal
4. Drive a given string on Hyper Terminal
5. Full duplex Link establishment using Hyper terminal
6. Drive a given value on a 8 bit DAC consisting of SPI
7. Drive Stepper motor using Analog GPIOs
8. Drive Accelerometer and Display the readings on Hyper Terminal

Arduino Based Programming Lab Manual Department of ECE, VLITS


Introduction to Arduino IDE

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


The code that we write in this IDE is known as sketch. After compiling an sketch it gives a Hex
file which we can upload to the Arduino. The code is written in the C or C++ language. Its user
interface has a navigation menu bar on the top, text editor in which we write the code and a output
pane where compilation logs are shown.

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.

New It is used to open a new sketch


Open To open existing sketch
Open Recent To open recent sketches
Sketchbook To open the entire sketches

Arduino Based Programming Lab Manual Department of ECE, VLITS


Example To open example codes
Close To close the window
Save To save the sketch
Save As To save the same sketch with different
name
Page Setup To setup the page with portrait or landscape
Print To print the text editor
Preferences It is used to set the page preferences, the
sketchbook location, compilation options
etc..
Quit To close all active windows

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”.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Upload
This shortcut button showing right sided arrow is called upload and used to upload the code into the
microcontroller of Arduino. Shortcut key for this is“CTRL+U”.
New
This shortcut button showing dotted paper is used to open a new sketch. Shortcut key to open a new
sketch is “CTRL+N”.
Open
The button with arrow up is used open an existing sketch. Shortcut key to open an existing sketch is
“CTRL+O”.
Save
The button with arrow down is used to save the sketch. Shortcut key to save a sketch is “CTRL+S”.
Serial monitor
As we press this button a separate window will pop up which will show the data that that is being
transmitted and received from an Arduino board. Shortcutkey for open serial monitor is
“CTRL+SHIFT+M”

Arduino Based Programming Lab Manual Department of ECE, VLITS


To start sending or receiving serial data we have to start serial communication in the code. Let’s see
how we can start serial communication in Arduino.

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.

Serial plotter in Arduino


There is another serial function and we call it “serial plotter”. Basically it is same as serial monitor
but it shows the serial data in the form of graph except string data. Suppose we are working with
some kind of heat sensor which output a data according to heat. So, serial plotter will show us heat
in the graphically. We can open serial plotter window by using shortcut key “CTRL+SHIFT+L”.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Here in the code, “i” is declared integer as globally. It means that we can use this everywhere in the
code. Then we started serial communication at 9600baud rate. Using the for loop value of “i” goes
up to 254 from 0. Then we print “i” serially. This basically means that we are printing the value of
“i”. As you can see that we have the graph of integer “i” printed on serial plotter window. Here x-
axis depends on the number and y-axis depends upon the highestvalue of serial data available.

Selecting the board type and port in Arduino


To upload the code on Arduino or serial communication or serial plotting we need to choose the
right board and port of board. These options will be available under “Tools” option and put the
mouse arrow on “Board”. It will open a window like figure shown below.

Arduino Based Programming Lab Manual Department of ECE, VLITS


From here you can choose the board you have connected form computer. And then go to port
option. Here we will be selecting the port of your operating system from which your board is
connected. It will look something like this.

In my case my Arduino UNO is connected to my COM11 port.


After selecting right board and port you can upload code to the board, see and plot the serial data.
During the code is uploading, the RX ant TX led on board should blink.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Including the libraries in Arduino code
In programming world libraries are so important. It consists the instruction set and predefined
function that we can run without writing it repeatedly. It adds extra functionality to any sketch that
we are writing by just including it. In Arduino we can include any library by using a
command“#include<library_name.h>” or by going to Sketch>Include Library>Select any Library.

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”.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Steps to Setup Arduino IDE for NODEMCU ESP8266

Step 1: Installing Arduino IDE Software


Install Arduino IDE software from the link http://www.arduino.cc/en/main/software
Step 2: Arduino IDE Icon
After installing Arduino IDE icon is created on the Desktop as show in the figure

Step 3: Opening Arduino IDE

Click on the Icon to open the Arduino window as shown in the figure

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 4: Preferences

Open the File and click on the Preferences as shown in the figure

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 5: Adding ESP8266 Board Manager

In the Additional Boards Manager enter below URL.


http://arduino.esp8266.com/stable/package_esp8266com_index.json

As highlighted in the figure and enter OK

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 6: Selecting Board

Now open the tools in that select Board: “Arduino/Genuino Uno” and click on the Boards
Manager as shown in the figure

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 7: ESP8266 Board Package

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 8: Selecting ESP8266 Arduino Board

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

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 9: Connecting ESP8266 to the PC

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 10: Selecting Example Program in Arduino IDE

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 11: Selecting COM Port

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 12: Uploading the Program to ESP8266 Module

Arduino Based Programming Lab Manual Department of ECE, VLITS


Step 13: Adding Libraries

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Node MCU
NodeMCU is an open-source firmware and development board that is based on the popular
ESP8266 Wi-Fi module. The firmware allows the ESP8266 to be programmed using the Lua
scripting language and provides a simple and easy-to-use development platform for creating
Internet of Things (IoT) devices and projects.
The NodeMCU development board includes a microcontroller, Wi-Fi module, and a USB-
to-serial converter, making it easy to connect to a computer and program. It also has a number of
pins for interfacing with other electronic components, such as sensors and actuators.
One of the main advantages of NodeMCU is its ease of use. With Lua, it is possible to write
and run code on the device without the need for a separate development environment. Additionally,
NodeMCU is compatible with the Arduino IDE, which makes it easy to port existing projects to the
platform.
NodeMCU can be used to create a wide range of IoT projects, from simple temperature
sensors to complex home automation systems.

Specifications & Construction :

• Operating Voltage: 2.5 to 3.3V


• Operating current: 800 mA
• 3.3V 600mA on-board voltage regulation
• ESP8266 comes up with 2 switches one is reset and another one is flash button, Reset button
is used to reset NodeMCU and flash button is used to download and is used while upgrading
the firmware. The board has build in LED indicator which is connected to D0 pin.
• The NodeMCU board also contains a CP2102 USB to UART module to convert the data from
USB to serial so that it can be controlled and programmed via computer.
• The esp8266 has 4 power pins: One VIN pin for input power supply and three 3.3V pins for
output power supply. Even if 5V regulated supply is given through VIN, the voltage regulator
will decrease it to 3.3v during output.
• The esp8266 has 3 GND pins which indicate ground supply. Generally, the negative terminals
are connected to these pins.
• Esp8266 board also has I2C pins which can be used both as I2C master and I2C Slave. These
pins are used to connect various I2C sensors and peripherals in your project. I2C interface
functionality can be controlled via programming, and the clock frequency is 100 kHz at a

Arduino Based Programming Lab Manual Department of ECE, VLITS


maximum.
• Esp8266 NodeMCU has 17 GPIO pins which can be assigned to various functions such as
UART, PWM, I2C,IR and Button via programming. When configured as an input pin, the
GPIO pins can also be set to edge-trigger or level-trigger to generate CPU interrupts.
• ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1, which offer
asynchronous communication, and may communicate at up to 4.5 Mbps. TXD0, RXD0, RST0
& CTS0 pins can be used for communication. It supports fluid control. However, TXD1 pin
features only data transmit signal so, it's usually used for printing log.
• ESP8266 has two SPI in slave and master modes. These SPIs also support the following
general features: 4 timing modes of the SPI format transfer. Up to 64-byte FIFO buffer.
• Esp8266 has a secure digital I/O interface which is used directly control the SD cards.
• Esp8266 has 4 channels of Pulse width modulation (PWM). The output can be controlled via
programming and is frequently used for driving motors and LEDs. The frequency ranges from
100Hz to 1KHz.
• There are three control pins on the esp8266: The enable pin (EN), the reset pin (RST) and the
wake pin.
• The esp8266 chip works when the enable pin is high. When the enable pin is low, the chip
works on minimum power.
• The reset pin is used to reset the esp8266 chip.

• The wake pin is used to wake up the chip from deep sleep mode.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 01
Measure Analog signal from Temperature Sensor

Aim: To measure analog signal from temperature sensor.


Apparatus:
Arduino IDE software
Node MCU Board
LM 35D Analog Temperature Sensor Module
Serial Cable
Theory:

In general, an LM35 is a temperature sensor which is designed specifically to measure the


hotness or coldness of an object. LM35 is a precision IC temperature sensor with its output
proportional to the temperature (in °C). With LM35, the temperature can be measured more
accurately than compared to the thermistor.

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Program:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = D1; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot


int outputValue = 0; // value output to the PWM (analog out)

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);

// print the results to the Serial Monitor:


Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital


// converter to settle after the last reading:
delay(2);
}

Output :

Result: The measured Analog Signal from Temperature Sensor is displayed in serial monitor.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 02
Generate PWM output

Aim: To generate a PWM output using Node MCU.


Apparatus:
Arduino IDE software
Node MCU Board
LED
Serial Cable
Theory:
To generate PWM output using an Node MCU with serial input, you can use the built-in
Serial.read() function in combination with the analogWrite() function. The Serial.read() function is
used to read data sent over the serial connection, and the analogWrite() function is used to output the
PWM signal.
The Serial.available() function is used to check if there is data available on the serial port,
and the Serial.read() function is used to read the incoming data. We can use a Serial Terminal
application (like Arduino IDE Serial Monitor) to send the value to the Node MCU which will be
read using the Serial.read() function.

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);
}

// decrease the LED brightness


for(int dutyCycle = 255; dutyCycle > 0; dutyCycle--)
{
// changing the LED brightness with PWM
analogWrite(ledPin, dutyCycle);
delay(1);
}
}

Arduino Based Programming Lab Manual Department of ECE, VLITS


Procedure:
1. Connect the LED TO PIN D2
2. Upload the code to the NodeMCU board using the Arduino IDE.
3. You can see the LED glow from high to low and low to high.

Result: The PWM output using Node MCU is generated.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 03
Drive single character generation on Hyper Terminal

Aim: To drive a single character generation on Hyper Terminal.


Apparatus:
Arduino IDE software
Node MCU Board
Serial Cable
Theory:

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() {

Arduino Based Programming Lab Manual Department of ECE, VLITS


// initialize serial communication at 9600 baud rate
Serial.begin(9600);
}
void loop() {
// send the character "A"
Serial.write("A");
delay(1000);
}

Output :

Result: A single character is generated using Node MCU and output is displayed in
serial monitor.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 04
Drive a given string on Hyper Terminal

Aim: To drive a given string on Hyper Terminal.


Apparatus:
Arduino IDE software
Node MCU Board
Serial Cable
Program:

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:

Arduino Based Programming Lab Manual Department of ECE, VLITS


Result: A string is generated using Node MCU and output is displayed in serial monitor.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 05
Full duplex Link establishment using Hyper terminal

Aim: To establish Full Duplex link using Hyper Terminal.


Apparatus:
Arduino IDE software
Node MCU Board
Serial Cable
Theory:
1. To establish a full-duplex link using Hyper Terminal and an Node MCU, you will need to use the
built in Serial communication functions in the Arduino IDE.
2. You can establish a full-duplex link between Hyper Terminal and an Node MCU.
3. This code sets up a serial communication at 9600 baud and in the loop, it checks if any data is
available on the serial port using Serial.available() function. If data is available, it reads the
incoming data using Serial.read() function and then it echoes the data back to the sender using
Serial.print(incomingByte).
4. You should match the baud rate of the Hyper Terminal and Arduino IDE Serial.begin() function
to establish the full duplex link correctly.
5. In Hyper Terminal, you can set it to match the baud rate of the Node MCU. You can then send
data to the Node MCU and the Node MCU will echo the data back to the Hyper Terminal.
6. By doing this, you can establish a full-duplex link between Hyper Terminal and the Node MCU,
allowing for two-way communication between the two devices.

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
}
}

Arduino Based Programming Lab Manual Department of ECE, VLITS


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 which is echoed by sending the data in serial monitor.

Output:

Result: A Full Duplex link is established using Node MCU and output is displayed in serial monitor.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 06
Drive a given value on a 8 bit DAC consisting of SPI

Aim: To drive a given value on a 8-bit DAC consisting of SPI.


Apparatus:
Arduino IDE software
Node MCU Board
Serial Cable
MCP4725 I2C DAC
Theory:
DAC stands for Digital to Analog Converter, this module has the ability to generate true
analog Voltage. It has a 12-bit resolution. So you could generate 4096 steps voltage output.
If we use Node MCU, the maximum voltage output would be 5V. Since the voltage reference
is 5V. So 4096 would mean 5V and 0 would mean 0V. So, if we want to generate an output of 2.5V,
for example, we need to find the middle value of this range. So it would be around 2048. And you can
find any value using this simple formula

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;

Arduino Based Programming Lab Manual Department of ECE, VLITS


Program:
#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

// Set this value to 9, 8, 7, 6 or 5 to adjust the resolution


#define DAC_RESOLUTION (9);

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 07
Drive Stepper motor using Analog GPIOs

Aim: To drive a stepper motor using Analog GPIOs.


Apparatus:
Arduino IDE software
Arduino Uno Board
28BYJ-48 Stepper Motor 5V Unipolar
ULN2003 stepper motor driver board
Serial Cable
Theory:
The 28BYJ-48 is a 5-wire unipolar stepper motor that runs on 5V. It’s perfect for projects
that require precise positioning, like opening and closing a vent. Because the motor does not use
contact brushes, it has a relatively precise movement and is quite reliable.
Despite its small size, the motor delivers a decent torque of 34.3 mN.m at a speed of around
15 RPM. It provides good torque even at a standstill and maintains it as long as the motor receives
power. The only drawback is that it is somewhat power-hungry and consumes energy even when it
is stationary.

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


ULN2003 Driver Board

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:

1. Get the motor connected to our Node MCU.


2. The connections are straightforward. Begin by connecting an external 5V power supply to the
ULN2003 driver.
3. Connect the driver board’s IN1, IN2, IN3, and IN4 to Arduino digital pins D1, D2, D3, and
D4, respectively. Then connect the stepper motor to the ULN2003 driver.
4. Finally, make sure your circuit and Node MCU share a common ground.
5. Check the running of the stepper motor.

Program:
//Includes the Arduino Stepper Library
#include <Stepper.h>

// Defines the number of steps per rotation


const int stepsPerRevolution = 2038;

Arduino Based Programming Lab Manual Department of ECE, VLITS


// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper = Stepper(stepsPerRevolution, A0, A1, A2, A3);

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);

//Rotate CCW quickly at 10 RPM


// myStepper.setSpeed(10);
// myStepper.step(-stepsPerRevolution);
//delay(1000);
}

Result: Stepper motor was driven successfully using Analog GPIOs

Arduino Based Programming Lab Manual Department of ECE, VLITS


Experiment - 08
Drive Accelerometer and Display the readings on Hyper Terminal

Aim: To drive accelerometer and Display the readings on Hyperterminal.


Apparatus:
Arduino IDE software
Node MCU Board
ADXL 345 Accelerometer
Serial Cable
Theory:
ADXL345 is easy to interface because of its digital nature. But its programming is difficult as it works
on the SPI/I2C protocol. ADXL345 can measure static and dynamic accelerations and suitable for
mobile applications. Also, these sensors are laboratory calibrated and don’t require any further
calibrations.
The circuit for the ADXL345 accelerometer is pretty straightforward and doesn’t require any complex
parts or wiring and can be connected directly to the Node MCU.

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.

Arduino Based Programming Lab Manual Department of ECE, VLITS


2. Make an instance by using any variable like accel to use the various functions of the ADXL345
library.
3. In void setup() function, initialize serial communication to print data on a serial monitor
using Serial.begin() function. Now, check whether the valid ADXL sensor is connected or not. We
will check the result returned by accel.begin() function if it returns false then print a message that no
valid sensor found.
4. In void loop() function, create a variable to use sensors_event_t structure. Use this variable (in this
case “event”) to fill the structure members using .getevent() function. Now, print the values of
acceleration in x,y, z-axis using event.acceleration.x() function.
Finally, connect the ADXL345 sensor with Node MCU properly and upload the code in the Node
MCU board. Then open Serial monitor and you will see acceleration readings in x, y, z-axis.

Program:

#include <Wire.h>
#include <Adafruit_Sensor.h> // Adafruit sensor library
#include <Adafruit_ADXL345_U.h> // ADXL345 library

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(); // ADXL345 Object

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(" ");

Arduino Based Programming Lab Manual Department of ECE, VLITS


delay(500);

Output:

Result: Accelerometer ADXL 345 interfaced successfully, and readings were shown
on serial monitor.

Arduino Based Programming Lab Manual Department of ECE, VLITS

You might also like