0% found this document useful (0 votes)
70 views37 pages

Exp. No.: 1 Date: Introduction To The Arduino Microcontroller & Nodemcu AIM

The Arduino (Uno) Board is a microcontroller board that was created to house the ATmega328 chip. The chip is a high performance and low power 8-bit micro-controller that has 23 programmable I/O lines, 32K bytes of flash memory (of which 0.5KB is already used for the Boot loader), 1k bytes of EEPROM and 2k bytes of RAM. The Arduino Uno board provides the user with 6 analog input pins, 14 digital I/O pins of which 6 of them can also be used for PWM outputs, a power jack, a USB port, an ICSP heade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views37 pages

Exp. No.: 1 Date: Introduction To The Arduino Microcontroller & Nodemcu AIM

The Arduino (Uno) Board is a microcontroller board that was created to house the ATmega328 chip. The chip is a high performance and low power 8-bit micro-controller that has 23 programmable I/O lines, 32K bytes of flash memory (of which 0.5KB is already used for the Boot loader), 1k bytes of EEPROM and 2k bytes of RAM. The Arduino Uno board provides the user with 6 analog input pins, 14 digital I/O pins of which 6 of them can also be used for PWM outputs, a power jack, a USB port, an ICSP heade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Embedded Systems and Applications Laboratory Manual 2019

Exp. No.: 1 Date:


INTRODUCTION TO THE ARDUINO MICROCONTROLLER & NODEMCU
AIM
Describe the basic functioning of the “standard” Arduino microcontroller board. Use the
Arduino IDE to load, compile, download and execute (provided samples and user-written)
programs.
The NodeMCU ESP8266 is the name of a micro controller designed by Espressif
Systems. The ESP8266 itself is a self-contained WiFi networking solution offering as a
bridge from existing micro controller to WiFi and is also capable of running self-contained
applications.

APPARATUS/ COMPONENTS REQUIRED

1. Arduino UNO
2. NodeMCU ESP8266

ARDUINO UNO

DESCRIPTION
The lab will be based on the Arduino Uno. The Arduino (Uno) Board is a micro-
controller board that was created to house the ATmega328 chip. The chip is a high performance
and low power 8-bit micro-controller that has 23 programmable I/O lines, 32K bytes of flash
memory (of which 0.5KB is already used for the Boot loader), 1k bytes of EEPROM and 2k
bytes of RAM. The Arduino Uno board provides the user with 6 analog input pins, 14 digital I/O
pins of which 6 of them can also be used for PWM outputs, a power jack, a USB port, an ICSP
header, a reset button, a small LED connected to digital pin 13, and a 16MHz crystal oscillator.
In comparison to earlier models, the board uses the Atmega8U2 programmed as a USB-
to-serial converter rather than the FTDI USB-to-serial driver chip. It is the latest in the Arduino
USB board series and the current reference model for the Arduino platform. The board is fairly
easy to use and capable of doing a lot of things.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 1
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.1 Image of the Arduino Uno Board and components are labeled

Features of Arduino Uno board

Microcontroller ATmega328
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328) of which 0.5 KB used by
boot loader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 2
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.2 ATmega 328 Pin mapping

Analog input pins – pins (A0-A5) that take-in analog values to be converted to be represented
with a number range 0-1023 through an Analog to Digital Converter (ADC).

ATmega328 chip – 8-bit microcontroller that processes the sketch you


programmed.

Built-in LED – in order to gain access or control of this pin, you have to change the
configuration of pin 13 where it is connected to.

Crystal Oscillator – clock that has a frequency of 16MHz

DC Jack – where the power source (AC-to-DC adapter or battery) should be connected. It is
limited to input values between 6-20V but recommended to be around 7-12V.

Digital I/O pins – input and output pins (0-13) of which 6 of them (3, 5, 6, 9, 10 and 11) also
provide PWM (Pulse Width Modulated) output by using the analog Write () function. Pins (0
(RX) and 1 (TX)) are also used to transmit and receive serial data. ICSP Header – pins for “In-
Circuit Serial Programming” which is another method of programming.

ON indicator – LED that lights up when the board is connected to a power source. Power
Pins, pins that can be used to supply a circuit with values VIN (voltage from DC Jack), 3.3V
and 5V.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 3
Embedded Systems and Applications Laboratory Manual 2019

