0% found this document useful (0 votes)
413 views50 pages

Experiment Book 2010 Final

Uploaded by

Mayur Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
413 views50 pages

Experiment Book 2010 Final

Uploaded by

Mayur Agrawal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Experiment Book

Embedded Systems and Robotics


HPES

Designed & Drafted


by

Sourabh Sankule
Arpit Mathur
Abhijeet Gupta
Ankur Agrawal
Tanmay Gangwani
Sahil Khan
Manoj Gulati
Abhishek Kumar
Punit Narang

Table of Contents
Overview of AVR based Trainer Board .......................................................................................... 6
INTRODUCTION ................................................................................................................................... 6
FEATURES ............................................................................................................................................ 6
HOW TO USE THE MANUAL ................................................................................................................ 7
MODULE LIST & DISCRIPTION ............................................................................................................. 7
1A. Microcontroller Module: Primary ................................................................................................. 7
1B. Microcontroller Module: Secondary............................................................................................. 8
2. Serial Programmer Module ............................................................................................................. 9
3. Serial Interface Module................................................................................................................. 10
4A. Sensor Module: Analog............................................................................................................... 11
4B. Sensor Module: Digital................................................................................................................ 11
5. LCD interface Module ................................................................................................................... 12
6. LED array modules ........................................................................................................................ 13
7. Switchpad Module ........................................................................................................................ 14
8. Variac Module ............................................................................................................................... 15
9. Motor Driver Modules .................................................................................................................. 16
10A. External Connection module for digital IR sensors................................................................... 17
10B. External Connection module for Buzzers, relays etc ................................................................ 18
11. Power supply module ................................................................................................................. 19
EXPERIMENTS IN EMBEDDED SYSTEMS....................................................................................... 20
Experiment 1: Digital Input/Output in a Microcontroller ............................................................ 20
Familiarizing with Atmega 16............................................................................................................ 20
Part A: To glow a visible light LED using Atmega 16 ......................................................................... 21
Problem Statement ........................................................................................................................... 21
Circuit Overview ................................................................................................................................ 21
Part B: Using a reset switch to operate an LED ................................................................................ 22
Problem Statement ........................................................................................................................... 22
Circuit Overview ................................................................................................................................ 22
Part C: Making different LED glow patterns .................................................................................... 23
Problem Statement ........................................................................................................................... 23
Circuit Overview ................................................................................................................................ 23
Part D: ............................................................................................................................................... 23
Problem Statement ........................................................................................................................... 23
Circuit Overview ................................................................................................................................ 23

HP Education Services

Experiment 2: To interface a 16x2 LCD with Atmega and implement the LCD functions ............... 24
LCD connections................................................................................................................................ 24
Part A: To print a constant string on LCD .......................................................................................... 25
Problem Statement ........................................................................................................................... 25
Some of the useful LCD functions: .................................................................................................... 25
Circuit Overview ................................................................................................................................ 25
Part B: To print strings in loop on LCD .............................................................................................. 26
Problem Statement ........................................................................................................................... 26
Circuit Overview ................................................................................................................................ 26
Part C: Display of integer data on LCD ............................................................................................. 26
Problem Statement ........................................................................................................................... 26
Printing an integer on LCD ................................................................................................................ 26
Part D: Display of floating point data on LCD ................................................................................... 27
Problem Statement ........................................................................................................................... 27
Printing a floating point number on LCD .......................................................................................... 27
Experiment 3: Interfacing a 16 key keypad .................................................................................. 28
Problem Statement ........................................................................................................................... 28
Designing of Keypad.......................................................................................................................... 28
Logic behind the code used to interface........................................................................................... 29
Circuit Overview ................................................................................................................................ 29
Experiment 4: Working with Timers - CTC mode.......................................................................... 30
Timer in CTC mode ............................................................................................................................ 30
Part A................................................................................................................................................. 31
Problem Statement ........................................................................................................................... 31
Part B................................................................................................................................................. 31
Problem Statement ........................................................................................................................... 31
Connecting a speaker ........................................................................................................................ 31
Circuit Overview ................................................................................................................................ 31
Experiment 5: Working with Timers Fast PWM mode ............................................................... 32
Timer in Fast PWM mode ................................................................................................................. 32
Problem Statement ........................................................................................................................... 33
Experiment 6: Working with ADC (Analog to Digital Convertor) ................................................... 34
Analog to Digital Convertor .............................................................................................................. 34
Initializing ADC .................................................................................................................................. 34
Problem Statement ........................................................................................................................... 35
Circuit Overview ................................................................................................................................ 35
Experiment 7: Data communication by UART .............................................................................. 36

