Sunteți pe pagina 1din 17

EMBEDDED SYSTEMS Enroll No.

1719MECE30011

PRACTICAL- 01
AIM: Introduction of Arduino kit with reference to embedded system

Introduction

Arduino is an open-source platform used for building electronics projects. Arduino consists of both
a physical programmable circuit board (often referred to as a microcontroller) and a piece
of software, or IDE (Integrated Development Environment) that runs on your computer, used to
write and upload computer code to the physical board.

The Arduino platform has become quite popular with people just starting out with electronics, and
for good reason. Unlike most previous programmable circuit boards, the Arduino does not need a
separate piece of hardware (called a programmer) in order to load new code onto the board – you
can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++,
making it easier to learn to program. Finally, Arduino provides a standard form factor that breaks
out the functions of the micro-controller into a more accessible package.

Figure. Arduino Uno tool kit


Arduino Hardware

The Arduino board is where the code you write is executed. The board can only control and
respond to electricity, so specific components are attached to it to enable it to interact with the real
world. These components can be sensors, which convert some aspect of the physical world to
electricity so that the board can sense it, or actuators, which get electricity from the board and
convert it into something that changes the world. Examples of sensors include switches,

MECE (2nd Sem) LDRP-ITR 1


EMBEDDED SYSTEMS Enroll No.1719MECE30011

accelerometers, and ultrasound distance sensors. Actuators are things like lights and LEDs,
speakers, motors, and displays.

Arduino Software
Software programs, called sketches, are created on a computer using the Arduino integrated
Development environment (IDE). The IDE Enables you to write and edit code and convert this
code into instructions that Arduino Hardware understands. The IDE Also transfers those
instructions to the Arduino board (a process called uploading).

Figure. Screenshot of the Arduino IDE.

The Uno is one of the more popular boards in the Arduino family and a great choice for beginners.

e.g. Believe it or not, those 10 lines of code are all you need to blink the on-board LED on your
Arduino. The code might not make perfect sense right now, but, after reading this tutorial and the
many more Arduino tutorials waiting for you on our site, we’ll get you up to speed in no time!

What does it do?

The Arduino hardware and software was designed for artists, designers, hobbyists, hackers,
newbies, and anyone interested in creating interactive objects or environments. Arduino can
interact with buttons, LEDs, motors, speakers, GPS units, cameras, the internet, and even your
smart-phone or you’re TV! This flexibility combined with the fact that the Arduino software is free,
the hardware boards are pretty cheap, and both the software and hardware are easy to learn has led
to a large community of users who have contributed code and released instructions for
a huge variety of Arduino-based projects.

MECE (2nd Sem) LDRP-ITR 2


EMBEDDED SYSTEMS Enroll No.1719MECE30011

What's on the board?

There are many varieties of Arduino boards that can be used for different purposes. Most Arduinos
have the majority of these components in common:

Power (USB / Barrel Jack)

Every Arduino board needs a way to be connected to a power source. The Arduino UNO can be
powered from a USB cable coming from your computer or a wall power supply that is terminated
in a barrel jack. In the picture above the USB connection is labeled (1) and the barrel jack is
labeled (2).

The USB connection is also how you will load code onto your Arduino board. More on how to
program with Arduino can be found in our Installing and Programming Arduino tutorial.

NOTE: Do NOT use a power supply greater than 20 Volts as it will overpower (and thereby
destroy) the Arduino board. The recommended voltage for most Arduino models is between 6 and
12 Volts.

Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)