Reset Button – a button that is pressed whenever you need to restart the sketch programmed
in the board.

USB port – allows the user to connect with a USB cable the board to a PC to upload sketches
or provide a voltage supply to the board. This is also used for serial communication through
the serial monitor from the Arduino software.

Setup & Installation

A. Arduino IDE (For Windows)


This part will guide you through the set up and installation process of the Integrated
Development Environment (IDE) that will be used throughout the exercises.

1. Open your default internet browser and access the Arduino website. Download the
latest Arduino IDE version. The software is compatible with Linux, Mac and
Windows so just choose the one that matches your OS. The Arduino download
page is at http://arduino.cc/en/Main/Software [2].

Figure 1.3 A part of Arduino Website’s download page. The current version at this time
was 0022. Arduino allows you to install its IDE on several platforms (see encircled)

2. After downloading the compressed file, extract its contents to your preferred
directory (C:\Program Files, your Desktop or etc…). Note that the whole folder size is
around 200MB when completely extracted [2].

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 4
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.4 Screenshot of attempt to extract the zipped Arduino folder. Make sure you
have an archive utility such as 7zip or WinRAR.
3. Congratulations! Arduino IDE is installed on your computer. To use it, just navigate
to your main folder directory and run the Arduino application [2].

Figure 1.5 Screenshot of what’s inside the Arduino-0022folder. The application icon looks
like an infinity symbol.
B. Arduino Uno board driver (For Windows)
This part will guide you through the set-up and installation process of the Arduino Uno
board driver for the device to be recognized by the IDE.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 5
Embedded Systems and Applications Laboratory Manual 2019

1. Connect the Arduino UNO to the computer via USB Cable (A on fig. 4) [2]. Check if
it is properly connected by observing the green LED labeled ON (B on fig. 4) on the
board.

Figure 1.6 Photo of Arduino Uno board connected to a Computer. Note that the board’s
USB-B port.
2. Wait for Windows to try and install the device’s driver until it fails. Navigate to the
Device Manager through Start > Control Panel > Device Manager. Locate the Arduino Uno
Device. Right-click it to choose Update Driver Software [2].

Figure 1.7 Screenshot of the Device Manager. The Arduino Uno should have an
exclamation point.
3. Choose to browse your computer for the driver by clicking Browse my computer for
driver software [2].

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 6
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.8 Screenshot of the options for searching the device driver. Choose the
second option so that you can look for it in your hard disk.

4. A new window will open for you to indicate the location of the driver. Click Browse…

Figure 1.9 Screenshot of the browse option menu. Choose the first option which is to
look manually for the folder that contains the Arduino Uno board’s driver.
5. Navigate to your Arduino folder and choose the drivers folder. Click OK upon selection
[2].

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 7
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.10 Screenshot of navigating through the Arduino software folder. Note that
the drivers folder was chosen rather than the FTDI USB Drivers (It was mentioned earlier
that only preceding models use this)

6. A Windows Security window sometimes pops up to confirm if you want to continue the
installation. Just click, Install this driver software anyway.

Figure 1.11 Screenshot of pop-up window. Windows can’t verify the publisher of the
device software but we know that the software’s publisher is Arduino.
7. Wait for Windows to finish installing the device driver. Upon completion, you should see
an installation successful message. Congratulations and click Close. You are ready to start
programming using Arduino!

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 8
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.12 Screenshot of successful driver installation of the Uno board. The next step is to
start doing the exercises.

Arduino Programming

Click on the Arduino executable which has the Arduino logo

The following screen comes up:

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 9
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.13 Screenshot of Sketches

The programs written for Arduino are called sketches. For the sketch to work on the
Arduino Uno, there are two hardware related settings need to be done in the Arduino IDE –
Board Serial Port.

For selecting the board, go to the Tools tab and select Board. From the menu select Uno.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 10
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.14 Screenshot of Connect the Arduino Uno to the USB port of PC

When you connect your Arduino Uno to the USB port of your PC, it will be mapped as
a serial port. To know the serial port to which your Arduino is mapped, follow the following
procedure:
Right click on My Computer

