Experiment Book 2010 Final
Experiment Book 2010 Final
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
HP Education Services
FEATURES
AT mega 16 & 8 microcontrollers with facility of
HP Education Services
HP Education Services
HP Education Services
HP Education Services
HP Education Services
10
Tx Rx
Associated circuitry
Connector for Output
IR Tx LED
TSOP 1738 IR Rx
Associated circuitry
Connector for output
HP Education Services
11
HP Education Services
12
HP Education Services
13
7. Switchpad Module
8 Switch-pad
PORT connector
External VCC/GND
HP Education Services
14
8. Variac Module
HP Education Services
15
IC l293D
Output pins for motors
HP Education Services
16
HP Education Services
17
HP Education Services
18
IC 7805
Associated circuitry
Output for 5V supply out
HP Education Services
19
RESET pin
HP Education Services
20
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
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
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.
Circuit Overview
Atmega-16
Set of 8 LEDs
Circuit Overview
Atmega-16
Set of 8 LEDs
SWITCH
HP Education Services
23
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
Problem Statement
1. Initialize the LCD at PORT C in the CVAVR graphical interface.
2. Program the Atmega to do the following :
Circuit Overview
Atmega-16
HP Education Services
LCD
25
DYNAMIC PRINTING- Print your name and make it move (left/right) on LCD.
Circuit Overview
Atmega-16
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.
HP Education Services
26
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
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.
HP Education Services
27
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
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
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
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:
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
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
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
Circuit Overview
Atmega-16
Serial Port
MAX 232
Docklight
Computer
HP Education Services
36
Circuit Overview
Atmega-16
Potentiometer
MAX 232
Docklight
HP Education Services
Serial Port
Computer
37
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
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
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
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
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.
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
Circuit Overview
TSOP Sensor
Atmega 16
HP Education Services
LED
44
HP Education Services
45
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
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:
Try to interface two sensors and four motors together. Easy..isnt it?
Circuit Overview
ATMEGA
TSOP
MOTOR
Circuit Overview
TSOP
RELAY
ATMEGA
TRANS. SWITCH
HP Education Services
48
Arrangement of 3 sensors:
LEFT
CENTRE
RIGHT
HP Education Services
49
Design:
SENSOR
MICROCONTROLLER
MOTOR
MOTOR DRIVER
Position of Line
Sensor (on)
Extreme Left
Left
Left
Turn left
Centre
Move forward
Centre
Right
Movement
Turn right
Right
Extreme 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