HP Education Services

Part A: ............................................................................................................................................... 36
Problem Statement ........................................................................................................................... 36
Circuit Overview ................................................................................................................................ 36
Part B:................................................................................................................................................ 37
Problem Statement ........................................................................................................................... 37
Circuit Overview ................................................................................................................................ 37
Part C:................................................................................................................................................ 38
Problem Statement ........................................................................................................................... 38
Circuit Overview ................................................................................................................................ 38
Part D: ............................................................................................................................................... 39
Problem Statement ........................................................................................................................... 39
Circuit Overview ................................................................................................................................ 39
Experiment 8: Data transfer by SPI protocol................................................................................ 40
Problem Statement ........................................................................................................................... 40
Circuit Overview ................................................................................................................................ 40
Experiment 9: Using External Interrupts ..................................................................................... 41
Problem Statement ........................................................................................................................... 41
Circuit Overview ................................................................................................................................ 41
EXPERIMENTS IN ROBOTICS/AUTOMATION ................................................................................ 42
Experiment 1: Analog IR Sensor .................................................................................................. 42
Part A: Interfacing Analog IR Sensor with microcontroller and to display variation in output on
LCD. ................................................................................................................................................... 42
Problem Statement ........................................................................................................................... 42
Circuit Overview ................................................................................................................................ 42
Part B: Analog IR Sensor used as a color sensor. ............................................................................. 43
Problem Statement ........................................................................................................................... 43
Part C: Analog IR Sensor used for distance measuring. ................................................................... 43
Problem Statement ........................................................................................................................... 43
Experiment 2: Digital IR (TSOP) sensor ....................................................................................... 44
Part A: Interfacing Digital TSOP IR Sensor with microcontroller and to display variation in output
on LCD / LED...................................................................................................................................... 44
Problem Statement ........................................................................................................................... 44
Circuit Overview ................................................................................................................................ 44
Part B: Digital TSOP IR Sensor used as contrast variation detection sensor.................................... 45
Problem Statement ........................................................................................................................... 45
Part C: Digital TSOP IR Sensor used as object detecting sensor. ..................................................... 45
Problem Statement ........................................................................................................................... 45

HP Education Services

Experiment 3: Motor Control using driver L293 ........................................................................... 46


Problem Statement ........................................................................................................................... 46
Circuit Overview ................................................................................................................................ 46
Experiment 4: Speed control of DC Motor .................................................................................. 47
Problem Statement ........................................................................................................................... 47
Circuit Overview ................................................................................................................................ 47
Experiment 4: Automation ........................................................................................................ 48
Part A: Controlling Motor through sensors. ..................................................................................... 48
Problem Statement ........................................................................................................................... 48
Circuit Overview ................................................................................................................................ 48
Part B: Switching Relay/Transistor through sensors......................................................................... 48
Problem Statement ........................................................................................................................... 48
Circuit Overview ................................................................................................................................ 48
LINE FOLLOWER ROBOT ............................................................................................................. 49

HP Education Services

Overview of AVR based Trainer Board


INTRODUCTION
The Embedded Development Board provided to you has been designed keeping in mind the needs of
engineering students and enthusiasts so that they can match up to the present industry standards
on latest developments in the rising field of Embedded Systems Design/Development and is better
than any existing boards available in the market.
The board has been intensively designed to cover all existing features of AVR microcontrollers and is
ready-to-use with its supporting equipment mounted in the periphery.

FEATURES
AT mega 16 & 8 microcontrollers with facility of

On-board serial programmer.


Option for In System Programming (ISP) based on externally provided STK500 platform.
On-board Digital and Analog IR sensors.
RS232 serial interface for establishing connections between the mcu and computer system.
On-board LED arrays, keypad and external connections for interfacing a number of devices.
On-board motor driver circuits etc.