Select the Manage option

In the pop up screen for Computer Management, select the Device Manager

Expand the Ports item; the Arduino Uno will appear as one of the drop down items

Figure 1.15 Screenshot of Port selection

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 11
Embedded Systems and Applications Laboratory Manual 2019

In the Arduino IDE, select the Serial Port as the port to which the Arduino is mapped.

Figure 1.16 Screenshot of Mapping the serial port

The basic structure of the Arduino sketch is fairly simple and has two required functions:

void setup()
{
statements;
}
void loop()
{
statements;
}
Where setup() is the preparation, loop() is the execution. Both functions are required for
the program to work. The setup function should follow the declaration of any variables at the
very beginning of the program. It is the first function to run in the program, is run only once, and
is used to set pin Mode or initialize serial communication.
The loop function follows next and includes the code to be executed continuously reading
inputs, triggering outputs, etc. This function is the core of all Arduino programs and does the
bulk of the work

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 12
Embedded Systems and Applications Laboratory Manual 2019

setup()

The setup() function is called once when your program starts. Use it to initialize pin
modes, or begin serial. It must be included in a program even if there are no statements to run.
void setup()
{
pinMode(pin, OUTPUT); // sets the 'pin' as output
}

loop()

After calling the setup() function, the loop() function does precisely what its name
suggests, and loops consecutively, allowing the program to change, respond, and control the
Arduino board.

void loop()
{
digitalWrite(pin, HIGH); // turns 'pin' on delay(1000); // pauses for one second digitalWrite(pin,
LOW); // turns 'pin' off delay(1000); // pauses for one second
}

pinMode(pin, mode)

Used in void setup() to configure a specified pin to behave either as an INPUT or an

OUTPUT.

pinMode(pin, OUTPUT); // sets ‘pin’ to output

There are also convenient pullup resistors built into the Atmega chip that can be accessed from
software. These built-in pullup resistors are accessed in the following manner:
Pin Mode (pin, INPUT); // set ‘pin’ to input digitalWrite(pin, HIGH); // turn on pullup resistors
Pullup resistors would normally be used for connecting inputs like switches. Notice in the above
example it does not convert pin to an output, it is merely a method for activating the internal
pull-ups.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 13
Embedded Systems and Applications Laboratory Manual 2019

Pins configured as OUTPUT can provide 40 mA (milliamps) of current to other


devices/circuits. This is enough current to brightly light up an LED (don't forget the series
resistor), but not enough current to run most relays, solenoids, or motors. Short circuits on
Arduino pins and excessive current can damage or destroy the output pin, or damage the
entire Atmega chip. It is often a good idea to connect an OUTPUT pin to an external device in
series with a 470Ω or 1KΩ resistor.

digitalRead(pin)

Reads the value from a specified digital pin with the result either HIGH or LOW. The pin can be
specified as either a variable or constant (0-13).
value = digitalRead(Pin); // sets 'value' equal to the input pin

digitalWrite(pin, value)

Outputs either logic level HIGH or LOW at (turns on or off) a specified digital pin. The
pin can be specified as either a variable or constant (0-13).
digitalWrite(pin, HIGH); // sets 'pin' to high

The following example reads a pushbutton connected to a digital input and turns on an LED
connected to a digital output when the button has been pressed:
int led = 13; // connect LED to pin 13
int pin = 7; // connect pushbutton to pin 7
int value = 0; // variable to store the read value void setup()
{
pinMode(led, OUTPUT); // sets pin 13 as output pinMode(pin, INPUT); // sets pin 7 as inut
}
void loop()
{
value = digitalRead(pin); // sets 'value' equal to the input pin digitalWrite(led, value); // sets 'led'
to the button's value
}

analogRead(pin)

Reads the value from a specified analog pin with a 10-bit resolution. This function only
works on the analog in pins (0-5). The resulting integer values range from 0 to 1023.
value = analogRead(pin); // sets 'value' equal to 'pin'

Note: Analog pins unlike digital ones, do not need to be first declared as INPUT or OUTPUT.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 14
Embedded Systems and Applications Laboratory Manual 2019

analogWrite(pin, value)

