0% found this document useful (0 votes)
40 views

MES Module 5

Engineering modules

Uploaded by

Prrishitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

MES Module 5

Engineering modules

Uploaded by

Prrishitha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Robotics Made Simple 73

Chapter 8
INTRODUCTION TO ARDUINO CONTROLLERS
8.1 OBJECTIVES OF CHAPTER 8:
• In this section, students learn about the Arduino controllers' fundamentals and their different types of
robot programming and robotic projects.
• Students can study Arduino Uno Board's features, power unit, and USB cable.
• Students understand the Windows XP and Application Execution method installation mechanism for the
Arduino drivers.
8.2 DEFINITION OF ARDUINO
Arduino is an open-source, hardware and software-based electronics platform. Arduino boards can read and
convert the output - a sensor light, a finger button or a Twitter message - by triggering a motor, turning an
LED, and publishing something online. By sending the microcontroller on the monitor, you will tell the board
what to do. To do this, you use the programming language of Arduino (based on wiring) and the processing-
based applications of Arduino (IDE).
Arduino has been the brain across thousands of projects, from daily objects to sophisticated research
instruments over the years. This open-source network brought together a worldwide community of makers—
students, hobbyists, artists, programmers and professionals—who have added an unbelievable amount of
usable information that can be useful to novices and experts.
Arduino was born as a simple platform for quick prototyping in the Ivrea Interaction Design Institute directed
at students without an academic and programming context. The Arduino board continues to adapt to new
demands and problems as soon as it enters a wider community and differentiates its offer from 8-bit boards to
IoT products, wearable, 3D printing and embedded environments. Both Arduino boards are entirely open
source, allowing users to develop them individually and finally adapt them to their individual needs. The app
is also open-source and is increasingly used by people around the world.
Why Arduino?
The Arduino is simple for beginners to use, but it is sufficiently versatile for advanced users. It operates for
Mac, Windows, and Linux. Teachers and students use it to create inexpensive science equipment, prove the
concepts of chemistry and physics, or start programming and robotics. Designers and engineers develop
immersive designs for installations and experiments on modern musical instruments by performers and artists.
Naturally, makers use it to build several designs, for example, shown in the Maker Faire. Arduino is an
effective platform for learning new material. Anyone, kids, hobbyists, artists, and programmers, can either
start tinkering on the directions of a kit step by step or exchange ideas with other Arduino group members
online. In thousands of diverse projects and software, Arduino was used.
For physical computing, there are various other microcontrollers and platforms. Parallax Basic Stamp
Netmedia's BX-24, Phidgets MIT handy board and several others provide similar features. Both these tools
take the messy microcontroller programming specifics and wrap it in a user-friendly box. In addition, Arduino
simplifies the operating process of microcontrollers but gives instructors, students and amateurs an advantage
over other systems:
• Inexpensive - Compared to other systems, Arduino boards are very low-cost. Arduino modules can be
manually assembled in the least expensive version, and even the preassembled modules in Arduino cost
under $50.
• Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux operating
systems. Many devices with microcontrollers are Windows mostly.
• Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for beginners yet
flexible enough for advanced users to take advantage of as well. It's conveniently based on the Processing
programming environment for teachers, so students learning to program in that environment will be
familiar with how the Arduino IDE works.
Robotics Made Simple 74

• Open source and extensible software - The platform is available for expansion by professional
programmers as Open Source Tools. The language can be extended by C++ libraries, meaning that people
who want to know the technical specifics can step from Arduino to the AVR C programming language it
is based on. Similarly, if you wish, you can explicitly connect AVR-C to your Arduino programmes.
• Open source and extensible hardware - Arduino board's plans are released under a Creative Commons
licence, so expert circuit designers can create, expand and enhance their own modules version. In order to
learn how it works and save money, even relatively inexperienced users can create the breadboard module
version.
8.3 TYPES OF ARDUINO BOARDS
Arduino is an outstanding platform for the creation of prototypes and projects, but when you want to choose
the correct board, you can be confusing. Below are some examples of Arduino boards of various kinds. The
boards called Arduino are the official boards, but there are many fantastic clones on the market also. One of
the best arguments for buying a clone is that it is usually cheaper than the official partner.