HP Education Services

HOW TO USE THE MANUAL


The board has been divided in modules and each module has been thus described with proper partdetails, circuit diagram and DIY connection diagram.

MODULE LIST & DISCRIPTION

1A. Microcontroller Module: Primary


Features an ATmega16 microcontroller with

Connectors for Ports A,B,C & D


Aref (reference voltage)
SPI
16MHz external crystal oscillator UART Slave select
Reset switch
Ext. GND

HP Education Services

1B. Microcontroller Module: Secondary


Features an Atmega 8 microcontroller with

Connectors for Ports B,C & D


SPI (pin 6,7,8,9,10,11)
16MHz external crystal oscillator
UART
Slave select
Reset switch
Ext. GND

HP Education Services

2. Serial Programmer Module

RS232 Serial Port


Connector for SPI

HP Education Services

3. Serial Interface Module

RS232 Serial port


Connector for UART
MAX232 IC & circuitry

HP Education Services

10

4A. Sensor Module: Analog

Tx Rx
Associated circuitry
Connector for Output

4B. Sensor Module: Digital

IR Tx LED
TSOP 1738 IR Rx
Associated circuitry
Connector for output

HP Education Services

11

5. LCD interface Module

16 pin LCD connector


PORT connector
Contrast control

HP Education Services

12

6. LED array modules

Features 8 LED array


PORT connector
Associated circuitry

HP Education Services

13

7. Switchpad Module

8 Switch-pad
PORT connector
External VCC/GND

HP Education Services

14

8. Variac Module

4 Variacs for ADC and misc. applications


Output Pins for interfacing

HP Education Services

15

9. Motor Driver Modules

IC l293D
Output pins for motors

Connectors for speed & direction control

HP Education Services

16

10A. External Connection module for digital IR sensors

Supports as many as 8 TSOP based IR sensors


PORT connectors for interfacing with atmega

HP Education Services

17

10B. External Connection module for Buzzers, relays etc

Supports variety of devices for interfacing purposes.


For example variety of relays, buzzers.
NPN transistors are used as simple switches.

HP Education Services

18

11. Power supply module

IC 7805
Associated circuitry
Output for 5V supply out

HP Education Services

19

EXPERIMENTS IN EMBEDDED SYSTEMS


Experiment 1: Digital Input/Output in a Microcontroller
Familiarizing with Atmega 16

Above shown is the pin configuration of Atmega 16 IC.


It is a 40 pin IC with pin numbers starting from the left side of the U-shaped notch.
Pin numbers 11 and 31 should be connected to ground.
Pin number 10 is connected to +5 volts.
Pin numbers 32(AREF) and 30(AVCC) are shorted and connected to +5 volts.
Pin number 9(RESET) should be connected to +5 volts through a pull-up resistor as shown
below.

RESET pin

HP Education Services

20

Part A: To glow a visible light LED using Atmega 16

Problem Statement
1. Connect a LED to pin number 40 i.e. PA0 of Atmega.
2. Connect the positive end (longer leg) of the LED to the pin and the negative end (shorter
leg) to ground via a 220 Ohm resistor (as shown).

3. Program the IC to switch on and off the LED after certain time intervals.
4. Consider module 1A/1B for mcu and module 6 for LED array connections.

Circuit Overview

LED

Atmega-16

HP Education Services

21

Part B: Using a reset switch to operate an LED

Problem Statement
1. Make the LED connections as in previous experiment.
2. Connect a reset switch to pin number 1 i.e. PB0 of Atmega.
3. Connect one leg of the switch to ground and the other leg to the pin pulled up by a 10K Ohm
resistor (as shown).
PORT B.0

4. Make PB0 as input pin and program the IC to control the LED with the switch.
5. Consider module 1A for mcu, module 6 for LED array and module 7 for switch pad
connections.
6. Now integrate as many switches and LEDs as you want and glow them using switches by
making changes in the program code.

Circuit Overview

LED

Atmega-16

SWITCH

HP Education Services

22

Part C: Making different LED glow patterns


Problem Statement
1.
2.
3.
4.