Writes a pseudo-analog value using hardware enabled pulse width modulation (PWM) to
an output pin marked PWM. On Uno, this function works on pins 3, 5, 6, 9, 10, and 11.
The value can be specified as a variable or constant with a value from 0-255. analogWrite(pin,
value); // writes 'value' to analog 'pin'

A value of 0 generates a steady 0 volts output at the specified pin; a value of


255 generates a steady 5 volts output at the specified pin. For values in between 0 and 255, the
pin rapidly alternates between 0 and 5 volts - the higher the value, the more often the pin is
HIGH (5 volts). For example, a value of 64 will be 0 volts three-quarters of the time, and 5
volts one quarter of the time; a value of 128 will be at 0 half the time and 255 half the time; and
a value of
192 will be 0 volts one quarter of the time and 5 volts three-quarters of the time.

Because this is a hardware function, the pin will generate a steady wave after a call to
analogWrite in the background until the next call to analogWrite (or a call to digitalRead or
digitalWrite on the same pin).

Note: Analog pins unlike digital ones do not need to be first declared as INPUT or OUTPUT.

The following example reads an analog value from an analog input pin, converts the
value by dividing by 4, and outputs a PWM signal on a PWM pin:
int led = 10; // LED with 220 resistor on pin 10 int pin = A0; // potentiometer on analog pin 0 int
value; // value for reading
void setup(){} // no setup needed void loop()
{
value = analogRead(pin); // sets 'value' equal to 'pin' value /= 4; // converts 0-1023 to 0-255
analogWrite(led, value); // outputs PWM signal to led
}

delay(ms)

Pauses a program for the amount of time as specified in milliseconds, where 1000 equals
1 second.
delay(1000); // waits for one second

millis()

Returns the number of milliseconds since the Arduino board began running the current program
as an unsigned long value.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 15
Embedded Systems and Applications Laboratory Manual 2019

value = millis(); // sets ‘value’ equal to millis()

Note: This number will overflow (reset back to zero), after approximately 9 hours.
Serial.begin(rate)

Opens serial port and sets the baud rate for serial data transmission. The typical baud
rate for communicating with the computer is 9600 although other speeds are supported.
void setup()
{
Serial.begin(9600); // opens serial port
} // sets data rate to 9600 bps
Note: When using serial communication, digital pins 0 (RX) and 1 (TX) cannot be used at the
same time.

Serial.println(data)

Prints data to the serial port, followed by an automatic carriage return and line feed. This
command takes the same form as Serial.print(), but is easier for reading data on the Serial
Monitor.
Serial.println(analogValue); // sends the value of

// 'analogValue'

Note: For more information on the various permutations of the Serial.println() and Serial.print
() functions please refer to the Arduino website.

The following simple example takes a reading from analog pin0 and sends this data to the
computer every 1 second.
void setup()
{
Serial.begin(9600); // sets serial to 9600bps
}
void loop()
{
Serial.println(analogRead(A0)); // sends analog value delay(1000); // pauses for 1 second
}

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 16
Embedded Systems and Applications Laboratory Manual 2019

Figure 1.17 Screenshot of Arduino program compilations

After entering your program, click on the Verify button for compilation. If there are
errors, the line numbers of the errors are shown in the bottom window. Correct the errors. After
successful verification, upload your program to the Arduino using the Upload button. A common
cause for failure in uploading is that your Arduino is not connected to a different COM port than
the one shown in the Arduino IDE.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 17
Embedded Systems and Applications Laboratory Manual 2019

NODE MCU ESP8266


The ESP8266 is the name of a micro controller designed by Espressif Systems.
The ESP8266 itself is a self-contained WiFi networking solution offering as a bridge from
existing micro controller to WiFi and is also capable of running self-contained applications.
This module comes with a built in USB connector and a rich assortment of pin-outs. With a
micro USB cable, you can connect NodeMCU devkit to your laptop and flash it without any
trouble, just like Arduino. It is also immediately breadboard friendly.

Specification:
 Voltage:3.3V.
 Wi-Fi Direct (P2P), soft-AP.
 Current consumption: 10uA~170mA.
 Flash memory attachable: 16M B max (512K normal).
 Integrated TCP/IP protocol stack.
 Processor: Tensilica L106 32-bit.
 Processor speed: 80~160MHz.
 RAM: 32K + 80K.
 GPIOs: 17 (multiplexed with other functions).
 Analog to Digital: 1 input with 1024 step resolution.
 +19.5dBm output power in 802.11b mode
 802.11 support: b/g/n.
 Maximum concurrent TCP connections: 5.
