Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Experiment-9

Aim: Introduction to Embedded system based application.

Apparatus: Arduino Board, LED, Potentiometer, Arduino software (IDE), USB cable, resistor,
bread board and Jumper wires.

Introduction

Arduino Leonardo is the addition to the Arduino family with added feature and new
functionalities. The microcontroller used on this board is ATmega32u4 instead of ATmega328 on
older version boards such as Arduino Uno. This board is equipped with more digital pins, PWM
pins and analog pins. The ATmega32u4 has built-in USB communication which eliminates the
need for a secondary processor to handle USB communication. The USB connection may be
confusing for the beginners. Every time you reset the board, the Leonardo’s USB serial connection
will be broken and re-established which may have implications for driver installation, uploading,
and communication.
Department of Electronics & Communication Engineering

Arduino IDE

Arduino IDE is the software tool needed to write sketch (code), and load into the Arduino main
board. This is the Arduino IDE:

Connect the micro B type end of USB cable to Arduino Leonardo, and the other end to the
computer/laptop USB port. Arduino Leonardo will automatically use the power from USB to start
up. The green LED (ON) on Arduino Leonardo should be ON and Red LED (L) will. 1st time user,
need to install the USB driver for communication. After the computer reboot plug the computer
through the USB cable, where the green LED is ON. Make sure the Arduino Leonardo is
connected to computer with the USB cable. Arduino IDE support many Arduino main board,
including Leonardo . We will need to select the correct board and microcontroller.
Goto Tools -> Board -> Arduino Leonardo, Click it.

1
Department of Electronics & Communication Engineering

Now, make sure Arduino IDE knows which COM Port the Arduino Leonardo is connected to.
Goto Tools -> Serial Port -> COM, The number might be different when different USB port, is
used. change different Arduino board and different computer.

The settings will appear at the bottom right corner of Arduino IDE.

2
Department of Electronics & Communication Engineering

Now, load the 1st example code, Blinking Goto File -> Examples -> Basic -> Blink, click it. The
example sketch/program will appear in a new Arduino IDE window.

Click the upload icon, Arduino IDE will compile the sketch and upload into Arduino Leonardo
connected to computer (if there is no error), further run the sketch on Arduino Leonardo. Wait
until the message box say Upload Done and look at the Arduino Leonardo. The red LED will

3
Department of Electronics & Communication Engineering

Blink at 1 second rate.

Now make the changes. Scroll down the program/sketch, in the loop function. Modify the value
from delay(1000) to delay(100), for both the delay. Click on the Uploadicon and sit back, wait
until it is done uploading.

4
Department of Electronics & Communication Engineering

Now, look at the Red LED blinking rate, it has become faster
 
Multi function shield

Features

5
Department of Electronics & Communication Engineering

4 digit 7-segment LED display module driven by two serial 74HC595’s


4 LED’s
10K potentiometer
3 x push buttons
Piezo buzzer
DS18B20 temperature sensor interface (not included)
Infrared receiver interface
Serial interface header for connection to serial modules

1. ALL LEDs BLINKING


int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
 
void setup()
{
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
 
void loop()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(1000);
}

1. SWITCHES EXAMPLE
const byte LED[] = {13,12,11,10};
 
#define BUTTON1 A1
#define BUTTON2 A2
 
void setup()
{
// initialize the digital pin as an output.

6
Department of Electronics & Communication Engineering

/* Set each pin to outputs */


pinMode(LED[0], OUTPUT);
pinMode(LED[1], OUTPUT);
pinMode(LED[2], OUTPUT);
pinMode(LED[3], OUTPUT);
}
 
void loop()
{
if(!digitalRead(BUTTON1))
{
digitalWrite(LED[0], HIGH);
digitalWrite(LED[1], HIGH);
digitalWrite(LED[2], HIGH);
digitalWrite(LED[3], HIGH);
}
 
if(!digitalRead(BUTTON2))
{
digitalWrite(LED[0], LOW);
digitalWrite(LED[1], LOW);
digitalWrite(LED[2], LOW);
digitalWrite(LED[3], LOW);
}
}

2. Pot and LED


const byte LED[] = {13,12,11,10};
#define Pot1 0
 
void setup()
{
Serial.begin(9600);
// initialize the digital pin as an output.
/* Set each pin to outputs */
pinMode(LED[0], OUTPUT);
pinMode(LED[1], OUTPUT);
pinMode(LED[2], OUTPUT);
pinMode(LED[3], OUTPUT);
}
 
/* Main Program */
void loop()
{
int PotValue;
//Serial.print(“Potentiometer reading: “);
PotValue = analogRead(Pot1);
/* Wait 0.5 seconds before reading again */
if(PotValue < 400)
{

7
Department of Electronics & Communication Engineering

digitalWrite(LED[0], LOW);
digitalWrite(LED[1], LOW);
digitalWrite(LED[2], LOW);
digitalWrite(LED[3], LOW);
Serial.print(“Potentiometer: “);
Serial.println(PotValue);
}
else
{
digitalWrite(LED[0], HIGH);
digitalWrite(LED[1], HIGH);
digitalWrite(LED[2], HIGH);
digitalWrite(LED[3], HIGH);
Serial.print(“Potentiometer: “);
Serial.println(PotValue);
}
delay(500);
}

digitalWrite(LATCH_DIO,HIGH);
}

Excercises:9 (A)
1. What is the need of IDE in Arduino based design?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

2. Mention the steps to perform the code with Arduino board.

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

8
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

3. Encircle and list the different part of Arduino board in following figure

______________________________________________________________________________

______________________________________________________________________________

9
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

4. Explain the need of potentiometer in delay controlled process using Arduino

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

5. Write a code to blink specific LED with fix delay time when specific push button is pressed.

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

10
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

6. Write a code below for blink LED with varying delay time using potentiometer with comment
of each line

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

11
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

Experiment-9 (b)

Aim: Implement a control of servomotor using Arduino.

Because servo motors use feedback to determine the position of the shaft, you can control
that position very precisely. As a result, servo motors are used to control the position of objects,
rotate objects, move legs, arms or hands of robots, move sensors etc. with high precision. Servo
motors are small in size, and because they have built-in circuitry to control their movement, they
can be connected directly to an Arduino.  

Most servo motors have the following three connections: 

Black/Brown ground wire. 

Red power wire (around 5V). 

Yellow or White PWM wire.

In this experiment, the power and ground pins directly connect to the Arduino 5V and GND pins.
The PWM input will be connected to one of the Arduino's digital output pins.

Specification

12
Department of Electronics & Communication Engineering

9G servo: SG90Servo

Potentiometer:

Resistance Value: 10K ohm;

Adjustment Type: Top Adjustment

Pin Definition for 9G Servo

Hardware Required

Connection Diagram

13
Department of Electronics & Communication Engineering

IDE Code

#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and
1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

14
Department of Electronics & Communication Engineering

Excercises: 9 (b)
1. What is the use of servo motor?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

2. Mention the different connection of servo motor with Arduino board.

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

3. List out the hardware require to implement the servo motor control

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

15
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

4. Explain the need of potentiometer in controlled process of servo motor using Arduino

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

5. Write a code below for servo motor control with comment of each line

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

16
Department of Electronics & Communication Engineering

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

17

You might also like