For eg. Adafruit and Sparkfun offer Arduino board variants that cost less but are of the same standard as
originals. The kind of project you choose to pursue is another consideration to remember when selecting a
board. For, eg. we may want to suggest the LilyPad board from Sparkfun if we want to create a wearable
electronic project. The LilyPad is designed to be quickly sewn into wearable and e-textiles. If our project has a
small form factor, we may wish to use the Arduino Pro Mini, which has a very small footprint relative to other
boards.
8.4 FEATURES OF ARDUINO BOARDS

8.5 POPULAR ARDUINO BOARDS


The Arduino boards list comprises the following
• Arduino Uno(R3)
• LilyPad Arduino
Robotics Made Simple 75

• RedBoard
• Arduino Mega(R3)
• Arduino Leonardo
• Arduino nano

Arduino Uno front and back views


Arduino UNO is the best electronics and coding board to be started. The UNO is the most stable board to start
playing on when its first encounter with the platform. The UNO is the most commonly used and recorded
panel of the entire Arduino family.
Arduino Uno is an ATmega328P-based microcontroller board (datasheet). This system contains 14 digital
input and output pins (6 for PWM output), six analogue inputs, a ceramic 16 MHz resonator
(CSTCE16M0V53-R0), a USB link, a power socket, an ICSP header and a reset button. It provides all the
necessary elements to support the microcontroller; it can be conveniently attached to a USB cable device or
powered by an AC-to-DC adapter and battery. You can tinker with your Uno without worrying too much. You
can change the chip for few bucks and start again in the worst-case scenario.
"Uno" in Italian means one and has been selected as a label for Arduino (IDE) 1.0 updates. Arduino
Software's Uno board and version 1.0 (IDE) have now developed to newer iterations, the Arduino's reference
versions. The Uno board is the first in a series of Arduino USB boards and the Arduino platform's reference
model; the Arduino boards index displays a wide range of existing, past or obsolete boards."
Features of Arduino Uno Board:

Features of Arduino Uno


1. Reset Button – This restarts every Arduino code that is loaded.
2. AREF – stands for "analog references" and is used for describing an external voltage of references.
3. Ground Pin – The Arduino has some base pins, and they all work together.
4. Digital Input/Output – Digital input or output can be used on pins 0-13.
5. PWM – Analog performance can be simulated by the pins labelled with the symbol (~).
6. USB Connection – Used to power up your sketches and upload your Arduino.
7. TX/RX – Data indicator LEDs are Transmit and received.
Robotics Made Simple 76

8. ATmega Microcontroller – This is the brain and the location of the programming.
9. Power LED Indicator – This LED lights up once the board is attached to a power source.
10. Voltage Regulator – This controls the voltage into the Arduino board.
11. DC Power Barrel Jack – This is used for the power supply of your Arduino.
12. 3.3V Pin – This pin provides your projects with 3.3 volts of power.
13. 5V Pin – The pin provides your projects with 5 volts of power.
14. Ground Pins – The Arduino has some base pins, and all of them are the same.
15. Analog Pins – These pins can read and translate the signal from an analog sensor.
LilyPad Arduino Board
Leah Buechley has extended the Lily Pad Arduino board to incorporate an e-Textile technology that has been
considerably developed by "Leah and SparkFun." Each board was built with massive pads and a smooth back
in imagination to be sewn into clothing by conducting thread. This Arduino also includes I/O, control and
sensor boards that are particularly designed for e-textiles. These can even be washed!

LilyPad Arduino Board


RedBoard Arduino Board
The RedBoard Arduino can be programmed with the Arduino IDE using a mini-B USB cable. It runs on
Windows 8 and does not have to adjust your security setting. The USB or FTDI chip is more constant and is
completely flat on the back too. It is really simple to create for the nature of the project. The only plug in the
board, pick the Arduino UNO menu option, and you will have the software uploadable. Using a barrel jack,
you can power the RedBoard via a USB cable.

RedBoard Arduino Board


Arduino Mega (R3) Board
The Arduino Mega is like the big brother of the UNO. This requires several digital I/O pins, including 14 pins
of PWM, six analog inputs, a reset button, a power jack, a USB connection, and a reset button. It requires
everything necessary to carry the microcontroller, connect it to the PC using a USB cable, and start the supply
using an AC-to-DC adapter or battery. The enormous number of pins greatly allows this Arduino board to
design projects involving many digital i/ps or o/ps as many buttons.
Robotics Made Simple 77

Arduino Mega (R3) Board