Features:
 Version : DevKit v1.0
 Breadboard Friendly
 Light Weight and small size.
 Arduino IDE compatible (extension board manager required).
 Supports Lua (alike node.js) and Arduino C programming language.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 18
Embedded Systems and Applications Laboratory Manual 2019

Pin Definition:

Pin Names on Pin Names on ESP8266 Internal


ESP8266 Internal
NodeMCU NodeMCU GPIO Pin number
GPIO Pin number
Development Kit Development Kit

D0 GPIO16 D7 GPIO13

D1 GPIO5 D8 GPIO15

D2 GPIO4 D9/RX GPIO3

D3 GPIO0 D10/TX GPIO1

D4 GPIO2 D11/SD2 GPIO9

D5 GPIO14 D12/SD3 GPIO10

D6 GPIO12 D9/RX GPIO3

NodeMCU Dev Kit IO pins and ESP8266 internal GPIO pins mapping

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 19
Embedded Systems and Applications Laboratory Manual 2019

Install the Arduino IDE:

Download Arduino IDE from Arduino.cc (1.6.4 or greater), You can use your existing IDE if
you have already installed it. Download the ready-to-go package from the ESP8266-Arduino project.

Install the ESP8266 Board Package


Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board
Manager URLs field in the Arduino v1.6.4+ preferences.

Click ‘File’ -> ‘Preferences’ to access this panel. Next, use the Board manager to install the
ESP8266 package.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 20
Embedded Systems and Applications Laboratory Manual 2019

Click ‘Tools’ -> ‘Board:’ -> ‘Board Manager…’ to access this panel.
Scroll down to ‘esp8266 by ESP8266 Community’ and click “Install” button to install the
ESP8266 library package. Once installation completed, close and re-open Arduino IDE for
ESP8266 library to take effect.
Setup ESP8266 Support
When you've restarted Arduino IDE, select ‘Generic ESP8266 Module’ from the ‘Tools’ ->
‘Board:’ dropdown menu.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 21
Embedded Systems and Applications Laboratory Manual 2019

Select 80 MHz as the CPU frequency (you can try 160 MHz overclock later)

Select ‘115200’ baud upload speed is a good place to start - later on you can try higher speeds
but 115200 is a good safe place to start.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 22
Embedded Systems and Applications Laboratory Manual 2019

Go to your Windows ‘Device Manager’ to find out which Com Port ‘USB-Serial CH340’ is
assigned to. Select the matching COM/serial port for your CH340 USB-Serial interface.

Note: if this is your first time using CH340 “ USB-to-Serial ” interface, please install the driver
first before proceed the above Com Port setting. The CH340 driver can be download from the
below site: https://github.com/nodemcu/nodemcu-devkit/tree/master/Drivers.

Blink Test:

We'll begin with the simple blink test. Enter this into the sketch window (and save since you'll
have to). Connect a LED as shown in Figure3-1.
void setup ()
{
pinMode (5, OUTPUT); // GPIO05, Digital Pin D1
}
Void loop ()
{
digitalWrite (5, HIGH);
delay (900);
digitalWrite (5, LOW);
delay(500);
}

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 23
Embedded Systems and Applications Laboratory Manual 2019

Now you'll need to put the board into bootload mode. You'll have to do this before each
upload. There is no timeout for bootload mode, so you don't have to rush!
 Hold down the ‘Flash’ button.
 While holding down ‘ Flash’, press the ‘RST’ button.
 Release ‘RST’, then release ‘Flash’
 When you release the ‘RST’ button, the blue indication will blink once, this means
its ready to bootload.
 Once the ESP board is in bootload mode, upload the sketch via the IDE, Figure 3-2.

Figure3-1: Connection diagram for the blinking test

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 24
Embedded Systems and Applications Laboratory Manual 2019

Figure 3.2: Uploading the sketch to ESP8266 NodeMCU module.


The sketch will start immediately - you'll see the LED blinking.