Connect 8 LEDs to the entire PORT C of Atmega i.e. pin number 33 to 40.
Each LED is to be connected in the manner shown before.
Program the IC to display different LED patterns using the PORT C I/O pins.
Some of the patterns for practice are :
LEDs glow in a line with certain delay in between.
Alternative glowing LEDs.
Converging pattern.
Diverging pattern.

5. Consider module 1A for mcu, module 6 for LED array connections.

Circuit Overview

Atmega-16

Set of 8 LEDs

Part D: To change pattern of glowing LEDs using switch


Problem Statement
1.
2.
3.
4.

Make the LED connections as before.


Make the switch connections to PB0 as before.
Program the IC to display different LED patterns on the press and release of the switch.
Consider module 1A/1B for mcu, module 6 for LED array and module 7 for switch pad
connections.

Circuit Overview
Atmega-16

Set of 8 LEDs

SWITCH

HP Education Services

23

Experiment 2: To interface a 16x2 LCD with Atmega and implement


the LCD functions

LCD connections

Connect a 16x2 LCD with PORT C of Atmega as per the connections shown in module
5.
Actual connections for 16x2 LCD already done on Board
Note: - Port X=C

HP Education Services

24

Part A: To print a constant string on LCD

Problem Statement
1. Initialize the LCD at PORT C in the CVAVR graphical interface.
2. Program the Atmega to do the following :

STATIC PRINTING- Print your name at different locations of the LCD.

Some of the useful LCD functions:

lcd_clear () Clears the LCD.


lcd_gotoxy(x, y) Takes the cursor to the coordinate (x, y).
lcd_putchar(c) Prints the character c on the LCD.
lcd_puts (str) Prints the string str on the LCD.
lcd_putsf (ABC) Prints ABC on the LCD. Function used to print constant strings on LCD.

Circuit Overview

Atmega-16

HP Education Services

LCD

25

Part B: To print strings in loop on LCD


Problem Statement
1. Initialize the LCD at PORT C in the CVAVR graphical interface.
2. Program the Atmega to do the following :

DYNAMIC PRINTING- Print your name and make it move (left/right) on LCD.

Circuit Overview

Atmega-16

LCD

Part C: Display of integer data on LCD


Problem Statement
1. Make the LCD connections as in previous experiment.
2. Program the IC to print the following on the LCD:
Your date of birth

Printing an integer on LCD

Create a character buffer with size atleast 1 more than the number of digits in the
integer.
itoa (int, char[n]) This function converts the integer to a string.
Use lcd_puts () to print the string on the LCD.

Example To print 99 on the LCD


int a=99;
char buff[3];
itoa(a,buff);
lcd_gotoxy(0,0);
lcd_puts (buff);

//prints 99 at location (0, 0)

HP Education Services

26

Part D: Display of floating point data on LCD

Problem Statement
1. Make the LCD connections as in previous experiment.
2. Program the IC to print the following on the LCD:
Your class XII board percentage

Printing a floating point number on LCD

Create a character buffer with size atleast 1 more than the number of digits in the
float number. (decimal point counted as a digit)
ftoa (float,int,char[n]) This function converts the integer to a string.
The second argument (int) of the function decides the number of places after
decimal in the string created.
Use lcd_puts () to print the string on the LCD.

Example To print 99.99 on the LCD


float a=99;
char buff[6];
ftoa(a,2,buff);
lcd_gotoxy(0,0);
lcd_puts (buff);

//prints 99.99 at location (0, 0)

HP Education Services

27

Experiment 3: Interfacing a 16 key keypad


Problem Statement
1. Interface the given 16 key keypad to the 8 pins of PORT A of Atmega.
2. Make connection to LCD with PORT C as done before.
3. Press the keys of keypad one by one and obtain corresponding display on LCD.
4. Consider module 1A/1B for mcu and 16 matrix keypad connections.

Designing of Keypad

Schematic

The 16 reset switches are connected in a square matrix fashion with 8 output wires
connected to an 8 pin FRC female connector.

HP Education Services

28

Logic behind the code used to interface