Arduino Leonardo Board
The Leonardo board is the first developed board for Arduino. This board uses a USB and one
microcontroller. It can be very easy and cost-effective. This board manages USB directly and helps the
programme libraries to navigate the Arduino board on the computer, mouse, etc. This board can be accessed.

Arduino Leonardo Board


Arduino Nano Board
The Arduino has developed the Arduino nano. Cc as one type of microcontroller board. It is available with an
Atmega328 microcontroller. The Arduino UNO is a microcontroller that is compact and usable in different
applications. It also functions with the Arduino Uno. Arduino Mega, Arduino Pro Mini, Arduino UNO,
Arduino YUN, Arduino Lilypad, Arduino Leonardo and Arduino Due are some of the other Arduino boards.
And the AVR Development Board, the PIC Development Board, Raspberry Pi, Intel Edison, MSP430
Launchpad and ESP42 board are all other development boards.
This board has various features, such as a Duemilanove Arduino board. But the packaging of this Nano board
is different. It does not have a DC jack to provide power. Therefore, it can supply through a small USB
socket, otherwise attached directly to VCC and GND pins. This board is available with a micro USB port on
the board with 6 to 20 volts.

Arduino Nano Board


Robotics Made Simple 78

8.6 DIFFERENCE BETWEEN ARDUINO UNO AND ARDUINO NANO


The Arduino Nano board is identical to a UNO board with the same ATMEga328p microcontroller. And they
will enrol in a similar programme—these two are very large in scale. Because Arduino Uno is twice as large
as nano board
s, therefore Uno boards use more machine space. UNO can be programmed using a USB cable, while Nano
uses a micro USB cable. In the following table are listed the key distinctions between the two.
SPECIFICATIONS ARDUINO UNO ARDUINO NANO

Processor ATmega328P ATmega328P

Input Voltage 5V / 7-12V 5V / 7-12V

Speed of CPU 16 MHz 16 MHz

Analog I/O 6/0 8/0

Digital IO/PWM 14/6 14/6

EEPROM/SPAM[kB] 1/2 1/2

Flash 32 32

USN Regular Mini

USART 1 1

8.7 ARDUINO POWER SUPPLY


For the Arduino UNO to work and be driven in a number of ways, the energy source is needed. We will do as
most people do and connect the board directly via a USB cable to your device. If you want a mobile project,
consider using a 9V battery pack to supply it with the input.

Power supply unit


USB cable type A/B.

USB Cable and Its connection to Laptop


Put it on your device to connect Arduino Uno, Arduino Super 2560, Arduino 101 or any USB female port.
The thickness of the cable is around 178cm. As our inventory rotates, cable colour and shape might differ
Robotics Made Simple 79

slowly from an image. Check the cable pinouts guide page on the pinouts.ru, USB cable type A/B, Regular
USB 2.0 cable if you want a better look at the USB cables and the standards.
8.8 ARDUINO UNO ON THE ARDUINO DESKTOP IDE
The Uno is programmed using Arduino Software (IDE), and the Integrated Programming Environment is
common to all Arduino boards because it needs to load Arduino Desktop IDE first.
To programme the board and not simply power it, a USB connection with the PC is necessary. The Uno
receives energy automatically from either the USB or an external power supply. Connect the board via the
USB cable to your computer. The green power LED (PWR marked) is expected to begin.

Data transmission analysis between the computer and Arduino through the USB cable
The compiler compiles and uploads the code to the board setup.

8.9 INSTALLATION OF THE BOARD DRIVERS:


When we've used the Installer, Windows – from XP to 10 – requires us to instal drivers as soon as you
connect your board automatically.
Robotics Made Simple 80

Installing the Arduino drivers under Windows XP


This guide helps you make Uno and Mega2560 function under Window XP after trying to load the operating
system drivers. Please remember, if you have a Mega2560, look for Mega2560 instead of Uno. The screens
were made with an Uno monitor.
Robotics Made Simple 81
Robotics Made Simple 82
Robotics Made Simple 83
Robotics Made Simple 84
Robotics Made Simple 85

8.10 OPEN OF ARDUINO FIRST SKETCH


1. Open the LED blink example sketch: File > Examples >01. Basics > Blink.

2. Select your board type and port: We must select the entry that corresponds to your Arduino board from the
Tools > Board menu.

Select the serial device of the board from the Tools | Serial Port menu. This is actually COM3 or greater
(COM1 and COM2 are usually reserved for hardware serial ports). To figure out, you can unplug your board
and reopen the menu; the Arduino board must be the entry that will vanish. Return to the board and choose the
serial terminal.