Connecting via WiFi :


OK once you've got the LED blinking, let’s go straight to the fun part, connecting to a
web server. Create a new sketch with this code:
Don’t forget to update:
const char* ssid = "yourssid";
const char* password = "yourpassword";
to your WiFi access point and password, then upload the same way: get into boot load
mode, then upload code via IDE.

/* * Simple HTTP get webclient test */


#include <ESP8266WiFi.h>
const char* ssid = "handson"; // key in your own SSID
const char* password = "abc1234"; // key in your own WiFi access point
password
const char* host = "www.handsontec.com";
void setup() { Serial.begin(115200); delay(100);
// We start by connecting to a WiFi network

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 25
Embedded Systems and Applications Laboratory Manual 2019

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request String url = "/projects/index.html";
Serial.print("Requesting URL: "); Serial.println(url);
// This will send the request to the server client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(500);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
Open up the IDE serial console at 115200 baud to see the connection and webpage printout!

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 26
Embedded Systems and Applications Laboratory Manual 2019

That's it, pretty easy right ! This section is just to get you started and test out your module.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 27
Embedded Systems and Applications Laboratory Manual 2019

INTERFACING ARDUINO UNO WITH LCD AND PUSH BUTTON

Designing a circuit for Up Counting when pressed Push button and display the result in
LCD.

Hardware Requirements:

S.No. Title of Component Component Image Quantity

1. Arduino Uno 01

2. Mini Push Button 01

3. LCD 16×2 YJD1602A-1 01

4. 10KΩ POT & 1KΩ POT 01 each

5 220Ω Resistor 02

Connecting Wires & USB As per


6.
Cable Requirement

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 28
Embedded Systems and Applications Laboratory Manual 2019

Pre Lab Session:

1. Study of various Types of Laboratory as well as Industrial Push Button and Its
Description.

2. Study of various Displays for Embedded System and its configuration.

3. Perform the experiment to display the incremented integer values on LCD with switch
control.

4. Implementation of interfacing two or more Number of Push Buttons.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 29
Embedded Systems and Applications Laboratory Manual 2019

Description:

The objective of this experiment is to interface Arduino with LCD and Push buttons. In
this experiment decimal value increment when button is pressed and the result is shown in LCD
display. Here the Push button1 is dedicated for an up count. The initial value is zero, if push
button1 is pressed then count value is increment to 1 and when ever push button1 pressed count
value must increase by one decimal value and the result must display in LCD screen.

The Component Pin diagram are shown below,

Fig:1.1 Mini Push Button

Fig: 1.2 Display LCD 16×2 JHD1602A-1

Fig: 1.3 10KΩ potentiometer

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 30
Embedded Systems and Applications Laboratory Manual 2019

LCD Interfacing with Arduino UNO


 The interfacing connection between LCD and Arduino UNO is shown in Fig1.5.
The LCDs have a parallel interface, meaning that the microcontroller has to manipulate
several interface pins at once to control the display. The interface consists of the
following pins:
 A register select (RS) pin that controls where writing data to in the LCD's memory.
Here it can select either the data register, which holds what goes on the screen, or an
instruction register, which is where the LCD's controller looks for instructions on what to
do next.
 A Read/Write (R/W) pin that selects reading mode or writing mode
 An Enable pin that enables writing to the registers
 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that are writing to
a register when it write, or the values that reading when it read.
 There's also a display contrast pin (Vo), power supply pins (+5V and Gnd) and LED
Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD, control the display
contrast, and turn on and off the LED backlight, respectively.
 The process of controlling the display involves putting the data that form the image of
what text to display into the data registers, then putting instructions in the instruction
register. The Liquid Crystal Library simplifies and don't need to know the low-level
instructions.

Fig 1.4 Interfacing LCD with Arduino UNO Board

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 31
Embedded Systems and Applications Laboratory Manual 2019

Circuit
 Before wiring the LCD screen to Arduino board we suggest to solder a pin header strip to
the 14 (or 16) pin count connector of the LCD screen, as shown in the image above.
 To wire your LCD screen to Arduino board, connect the following pins:
 LCD RS pin to digital pin 12
 LCD Enable pin to digital pin 11
 LCD D4 pin to digital pin 5
 LCD D5 pin to digital pin 4
 LCD D6 pin to digital pin 3
 LCD D7 pin to digital pin 2
 Additionally, wire a 10k pot to +5V and GND, with it's wiper (output) to LCD screens
VO pin (pin3). A 220 ohm resistor is used to power the backlight of the display, usually
on pin 15 and 16 of the LCD connector

Fig 1.5 Circuit setup for interfacing LCD and Push buttons with Arduino UNO

Procedure:

Step 1: Connect the circuit as shown in Fig 1.5.

Step 2: Complete the programme verification in Arduino Sketch and save the sketch.

Step 3: Connect the Arduino board to PC and upload the verified sketch.

Step 4: Verify the output.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 32
Embedded Systems and Applications Laboratory Manual 2019

Programming Code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int a =0;
int e = 7;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("WELCOME TO K L U");
pinMode(e,INPUT);
}
void loop()
{
int button = digitalRead(e);
lcd.setCursor(3, 1);
lcd.print(a);
if (button == HIGH)
{
a ++;
lcd.setCursor(3, 1);
lcd.print(a);
delay(200);
}
}