Firstly the first four pins of the port (vertical lines) are made as output pins with 0
output and the remaining four (horizontal lines) are made input pins with an internal
pull-up.
If any switch is pressed then a 0 appears on one of the horizontal line when it is read.
In the second part the first four pins are made input pins with internal pull-up and
remaining four are made output pins with 0 output.
If any switch is pressed then a 0 appears on one of the vertical line when it is read.
This way the exact switch pressed is determined.

Circuit Overview
Atmega-16

LCD

16-key Keypad

HP Education Services

29

Experiment 4: Working with Timers - CTC mode

Timer in CTC mode

In CTC mode duty cycle is fixed to 50%, but frequency of pulse can be selected.
In the graphical interface of CVAVR use Timer 0 and Timer 2 for CTC mode.
Do following settings:
Clock source System clock
Clock value - Select any from the list as per frequency required. Call it ft
Mode- CTCtop=OCRx (x= 0 or 2)
Output- Toggle on compare match
In the program write the value of OCRx register.This determines the output frequency
according to the formula:

f = ft / (2 x (OCRx+1))

The output pulse is obtained at PB3 (for Timer 0) and PD7 (for Timer 2).
Consider module 1A for mcu pin connections.

HP Education Services

30

Part A
Problem Statement
1. Program the Atmega to generate a clock of the following two frequencies using CTC mode:
38 kHz
120 kHz
2. Measure the frequency and the voltage using a digital multimeter and compare with
theoretical predictions

Theoretical value
Frequency
38 kHz

Experimental value
Frequency

Theoretical value
Voltage
2.5 V

120kHz

Experimental value
Voltage

2.5 V

Part B
Problem Statement

Generate a clock pulse of frequency in the audible range (20 Hz to 20 kHz) and apply it on a
speaker to make a buzzer.

Connecting a speaker

Connect one wire of the speaker to ground and the other wire to the output pin of the
timer.
Consider module 1A for mcu, module 10B for External Buzzers connections.

Circuit Overview

Atmega-16

Speaker

Timer

HP Education Services

31

Experiment 5: Working with Timers Fast PWM mode


Timer in Fast PWM mode

In Fast PWM mode frequency is fixed, but duty cycle of pulse can be selected.
In the graphical interface of CVAVR use Timer 0, Timer 1and Timer 2 for Fast PWM mode.
Do following settings:
Clock source System clock
Clock value - Select any from the list as per frequency required. Call it ft
The frequency of the pulse would then be fixed to ft /256 .
Mode- Fast PWM top=FFh
Output- Non-Inverted PWM (Inverted PWM is just the negation of this).
In the program write the value of OCRx register.This determines the output duty cycle
according to the formula:

Duty Cycle = ( OCRx / 256 ) x 100 %

The output voltage measured by multimeter is given by:

Voltage = ( OCRx / 256 ) x Vcc

The output pulse is obtained at PB3 (for Timer 0), PD4 (for Timer 1B), PD5 (for Timer 1A) and
PD7 (for Timer 2).
Consider module 1A for mcu connections.

HP Education Services

32

Problem Statement
1. To generate pulses with duty cycle by using timer in PWM mode:
25%
50%
75%
2. Measure the frequency and the average DC voltage using a digital multimeter and compare
with theoretical predictions.

Duty Cycle

Theoretical value
Frequency

Experimental value
Frequency

Theoretical value
Voltage

Experimental value
Voltage

25%
50%
75%

HP Education Services

33

Experiment 6: Working with ADC (Analog to Digital Convertor)


Analog to Digital Convertor

Atmega offers in-built ADC facility at PORT A i.e. pin number 33 to 40.
Voltage applied to the ADC pin can vary from 0 volts to the voltage applied at AREF pin i.e.
pin 32 of Atmega.
The digital conversion can be 8-bit or 10-bit at the discretion of the user.

Function used to read the ADC value is read_adc(x) (x is the pin number ranging from 0

to 7).It returns an integer corresponding to the voltage at the pin.


Consider module 1A for mcu ADC connections.

Initializing ADC

In the CVAVR graphical interface, click on ADC and enable the facility.
By default 10 bit conversion is done. Select Use 8 bits option for 8 bit conversion.
Voltage reference can be made AREF or AVCC since both pins are shorted.
Clock represents the ADC sampling frequency. Select it as 125,000 kHz.

HP Education Services

34

Problem Statement

Make a voltage divider circuit using a 1k Ohm resistor and a 1k Ohm potentiometer
(as shown).

Connect it to one of the ADC pins of Atmega 16 and read the ADC value.
Connect a 16x2 LCD at PORT C of Atmega and display the following on LCD:
Corresponding digital voltage 8 bit/10 bit (do both cases)
Corresponding voltage values (in Volts)
Consider module 1A for mcu ADC, module 8 for VARIAC and module 5 for LCD connections.

Circuit Overview

ADC of
Atmega-16

LCD

Potentiometer
Circuit

HP Education Services

35

Experiment 7: Data communication by UART

Part A: To send characters from microcontroller and displaying on computer screen.


Problem Statement
1. Initialize UART of Atmega-16 with following parameters:

Communication Parameters: 8 Data, 1 Stop, No Parity


USART Receiver: On
USART Transmitter: On
USART Mode: Asynchronous
USART Baud rate: 9600

2. Write a program to continuously send a charactert though UART.


3. Confirm the transfer of data on computer using software Docklight. Keep the same
communication parameters.
4. Consider module 1A for mcu UART connections, module 3 for Serial Interface Module
connections.

Circuit Overview
Atmega-16

Serial Port

MAX 232

Docklight

Computer

HP Education Services

36

Part B: To send ADC values from uC to computer.


Problem Statement
1. Design a voltage divider circuit using potentiometer to generate analog voltages.
2. Connect the analog output to PA0
3. Initialize the UART in previous parts mode.
4. Write a program to convert the analog voltage to 8 bit digital word and transfer
continuously to computer using UART. Give a delay of > 20ms between two
readings to avoid crashing of computer.
5. Monitor the values in integer mode on computer using software Docklight.
6. Vary the potentiometer and analyze the readings.

Circuit Overview

Atmega-16

Potentiometer

MAX 232

Docklight

HP Education Services

Serial Port

Computer

37

Part C: To send characters from computer keyboard to uC and print on LCD.


Problem Statement
1.
2.
3.
4.

Initialize the UART as before.


Using Docklight send data from the computer to the uC via UART protocol.
Make LCD connections to PORT C of Atmega.
Write a program to display the received data on the LCD.

5. Consider module 1A for mcu UART connections, module 3 for Serial Interface Module
connections and module 5 for LCD connections.

Circuit Overview

Docklight

Computer

Serial Port

LCD

Atmega-16

MAX 232

HP Education Services

38

Part D: To send characters from one uC to another and displaying it on LCD.

Problem Statement
1. Initialize UART on both microcontrollers as before.
2. Make one of them as the receiver and the other as the transmitter with same parity
and baud rate settings in both.
3. Connect the Rx pin of uC1 to Tx pin of uC2 and Tx pin of uC1 to Rx pin of uC2.
4. Make sure that the ground connections of both the microcontrollers are same for
proper communication.
5. Write a program to send characters from one uC.
6. Receive them on the other uC and display them on a 16x2 LCD connected to PORT C.
7. Consider module 1A/1B for mcu UART connections.

Circuit Overview

Atmega 1

Through
UART

Atmega 2

LCD

HP Education Services

39

Experiment 8: Data transfer by SPI protocol


Problem Statement
1. In the graphical interface of CVAVR, enable SPI and do the following settings:
SPI clock rate- 2000 kHz
SPI type- Make one microcontroller the master and the other slave
Clock phase- Cycle half
Clock polarity- Low
Data order- MSB first
2. Connect the following pin numbers of one uC to the corresponding pins of the other uC
(As shown):
Pin number 5 (SS bar)
Pin number 6 (MOSI)
Pin number 7 (MISO)
Pin number 8 (SCK)

3. Make sure that the ground connections of both the microcontrollers are same for

proper communication.
4. Write a program to send characters from the master.
5. Receive them on the slave and display the received data on a 16x2 LCD.
6. Consider module 1A/1B for mcu SPI connections, module 5 for LCD connections.
7. Now make another code to send ADC values from uC1 to uC2 and displaying it on LCD.

Circuit Overview
Atmega 1

Through
SPI

Atmega 2

LCD

HP Education Services

40

Experiment 9: Using External Interrupts


Problem Statement
1.
2.
3.
4.
5.

Initialize INT0 in Falling Edge mode.


Write an LED blinking program in the Interrupt Service Routine.
Put a pull up resistance and a switch connecting to Gnd to provide interrupt.
Press the switch to blink the LED.
Consider module 1A for mcu interrupt pin connections, module6 for LED array connections
and module 7 for switch pad.

Circuit Overview

Atmega

Interrupt

LED

Switch
LED

HP Education Services

41

EXPERIMENTS IN ROBOTICS/AUTOMATION
Experiment 1: Analog IR Sensor
Part A: Interfacing Analog IR Sensor with microcontroller and to display
variation in output on LCD.

Problem Statement
1. Make the circuit as shown in the figure.
2. The phototransistor D1 and IR-LED must be adjacent to each other (but not
touching) and perpendicular to the breadboard.
3. After making the connections, measure the voltage VOutput by a multimeter.
4. Now bring a plane reflecting surface (white paper) over D1 and IR-LED and note the
gradual change in the voltage.
5. Vary the resistance using variac and note the change in range of sensor.
6. Now enable ADC of Atmega 16 and check Use 8 bits.
7. Bring the output of the analog sensor at one of the input pins for ADC (e.g., PINA.0)
and write a code to read its digital value and display it on LCD.
8. Consider module 4A for Analog Sensor Module connections.

Circuit Overview

IR Analog Sensor

Atmega 16

HP Education Services

LCD

42

Part B: Analog IR Sensor used as a color sensor.

Problem Statement
1. Use the circuit connections from the previous part without any changes.
2. Now change the program code of the mcu to read ADC values for different colors viz take
three-four colors for instance like RED, GREEN, BLACK , BLUE.
3. Take a pen and paper and note down the range of variations in ADC values when the
sensor is exposed to these colors one by one.
4. Now alter the program code to check the range of ADC values and display corresponding
color name on LCD.
5. Find out how many colors the mcu can differentiate.

Part C: Analog IR Sensor used for distance measuring.

Problem Statement
1. Use the circuit connections from the previous part without any changes.
2. Now change the program code of the mcu to read ADC values for distances of the order of
centimeters
3. Take a pen and paper and note down the range of variations in ADC values cm by cm.
4. Now alter the program code to check the range of ADC values and display the distance on
LCD.
5. Find out the minimum distance mcu can resolve using IR sonsor.

HP Education Services

43

Experiment 2: Digital IR (TSOP) sensor


Part A: Interfacing Digital TSOP IR Sensor with microcontroller and
to display variation in output on LCD / LED.
Problem Statement
1. Make the circuit as shown in the figure.
2. The TSOP sensor and IR-LED must be adjacent to each other (but not touching) and
perpendicular to the breadboard.
3. To generate a pulse of 38kHz, initialize Timer 0 of Atmega-16 with following
parameters:
Clock Source: System Clock
Clock Value: 1000.000 kHz
Mode: CTC top= OCR0
Output: Toggle on Compare Match
Set Compare Value as calculated for a pulse of 38 kHz (in hexadecimals).
4. Connect the output pin of Timer 0 with the positive terminal of IR-LED so as to give
it a pulse of 38 kHz.
5. Check that the default output voltage of TSOP sensor is +5V (when no IR falls on it)
and 0V on bringing a plane reflecting surface (white paper) over the sensor and the
IR-LED.
6. Now connect the output pin of TSOP sensor to an I/O pin of Atmega 16 (e.g., PIND.0)
and connect the positive terminal of an LED to another I/O pin of the uC (e.g.,
PIND.1). Connect negative terminal of the LED to gnd through a 220ohm resistance.
7. Now write a code that takes input from the TSOP sensor and glows the LED when
the sensor receives IR.
8. Vary the resistance using variac and note the change in range of sensor.
9. Consider module 4B for Digital Sensor Module connections.

Circuit Overview
TSOP Sensor

Atmega 16

HP Education Services

LED

44

Part B: Digital TSOP IR Sensor used as contrast variation detection


sensor.
Problem Statement
1. Use the same circuit connections.
2. Write a program code for detecting contrast variations, viz. black and white.
3. Contrast variation comes handy in designing line following robots.

Part C: Digital TSOP IR Sensor used as object detecting sensor.


Problem Statement
1. Use the same circuit connections.
2. Write a program code for detecting obstacles in front of digital sensor.
3. Obstacle detection comes handy in obstacle detection robots.

HP Education Services

45

Experiment 3: Motor Control using driver L293

Problem Statement
1. Connect any two I/O pins of Atmega16 (pin no. 39 & 40) with the input pins of motor driver
L293D i.e., Direction 1-A and Direction 2-A.
2. Connect the enable pin (PWM A) and VCC1 (pin no. 16) with constant 5V and ground as
shown.
3. Connect the output pins of L293D with the terminals of the motor.
4. Give 12 V as VCC2 to L293D.
5. Write a code to so as to make pin 39 of uC high and pin 40 as low and note the direction of
rotation of the motor.
6. Now interchange the outputs these pins of uC and note the change in direction of rotation.
7. Now make both the pins as high (or low) and observe the locking effect in the motor.
8. Consider module 1A for mcu connections, module 9 for Motor Driver Module connections.

Circuit Overview
Atmega-16

L293D

HP Education Services

DC Motor

46

Experiment 4: Speed control of DC Motor


Problem Statement

1. Initialize Timer 0 of Atmega-16 with following parameters:


Clock Source: System Clock
Clock Value: 1000.000 kHz
Mode: Fast PWM top=FFh
Output: Non-Inverted PWM
Set Compare Value to 80 (decimal 128= hex 80)
2. Now Connect the Timer 0 output pin, i.e., PINB.3 (OCR0) to the enable pin of L293D,
marked as PWM A.
3. All other connections are same as in Exp. 14.
4. Note the reduction in speed of motor as compared to that in Exp. 14.
5. To run the motor at full speed again, change OCR0 value to 255.
6. Consider module 9 for Motor driver connections.

Circuit Overview

Atmega-16

L293D

HP Education Services

DC Motor

47

Experiment 4: Automation
Part A: Controlling Motor through sensors.
Problem Statement
1. Interface Digital Sensor and Motor driver module with mcu.
2. Write a program code for the following:

Motor 1 changes direction when obstacle comes in front of sensor.


Motor 2 changes direction when obstacle comes in front of sensor.

Try to interface two sensors and four motors together. Easy..isnt it?

Circuit Overview

ATMEGA

TSOP

MOTOR

Part B: Switching Relay/Transistor through sensors.


Problem Statement
1. Interface Digital Sensor and Transistor module with the mcu.
2. Write a program code for the following:

Relays switch when obstacle comes in front of sensor.

Circuit Overview

TSOP

RELAY

ATMEGA

TRANS. SWITCH

HP Education Services

48

LINE FOLLOWER ROBOT


Task:
To design an autonomous robot to follow a line.

There can be two cases:


A: Bright strip over dark background (White over Black)
B: Dark strip over bright background (Black over White)

How to differentiate white and black?


Digital IR Sensor (TSOP) used for contrast detection as discussed.

How to follow a line?


We have sensors to differentiate between white and black surfaces. Hence we can use them in a
pattern to detect line and move robot accordingly.

Arrangement of 3 sensors:

LEFT

CENTRE

RIGHT

Each purple circle represents a Tx-Rx pair.


Sensor over white surface: output low (logic level 0)
Sensor over black surface: output high (logic level 1)

HP Education Services

49

Design:
SENSOR

MICROCONTROLLER

MOTOR

MOTOR DRIVER

How to control robot:


a
vv

Position of Line

Sensor (on)

Extreme Left
Left

Left

Turn sharp left

Centre and Right

Turn left

Centre

Move forward

Centre
Right

Movement

Centre and Right

Turn right

Right

Turn sharp right

Extreme Right

Simplifying Line Follower Robot:


Use two sensors instead, one for left and other for right.

LEFT

RIGHT

l
How to control robot:
Position of line

Sensor (on)

Movement

Left

Left

Turn right

Centre

None

Move Forward

Right

Right

Turn left

HP Education Services

50

You might also like