3. Compiling program: The compiler compiles and uploads the code to the board configured.
Robotics Made Simple 86

Upload the program: Click the "Upload" button in the environment now. Wait a few seconds - RX and TX
LEDs on a board are expected to flash. The message "Done uploading." will appear in the status bar if the
upload completes.
Robotics Made Simple 87

Just a few seconds after the upload completes, the LED Pin 13 (L) should start to blink on the board (in
orange). If so, Arduino has got up and running. If we have issues, we would see the suggestions for
troubleshooting.
8.11 EXAMPLES OF ARDUINO PROGRAMMING
1. Blink of an LED
The fastest thing you can do to see the physical production is this example of an Arduino or genuino: it blinks
an LED.
Hardware Required
• Arduino or Genuino Board
• LED
• 220-ohm resistor
Circuit
Connect one end of the resistor to the Arduino pin 13 to construct the circuit. Connect the LED's long leg to
the other end of the resistor (the positive leg called the anode). The diagram below connects the short leg
(negative leg, called a cathode) to the Arduino GND.
Many Arduino boards have an LED on the board itself, connected to pin 13. You can see this blink of LED if
you run this example with no hardware on it.
The value in the resistor sequence can be different from 220 ohms with the Lead; even up to 1K ohms can be
seen in the LED.
Robotics Made Simple 88

Code
Start the Arduino software (IDE) and insert the code below after you have plugged the Arduino or Genuino
board into your computer. The File/Examples/01.Basics/Blink menu will load it as well. The first thing you do
is configure pin 13 as a line output pin
pinMode(13, OUTPUT);

You turn the LED on with the line in the main circuit:

This provides pin 13 with 5 volts. This generates and enlightens a voltage difference between the pins of the
LED. You then switch the line off:

digitalWrite(13, LOW);
This pin 13 brings back to 0 volts and disables the LED. You need enough time to see the difference between
the on and off, so Delay() commands tell the board not to do anything for 1000 milliseconds or for a second.
Nothing else occurs for the period of time that you use the Delay() command. Once the basic explanations are
understood, see the Blink Without Delay example about how you create a delay while doing some things.
Once this explanation was grasped, see the DigitalReadSerial example to figure out how to read a switch
attached to the board.

// the setup function runs once when you press reset or power the board
void setup ( ) {
// initialize digital pin 13 as an output.
pinMode ( 13 , OUTPUT ) ;
}
// the loop function runs over and over again forever
void loop ( ) {
digitalWrite ( 13 , HIGH ) ; // turn the LED on (HIGH is the voltage level)
delay ( 1000); // wait for asecond
digitalWrite ( 13 , LOW); // turn the LED off by making the voltageLOW
delay ( 1000); // wait for asecond
}
1. Button On and OFF
Button
Pushbuttons or switches, when you click them, connect two points on a circuit. The built-in LED on pin 13 is
triggered by this example when you push the switch.
Hardware
• Arduino or Genuino Board
• Momentary button or Switch
• 10K ohm resistor
• Hook-up wires
• Breadboard
Robotics Made Simple 89

Circuit

Connect the board to three wires. The first two, black and red, connect on the side of the panel on both long
vertical lines to reach the five volts of supply and ground. The third wire is from the digital pin 2 to a button
leg. The same button leg is joined to the ground by a pulldown resistor (10K ohm here). The other button leg
connects with the supply of 5 volts.
When the push button is open (unpressed), no connection occurs between the two button legs such that the pin
(via the pulldown resistor) is attached to the ground, and a LOW can be read. When the button is pushed, it
attaches its two legs and connects the pin to 5 volts, so HIGH can be read.
You can also wire this circuit the other way around with a pull-up resistor that holds the input HIGH and goes
LOW when pushing the button. If so, the sketch behaviour is reversed, usually with the LED triggered and
switched on, as soon as the button is pressed.
When the wireless I/O pin is disconnected, the LED will be flashing erratically. The input is floating, and it
returns either HIGH or LOW at random. Therefore, a pull-up or down resistor is required in the circuit.
Schematic

Code
// set pin numbers:
const int buttonPin = 2 ; // the number of the pushbuttonpin
const int ledPin = 13 ; // the number of the LED pin

// variables will change:


int buttonState =0 ; // variable for reading the pushbutton status
Robotics Made Simple 90