Output:

Results/ Conclusion:
The Interfacing of LCD and Push button with Arduino is completed successfully. The
push button used for increment of count for key press and the result will show in the LCD
dynamically updates. This experiment can be extended to perform various projects increment or
decrement of a value for a pressed key. This can be implemented for GUI game implementation
using Arduino Uno.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 33
Embedded Systems and Applications Laboratory Manual 2019

Post Lab Session:

1. Construct module to display your name and register number on your project kit using Arduino
Board.

2. Demonstrate the Token number displaying system used in Bank/other places using Arduino
and LCD.

3. Implementation of Push Button & LCD based GUI Game using Arduino.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 34
Embedded Systems and Applications Laboratory Manual 2019

Interference Analysis:
First we'll set up constants for the pin numbers. Since a pushbutton has only two states
(pushed or not pushed), we've run them into digital inputs. To read an input, we'll use the digital
Read () function. This function takes one parameter, the pin number, and returns either HIGH
(5V) or LOW (GND). Here we'll read the current pushbutton states into two variables:
Remember that if the button is being pressed, it will be connected to GND. If the button is not
being pressed, the pull up resistor will connect it to 5 Volts. So the state will be LOW when it is
being pressed and HIGH when it is not being pressed. Now we'll use those states to control the
LCD. Here's what we want to do: "If either button is being pressed, light up the LED/ Values"
"But, if BOTH buttons are being pressed, DON'T light up the LED/ Values" Let's translate that
into computer code. The Arduino gives you special logic functions to deal with true/false logic:

Applications

Display the information/ data as per the instruction/ controlled with external interrupts.
Like Students data, Token System in public and private places and etc.

Viva voice Questions:

Hardware Related Question.

1. Explain About Types of Push Button.

2. What is Debouncing.

3. Explain about LCD data sheet.

4. How to control the LCD brightness.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 35
Embedded Systems and Applications Laboratory Manual 2019

5. List out types of Arduino Boards

6. What is the voltage range is used for Arduino

7. What type of Micro controller is used in Arduino Uno

8. What is the purpose of Analog Pins.

9. What is the Purpose of PWM pins in Arduino

10. How to interface Push button and Arduino.

Programming Related Questions

1. What are the required Libraries for LCD interfacing?

2. What type of Arduino pin is connected to read the action of a Push Button?

3. What is purpose of “Pinmode” in programming?

4. What is the command for scrolling displaying?

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 36
Embedded Systems and Applications Laboratory Manual 2019

5. What is the Difference between Function Void Setup and Void loop?

6. What is the command for display the data on LCD?

7. What is the command for display the data on Serial Monitor?

8. Explain how to print any character at second row 5th column place.

9. How to clear the present display content on LCD screen.

10. How to select the cursor position.

RESULTS

Successfully studied and configure the Arduino Uno and Node McU to communicate
with the Arduino IDE and hardware and a executed sample project to display the result in LCD.

Koneru Lakshmaiah Education Foundation (Deemed to be University), NAAC - “A++”, Guntur, AP | ECE 37

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy