MES Module 5
MES Module 5
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
• RedBoard
• Arduino Mega(R3)
• Arduino Leonardo
• Arduino nano
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!
Flash 32 32
USART 1 1
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.
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
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) ;
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
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
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
/*
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 ) ;
Schematic
Robotics Made Simple 96
Code:
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