void setup ( ) {
// initialize the LED pin as an output:
pinMode ( ledPin , OUTPUT ) ;
// initialize the pushbutton pin as an input:
pinMode ( buttonPin , INPUT ) ;
}

void loop ( ) {
// read the state of the pushbutton value:
buttonState = digitalRead ( buttonPin) ;

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if ( buttonState == HIGH ) {
// turn LED on:
digitalWrite ( ledPin , HIGH ) ;
} else {
// turn LED off:
digitalWrite ( ledPin , LOW ) ;
}
}
2. LED Bar Graph
LED Bar Graph
The bar graph, which comprises a set of LEDs as seen on an audio display, is a popular analog sensor
hardware display. It consists of a set of LEDs in a row and a small analog input like a potentiometer. Multi-
LED bar graphs like this can be obtained reasonably cheaply. This tutorial illustrates how to monitor a number
of LEDs in a series but can be used on all digital outputs.
Hardware Required
• Arduino or Genuino Board
• LED bar graph display or 10 LEDs
• Potentiometer
• 10 220 ohm resistors
• hook-up wires
• breadboard
Robotics Made Simple 91

Circuit Schematic:

Code
The sketch works as follows: first, you read the input. In this case, 10 LEDs map the input value to the output
field. Then set up a loop for the outputs to iterate. If the series output number is less than the mapped input,
you trigger it. Otherwise, you can turn it off.
/*
LED bar graph

// these constants won't change:


const int analogPin = A0 ; // the pin that the potentiometer is attached to
const int ledCount =10 ; // the number of LEDs in the bargraph

int ledPins [ ] = {
2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11
} ; // an array of pin numbers to which LEDs are attached

void setup ( ) {
// loop over the pin array and set them all to output:
for ( int thisLed = 0 ; thisLed <ledCount ; thisLed ++ ) {
pinMode ( ledPins [ thisLed ] , OUTPUT) ;
}
}

void loop ( ) {
// read the potentiometer:
int sensorReading = analogRead (analogPin ) ;
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map ( sensorReading , 0 ,1023 , 0 , ledCount ) ;
Robotics Made Simple 92

// loop over the LED array:


for ( int thisLed = 0 ; thisLed <ledCount ; thisLed ++ ) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if ( thisLed < ledLevel ) {
digitalWrite ( ledPins [ thisLed ] ,HIGH ) ;
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite ( ledPins [ thisLed ] ,LOW ) ;
}
}
}
3. Joystick Mouse Control
You can monitor the on-screen cursor with Arduino Leonardo, Micro or Due using the Mouse library. A
pushbutton is used to turn on and off the joystick mouse control in this particular case. The Arduino rotation is
always proportional to the cursor. Thus, the cursor's position in relation to its current position is always
changed every time the analog input is read. There are conversions from two analog inputs, 0 to 1023, in the
range of -12 to 12. The sketch suggests that the rest values are in the centre of the spectrum, but beyond a
threshold, they are different. You can turn on and off the mouse with the pushbutton. You can also attach a
status LED to pin 5, which will light up when Arduino tests the mouse. The other 10k ohm pulldown resistor
(into GND) to D3 can be attached with a second pushbutton to serve as the left mouse click when we use the
command mouse. Move (), the Arduino takes over your device's cursor! Make sure you have a controller in
order until you call the mouse. Move () so we don't lose control of your machine when running an outline of
this feature. This sketch provides a button for the control of the mouse to trigger and deactivate the control of
the mouse.
Hardware Required
• Arduino Leonardo, Micro, or Due board
• 2 axis joystick
• Momentary pushbutton (possibly integrated with the joystick)
• LED
• 220-ohm resistor
• 10k ohm resistor (if needed as pulldown)
Circuit
Connect your Leonardo board with a micro USB cable to your computer. You should connect the pushbutton
with pin 6. You don't need a pulldown resistor by using a component such as a Joystick shield below. The x-
axis is connected to the analog in 0, and the y-axis is on analog in 1.
Robotics Made Simple 93

Schematic

Code
/*
Joystick Mouse Control
*/
#include "Mouse.h" #include "HID.h"
// set pin numbers for switch, joystick axes, and LED:
const int switchPin =2 ;
// switch to turn on and off mouse control const int mouseButton =3 ;
// input pin for the mouse pushButton const int xAxis = A0 ;
// joystick Xaxis
const int yAxis =A1;
// joystick Y axis
const int ledPin =5 ;
// Mouse control LED
// parameters for reading the joystick:
int range =12;
// output range of X or Y movement
int responseDelay =5 ;
// response delay of the mouse, inms
int threshold = range /4;
// resting threshold
int center = range /2;
// resting position value
boolean mouseIsActive =false;
// whether or not to control themouse
int lastSwitchState =LOW;
// previous switchstate
void setup ( ) {
pinMode ( switchPin , INPUT);
// the switchpin
Robotics Made Simple 94

pinMode ( ledPin , OUTPUT);


// the LEDpin
// take control of the mouse:
Mouse. begin ( ) ;
}
void loop ( ) {
// read the switch:
int switchState = digitalRead (switchPin ) ;
// if it's changed and it's high, toggle the mouse state:
if ( switchState != lastSwitchState ){ if ( switchState == HIGH ) { mouseIsActive = ! mouseIsActive ;
// turn on LED to indicate mouse state:
digitalWrite ( ledPin ,mouseIsActive ) ;
}
}
// save switch state for next comparison:
lastSwitchState = switchState ;
// read and scale the two axes: int xReading = readAxis ( A0 ) ; int yReading = readAxis ( A1 ) ;
// if the mouse control state is active, move the mouse:
if ( mouseIsActive ) {
Mouse. move ( xReading , yReading ,0 ) ;
}
// read the mouse button and click or not click:
// if the mouse button is pressed:
if ( digitalRead ( mouseButton ) ==HIGH ) {
// if the mouse is not pressed, press it:
if ( ! Mouse. isPressed ( MOUSE_LEFT) ) { Mouse. press ( MOUSE_LEFT ) ;
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if ( Mouse. isPressed ( MOUSE_LEFT )) { Mouse. release ( MOUSE_LEFT ) ;
}
}
delay ( responseDelay ) ;
}

/*
reads an axis (0 or 1 for x or y) and scales the analog input range to a range from 0 to <range>
*/
int readAxis ( int thisAxis ) {
// read the analog input:
int reading = analogRead ( thisAxis );
// map the reading from the analog input range to the output range:
reading = map ( reading , 0 , 1023 , 0, range ) ;

// if the output reading is outside from the


// rest position threshold, use it:
int distance = reading - center ;
Robotics Made Simple 95

if ( abs ( distance ) < threshold ) {


distance = 0 ;
}
// return the distance for this axis:
return distance ;
}
3. Interface LCD (Liquid Crystal Display) Using an Arduino
This circuit diagram displays the Arduino Module liquid crystal display. The circuit diagram shows that the
LCD RS pin is connected to the Arduino pin 12. The LCD is connected to the ground by the R/W pin. Pin 11
is connected to the LCD module's enabled signal pin. This project interfaced with the 4-bit mode of the LCD
module & Arduino. 4 input lines are LCD's DB4 to DB7. This method is very easy and requires less cable
connection, and we can also use the most potential of the LCD module.
DB4-DB7 is a digital input line that is connected to the 5-2 Arduino pins. We use a 10K potentiometer to
adjust the contrast of the monitor in this situation. The current around the LED backlight is from the resistor
of 560 ohms. The external power jack is supplied to the Arduino by the pin. The Arduino can operate the PC
via the USB connector. Any parts of the circuit may need 05V of power to be supplied on the Arduino board
from the 5V source.
Circuit

Schematic
Robotics Made Simple 96

Code:

4. Arduino 7 Segment Display Interface


This project involves learning about 7 Segment Displays and the functioning of the Arduino 7 Segment
Display Interface. 7 Segment Display is one of the simplest display devices which can be connected with
Arduino or any microcontroller. A basic seven segment display is appropriate for many applications. There
are many display devices, including alphanumeric LCD, graphic LCD, touch panel, etc. Tools such as a
washing machine, microwave ovens etc., also use seven segment displays to present details such as quantity
and time. The biggest reason is the simple and inexpensive interface. If your project requires only displaying
numbers, your safe bet would be a 7-segment display instead of the costly 16×2 LCD display.

A Brief Introduction to 7 Segment Display


A 7 Segment Display is a simple device. It consists of 7 LEDs called arranged in Segments. Hence, the name
7 Segment Display. Each LED segment is in the shape of a hexagon, and all the 7 LEDs are arranged in an "8"
like fashion so that it can display digits from 0 to9.
Considering the internal structure of a Common Anode 7 Segment Display, i.e. how the LEDs are connected.

We will observe that all LED anodes are connected together, and all cathodes are left open. For the activation
of a segment, the typical terminal is connected with the supply +ve (positive), and a particular segment will
light up when any cathode connection is made to the –ve (negative).
NOTE: The common terminal would be Cathode, which has to be connected with GND in the case of
Common Cathode 7 Segment Display.
Robotics Made Simple 97

Now let's look at the pin map of the 7 Segment Display Common Anode. The picture below shows a basic
regular display with seven segments. There are 10 pins in it.

The top five pins are "g,""f,""COM,""a" and "b," and the lowest five pins are: "e" and "d," and "COM," and
"c" and 'dp.' As this is a common anode display, the VCC is connected to the COM (common pin).
NOTE: The same configuration of the pin will be used for a common cathode 7 segment display. However,
the COM pin will be connected to the GND.
You must enable those segments on each digit to display digits from 0 to 9 on this display of the 7 segments.
The table below displays the list of segments to be activated in order to display a certain number.

The table above can be helpful when Arduino or some other microcontroller is programmed.
Now we saw about a 7 segment display; let's see how to interface a typical 7 segment anode to an Arduino.
Simple Arduino 7 Segment Display Interface
I can show you on the first circuit how a common anode 7 segment display is connected to Arduino UNO, and
the numbers from 0 to 9 are shown in one loop. This summary describes the circuit diagram, modules, code
and operation.
Circuit Diagram
Robotics Made Simple 98

Components Required
• Arduino UNO
• 7 segment display
• 7 x 220Ω Resistors (1/4Watt)
• Breadboard
• Power Supply
• Connecting Wires
NOTE: When applying the actual limiting resistors, I did not connect them to the individual LEDs in the 7
Segment Display. But I suggest that you connect those resistors.
Code
//e =2;
//d =3;
//c =4;
//g = 5;

//f =6;
//a =7;
//b =8;
int
num[10][7]={{0,0,0,1,0,0,0},
{1,1,0,1,1,1,0},
{0,0,1,0,1,0,0},
{1,0,0,0,1,0,0},
{1,1,0,0,0,1,0},
{1,0,0,0,0,0,1},
{0,0,0,0,0,1,1},
{1,1,0,1,1,0,0},
{0,0,0,0,0,0,0},
{1,0,0,0,0,0,0}
};
voidsetup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
void loop()
Robotics Made Simple 99

{
for(inti=0;i<10;i++)
{
for(intj=0;j<7;j++)
{
digitalWrite(j+2,num[i][j]);
}
delay(1000);
}
}
Working
The Arduino 7 segment interface is explained by a basic sketch. The Arduino is connected to the 7 segment
pins as follows.
• a – Arduino Pin7
• b – Arduino Pin8
• c – Arduino Pin4
• d – Arduino Pin3
• e – Arduino Pin2
• f – Arduino Pin6
• g – Arduino Pin5
Since this project has a common anode style display of the 7 Segment Display, the common pin is connected
to Arduino pin nine and often is made HIGH.
The corresponding Arduino Pin must be LOW to enable a certain segment, for example, segment "a." The 'a'
section is connected here with Arduino pin 7. Likewise, LOW can be rendered for other segments, and a digit
can be shown on the 7 Segment Display according to the table above, based on the chosen segments.
Rolling Dice using Arduino and 7 Segment Display
We will use the second circuit button to display a random number between 1 and 6, where A rolling dice
feature will be implemented.
Circuit Diagram

Components Required
• Arduino UNO
• 7 segment display
• Pushbutton
• 7 x 220Ω Resistors (1/4Watt)
• Breadboard
Robotics Made Simple 100

• Power Supply
• Connecting Wires
NOTE: I did not connect the current limiting resistors to the individual LEDs of the 7 Segment display during
realistic implementation. But I suggest connecting these resistors.
Code
//e =
2;
//d =3;
//c =4;
//g =5;
//f =6;
//a =7;
//b =8;
int num[10][7]={{0,0,0,1,0,0,0},
{1,1,0,1,1,1,0},
{0,0,1,0,1,0,0},
{1,0,0,0,1,0,0},
{1,1,0,0,0,1,0},
{1,0,0,0,0,0,1},
{0,0,0,0,0,1,1},
{1,1,0,1,1,0,0},
{0,0,0,0,0,0,0},
{1,0,0,0,0,0,0}
};
longr_num;
int roll =12;
bool state =true;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(12,INPUT_PULLUP);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
randomSeed(analogRead(0));
}
void loop()
Robotics Made Simple 101