The pins on your Arduino are the places where you connect wires to construct a circuit (probably in
conjunction with a bread board and some wire. They usually have black plastic ‘headers’ that allow
you to just plug a wire right into the board. The Arduino has several different kinds of pins, each of
which is labeled on the board and used for different functions.

MECE (2nd Sem) LDRP-ITR 3


EMBEDDED SYSTEMS Enroll No.1719MECE30011

 GND (3): Short for ‘Ground’. There are several GND pins on the Arduino, any of which
can be used to ground your circuit.
 5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and the 3.3V
pin supplies 3.3 volts of power. Most of the simple components used with the Arduino run
happily off of 5 or 3.3 volts.
 Analog (6): The area of pins under the ‘Analog In’ label (A0 through A5 on the UNO) are
Analog In pins. These pins can read the signal from an analog sensor (like a temperature
sensor) and convert it into a digital value that we can read.
 Digital (7): Across from the analog pins are the digital pins (0 through 13 on the UNO).
These pins can be used for both digital input (like telling if a button is pushed) and digital
output (like powering an LED).
 PWM (8): You may have noticed the tilde (~) next to some of the digital pins (3, 5, 6, 9, 10,
and 11 on the UNO). These pins act as normal digital pins, but can also be used for
something called Pulse-Width Modulation (PWM). We have a tutorial on PWM, but for
now, think of these pins as being able to simulate analog output (like fading an LED in and
out).
 AREF (9): Stands for Analog Reference. Most of the time you can leave this pin alone. It is
sometimes used to set an external reference voltage (between 0 and 5 Volts) as the upper
limit for the analog input pins.

Reset Button

Just like the original Nintendo, the Arduino has a reset button (10). Pushing it will temporarily
connect the reset pin to ground and restart any code that is loaded on the Arduino. This can be very
useful if your code doesn’t repeat, but you want to test it multiple times. Unlike the original
Nintendo however, blowing on the Arduino doesn’t usually fix any problems.

Power LED Indicator

Just beneath and to the right of the word “UNO” on your circuit board, there’s a tiny LED next to
the word ‘ON’ (11). This LED should light up whenever you plug your Arduino into a power
source. If this light doesn’t turn on, there’s a good chance something is wrong. Time to re-check
your circuit!

TX RX LEDs

TX is short for transmit, RX is short for receive. These markings appear quite a bit in electronics to
indicate the pins responsible for serial communication. In our case, there are two places on the
Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a second time next to
the TX and RX indicator LEDs (12). These LEDs will give us some nice visual indications
whenever our Arduino is receiving or transmitting data (like when we’re loading a new program
onto the board).

MECE (2nd Sem) LDRP-ITR 4


EMBEDDED SYSTEMS Enroll No.1719MECE30011

Main IC

The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think of it as the brains
of our Arduino. The main IC on the Arduino is slightly different from board type to board type, but
is usually from the ATmega line of IC’s from the ATMEL Company. This can be important, as you
may need to know the IC type (along with your board type) before loading up a new program from
the Arduino software. This information can usually be found in writing on the top side of the IC. If
you want to know more about the difference between various IC’s, reading the datasheets is often a
good idea.

Voltage Regulator

The voltage regulator (14) is not actually something you can (or should) interact with on the
Arduino. But it is potentially useful to know that it is there and what it’s for. The voltage regulator
does exactly what it says – it controls the amount of voltage that is let into the Arduino board.
Think of it as a kind of gatekeeper; it will turn away an extra voltage that might harm the circuit. Of
course, it has its limits, so don’t hook up your Arduino to anything greater than 20 volts.

MECE (2nd Sem) LDRP-ITR 5


EMBEDDED SYSTEMS Enroll No.1719MECE30011

PRACTICAL- 02

AIM: Perform LED ON Without Delay


Sometimes you need to do two things at once. For example you might want to blink an LED while
reading a button press. In this case, you don't want to use delay(), because Arduino pauses your
program during the delay(). If the button is pressed while Arduino is paused waiting for the delay()
to pass, your program will miss the button press.

This sketch demonstrates how to blink an LED without using delay(). It turns on the LED on and
then makes note of the time. Then, each time through loop(), it checks to see if the desired blink
time has passed. If it has, it toggles the LED on or off and makes note of the new time. In this way
the LED blinks continuously.
Hardware Required

 Arduino Board
 LED
 Resistor, anything between 220 ohm to 1K ohm

MECE (2nd Sem) LDRP-ITR 6


EMBEDDED SYSTEMS Enroll No.1719MECE30011

Circuit

To build the circuit, connect one end of the resistor to Arduino pin 13. Connect the long leg of the
LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the
LED (the negative leg, called the cathode) to the Arduino GND, as shown in the diagram above and
the schematic below.

Most Arduino boards already have an LED attached to pin 13 on the board itself. If you run this
example with no hardware attached, you should see that LED blink.

Schematic:

After you build the circuit plug your Arduino board into your computer, start the Arduino IDE, and
enter the code below.

Source Code

The code below uses the millis() function, a command that returns the number of milliseconds since
the Arduino board started running its current program, to blink an LED.

MECE (2nd Sem) LDRP-ITR 7


EMBEDDED SYSTEMS Enroll No.1719MECE30011

/* Blink LED without Delay

Turns on and off a light emitting diode(LED) connected to a digital pin, without using the delay()
function. This means that other code can run at the same time without being interrupted by the
LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board that's attached to pin 13,
so no hardware is needed for this example.

// set pin numbers:


const int ledPin = 13; // the number of the LED pin

// Variables will change:


int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,


// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)

void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {


// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:


if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

// set the LED with the ledState of the variable:


digitalWrite(ledPin, ledState);
}
}

MECE (2nd Sem) LDRP-ITR 8


EMBEDDED SYSTEMS Enroll No.1719MECE30011

PRACTICAL- 03

AIM: Driving a 7-Segment numerical Display


The following sketch displays numerals from zero to nine on a single-digit, 7-segment display.
Figure shows the connections. The output is produced by turning on combinations of segments that
represent the numerals:

Figure. Connecting a 7-segment display


Source Code
/* SevenSegment sketch , Shows numerals ranging from 0 through 9 on a single-digit display ,
This example counts seconds from 0 to 9 */
// bits representing segments A through G (and decimal point) for numerals 0-9
const byte numeral[10] = {
//ABCDEFG /dp
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4

MECE (2nd Sem) LDRP-ITR 9


EMBEDDED SYSTEMS Enroll No.1719MECE30011

B10110110, // 5
B00111110, // 6
B11100000, // 7
B11111110, // 8
B11100110, // 9
};
// pins for decimal point and each segment
// dp,G,F,E,D,C,B,A
const int segmentPins[8] = { 5,9,8,7,6,4,3,2};
void setup()
{
for(int i=0; i < 8; i++)
{
pinMode(segmentPins[i], OUTPUT); // set segment and DP pins to output
}
}
void loop()
{
for(int i=0; i <= 10; i++)
{
showDigit(i);
delay(1000);
}
// the last value if i is 10 and this will turn the display off
delay(2000); // pause two seconds with the display off
}
// Displays a number from 0 through 9 on a 7-segment display
// any value not within the range of 0-9 turns the display off
void showDigit( int number)
{
boolean isBitSet;
for(int segment = 1; segment < 8; segment++)
{
if( number < 0 || number > 9){
isBitSet = 0; // turn off all segments
}
Else
{
// isBitSet will be true if given bit is 1
isBitSet = bitRead(numeral[number], segment);
}
isBitSet = ! isBitSet; // remove this line if common cathode display
digitalWrite( segmentPins[segment], isBitSet);
}
}
MECE (2nd Sem) LDRP-ITR 10
EMBEDDED SYSTEMS Enroll No.1719MECE30011

Discussion
The segments to be lit for each numeral are held in the array called numeral. There is one byte per
numeral where each bit in the byte represents one of seven segments (or the decimal point). The
array called segmentPins holds the pins associated with each segment. The showDigit function
checks that the number ranges from zero to 9, and if valid, looks at each segment bit and turns on
the segment if the bit is set (equal to 1).

a pin is set HIGH when turning on a segment on a common cathode display, and it’s set LOW
when turning on a segment on a common anode display.

The code here is for a common anode display, so it inverts the value (sets 0 to1 and 1 to 0) as
follows:

isBitSet = ! isBitSet; // remove this line if common cathode display

MECE (2nd Sem) LDRP-ITR 11


EMBEDDED SYSTEMS Enroll No.1719MECE30011

PRACTICAL- 04

AIM: Generate Pattern by Running LEDs using PWM


We want to control one or more LEDs and select the correct current-limiting resistor so that you do
not damage the LEDs. Generate require pattern of running LEDs by using PWM

Figure: wiring for three LEDs

Turning an LED on and off is easy to do with Arduino, and some of the recipes in previous
chapters have included this capability (see Recipe 5.1 for an example that controls the built-in LED
on pin 13).

The recipe here provides guidance on choosing and using external LEDs.

The following sketch lights up three LEDs connected to pins 3, 5, and 6 in sequence for one
second. We will write code for six LEDs and generate forward & backward running pattern

The sketch sets the pins connected to LEDs as output in the setup function. The loop function calls
blinkLED to flash the LED for each of the three pins. blinkLED sets the indicated pin HIGH for
one second (1,000 milliseconds).

Source Code
/*
LEDs sketch
Blink three LEDs each connected to a different digital pin
*/
const int firstLedPin = 3; // choose the pin for each of the LEDs

MECE (2nd Sem) LDRP-ITR 12


EMBEDDED SYSTEMS Enroll No.1719MECE30011

const int secondLedPin = 5;


const int thirdLedPin = 6;
const int fourthLedPin = 9; // choose the pin for each of the LEDs
const int fifthLedPin =10;
const int sixthLedPin = 11;

void setup()
{
pinMode(firstLedPin, OUTPUT); // declare LED pins as output
pinMode(secondLedPin, OUTPUT); // declare LED pins as output
pinMode(thirdLedPin, OUTPUT); // declare LED pins as output
pinMode(fourthLedPin, OUTPUT); // declare LED pins as output
pinMode(fifthLedPin, OUTPUT); // declare LED pins as output
pinMode(sixthLedPin, OUTPUT); // declare LED pins as output
}
void loop()
{
// flash each of the LEDs for 1000 milliseconds (1 second)
blinkLED(firstLedPin, 100);
blinkLED(secondLedPin, 100);
blinkLED(thirdLedPin, 100);
blinkLED(fourthLedPin, 100);
blinkLED(fifthLedPin, 100);
blinkLED(sixthLedPin, 100);
}
void blinkLED(int pin, int duration)
{
digitalWrite(pin, HIGH); // turn LED on
delay(duration);
digitalWrite(pin, LOW); // turn LED off
delay(duration);
}

Discussion

Because the anodes are connected to Arduino pins and the cathodes are connected to ground, the
LEDs will light when the pin goes HIGH and will be off when the pin is low. If you had connected
the LEDs the other way around (the cathodes to the pins and the anodes to ground), the LEDs
would light when the pin goes LOW (the visual effect would reverse—one of the LEDs would turn
off for a second while the other two would be lit). LEDs require a series resistor to control the
current or they can quickly burn out. The built-in LED on pin 13 has a resistor on the circuit board.
External LEDs need to be connected through a series resistor on either the anode or the cathode.

MECE (2nd Sem) LDRP-ITR 13


EMBEDDED SYSTEMS Enroll No.1719MECE30011

A resistor in series with the LED is used to control the amount of current that will flow when the
LED conducts. To calculate the resistor value you need to know the input power supply voltage
(Vs, usually 5 volts), the LED forward voltage (Vf), and the amount of current (I) that you want to
flow through the LED.

MECE (2nd Sem) LDRP-ITR 14


EMBEDDED SYSTEMS Enroll No.1719MECE30011

PRACTICAL-05

AIM: Displaying a Text on LCD Display


We have a text LCD based on the industry-standard HD44780 or a compatible controller chip, and
we want to display text or numeric values.

The Arduino software includes the LiquidCrystal library for driving LCD displays based on the
HD44780 chip

(Most text LCDs supplied for use with Arduino will be compatible with the Hitachi HD44780
controller. If you are not sure about your controller, check the data sheet to see if it is a 44780 or
compatible.)

To get the display working, you need to wire the power, data, and control pins. Connect the data
and status lines to digital output pins, and wire up a contrast potentiometer and connect the power
lines. If your display has a backlight, this needs connecting, usually through a resistor. Figure
shows the most common LCD connections. It’s important to check the data sheet for your LCD to
verify the pin connections. Table shows the most common pin connections, but if your LCD uses
different pins, make sure it is compatible with the Hitachi HD44780—this recipe will only work on
LCD displays that are compatible with that chip. The LCD will have 16 pins (or 14 pins if there is
no backlight) make sure you identify pin 1 on your panel; it may be in a different position than
shown in the figure

Figure. Connections for a text Display on LCD

Table:

MECE (2nd Sem) LDRP-ITR 15


EMBEDDED SYSTEMS Enroll No.1719MECE30011

LCD pin Function Arduino pin


1 Gnd or 0V or Vss Gnd
2 +5V or Vdd 5V
3 Vo or contrast
4 RS 12
5 R/W
6 E 11
7 D0
8 D1
9 D2
10 D3
11 D4 5
12 D5 4
13 D6 3
14 D7 2
15 A or analog
16 K or cathode
Source Code
/*
LiquidCrystal Library – displaying a Text
Demonstrates the use of a 16 × 2 LCD display.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
#include <LiquidCrystal.h> // include the library code
//constants for the number of rows and columns in the LCD
const int numRows = 2;
const int numCols = 16;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(numCols, numRows);
lcd.print("LDRP STAFF!"); // Print a message to the LCD.
}
void loop()
{

// set the cursor to column 0, line 1


MECE (2nd Sem) LDRP-ITR 16
EMBEDDED SYSTEMS Enroll No.1719MECE30011

// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
Run the sketch; you should see “LDRP STAFF” displayed on the first line of your LCD. The
second line will display a number that increases by one every second.

Discussion

If you don’t see any text and you have double-checked that all wires are connected correctly, you
may need to adjust the contrast pot. With the pot shaft rotated to one side (usually the side
connected to Gnd), you will have maximum contrast and should see blocks appear in all the
character positions. With the pot rotated to the other extreme, you probably won’t see anything at
all. The correct setting will depend on many factors, including viewing angle and temperature—
turn the pot until you get the best looking display.

MECE (2nd Sem) LDRP-ITR 17

S-ar putea să vă placă și