{
if(state)
{
r_num=random(1,6);
for(inti=0;i<7;i++)
{
digitalWrite(i+2,num[r_num][i]);
}
//delay(1500);
state=false;
}
while(digitalRead(roll)==LOW)
{
for(inti=0;i<10;i++)
{
for(intj=0;j<7;j++)
{
digitalWrite(j+2,num[i][j]);
}
delay(50);
}
state=true;
}
}
Working
The project functions in the same manner as the above project, but a Push Button is additionally interfaced
with Arduino. You will see Arduino displaying numbers from 0 to 9 when the button is pressed. When the
button is released, the output of the 7 Segment displays a random number between 1 and 6.
Applications
• You can easily view numbers from 0 to 9 using the Arduino 7 Segment display Interface.
• This can be used on large projects, such as an item counter, alarm clock, digital clock, timer circuit, etc.
Arduino 4-Digit 7-Segment LED display
In many implementations, LED segment displays are used to indicate the front panel number. Calculators,
microwave ovens, electrical devices, including feature generators and frequency counters, are the most
common applications.
Robotics Made Simple 102

A 7 segments LED display is comprised of 7 LEDs grouped so that numbers from 0 to 9 can be displayed. A
4-digit 7-segment LED display can be used to display Arduino numbers using either a small module that
includes four 7-segment LED displays. Or four separate 7-segment displays can be used through the
multiplexing of them. The LED displays can be used in this project.
Circuit Diagram

Components Required
• Arduino UNO —1
• 4 – Digit compact 7 – segment LED display — 1(Or)7 – Segment LED display —4
• BC547 —4
• 1KΩ —4
• 100Ω — 4
A 7 – LED display section, as the name suggests, includes the LED bar assembly that allows each bar to be
independently powered. Each LED bar is in the shape of a hexagon, and the overall arrangement is in the form
'8.'
Code
#define duration 5000
#define A2
#define B3
#define C4
#define D5
#define E6
#define F7
#define G8
#define DP9
#define disp110
#define disp211
Robotics Made Simple 103

#define disp312
#define disp4 13
#define numbersegments {\
{1,1,1,1,1,1,0,0},\
{0,1,1,0,0,0,0,0},\
{1,1,0,1,1,0,1,0},\
{1,1,1,1,0,0,1,0},\
{0,1,1,0,0,1,1,0},\
{1,0,1,1,0,1,1,0},\
{1,0,1,1,1,1,1,0},\
{1,1,1,0,0,0,0,0},\
{1,1,1,1,1,1,1,0},\
{1,1,1,0,0,1,1,0},\
}
byte numbers[10][8] =numbersegments;
const int segments[8] = {A, B, C, D, E, F, G, DP};
void setup()
{
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
pinMode(E,OUTPUT);
pinMode(F,OUTPUT);
pinMode(G,OUTPUT);
pinMode(DP, OUTPUT);

pinMode(disp1,OUTPUT);
pinMode(disp2,OUTPUT);
pinMode(disp3,OUTPUT);
pinMode(disp4,OUTPUT);
digitalWrite(A, LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F,LOW);
digitalWrite(G, LOW);
digitalWrite(DP,LOW);
digitalWrite(disp1,LOW);
digitalWrite(disp2,LOW);
digitalWrite(disp3,LOW);
digitalWrite(disp4,LOW);
}
void loop()
{
for (int digit4=0; digit4<10;digit4++)
{
for (int digit3=0; digit3<10;digit3++)
{
for (int digit2=0; digit2<10; digit2++)
{
for (int digit1=0; digit1<10; digit1++)
{
Robotics Made Simple 104

for (int t=0; t<30; t++)


{
setsegments(digit1, disp1, duration);
setsegments(digit2, disp2, duration);
setsegments(digit3, disp3, duration);
setsegments(digit4, disp4, duration);
}
}
}
}
}
}
void set segments(int number, int digit, into time)
{
for (int seg=0; seg<8;seg++)
{
if(numbers[number][seg]==1)
{
digitalWrite(segments[seg],HIGH);
}
else
{
digitalWrite(segments[seg],LOW);
}
}
digitalWrite(digit,HIGH);
delayMicroseconds(ontime);
digitalWrite(digit,LOW);
}

You might also like