exp2embedded[1]
exp2embedded[1]
EXPERIMENT: 2
Programming for Blinking LED, Pattern Generation,
Timing, and Sequence Generation
Objective
To program the ATmega2560 to:
Components Require
1. Proteus Software (for simulation).
Key Concepts
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
EXPERIMENT: 3
Programming for multi-digit 7-segment display and
implementing counter
Objective
To program the ATmega2560 to:
Components Require
1. Proteus Software (for simulation).
2. ATmega2560 microcontroller module in Proteus library.
3. Multi-digit 7-segment display (common cathode or common anode,
depending on the setup).
4. Resistors (220 Ω for current limiting).
5. Arduino IDE for code generation.
Key Concepts
1. 7-Segment Display:
A 7-segment display is made up of 7 LEDs arranged to form the digits 0-9. Each
segment can be controlled to form a number or a letter. In a multi-digit display,
several 7-segment displays are connected to show multiple digits.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
2.Digit Encoding:
Each digit (0-9) is represented by turning on specific segments of the 7-segment
display. The segments are typically labelled as A to G, and specific patterns of
HIGH (on) and LOW (off) are used to display each digit.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
2. Timing Control:
A counter is implemented to cycle through the digits of the display. Delays and
multiplexing are used to control the timing of each digit.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
EXPERIMENT: 4
Digital Input Handling Using Push Buttons
Objective
The objective of this lab is to learn how to interface a push button switch with
the ATmega2560 microcontroller using Embedded C. By the end of this
experiment, you will be able to:
• Understand the working principle of a push button switch.
• Configure the GPIO pins of the ATmega2560 for input and output
operations.
• Write an Embedded C program to detect the state of the push button and
perform specific actions based on its state.
Components Require
To complete this experiment, you will need the following components:
1. ATmega2560 Microcontroller Development Board (e.g., Arduino
Mega or standalone ATmega2560 board)
2. Push Button Switch
3. Resistors (1kΩ pull-down resistor)
4. LED (for output indication)
5. Seven Segment Display
6. Breadboard and Connecting Wires
7. Power Supply (or USB connection for programming and power)
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Key Concepts
1. Push Button Switch
A push button switch is a simple input device that allows users to provide binary input
(ON/OFF) to a microcontroller. It has two states:
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Additional Task 1:
Conclusion:
we learned how to handle digital inputs using push buttons by configuring GPIO pins and
detecting button states. We explored debouncing techniques to ensure reliable signal
detection and understood the role of pull-up and pull-down resistors. This hands-on
experience is essential for designing interactive embedded systems.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
EXPERIMENT: 5
Interfacing 16x2 LCD in 8-bit Mode
Objective
The objective of this lab is to interface a 16x2 LCD with an ATmega2560
microcontroller in 8-bit mode and display the text on the LCD. This experiment
will help you understand how to configure and control an LCD using Embedded
C programming.
Components Require
1. ATmega2560 Microcontroller (or Arduino Mega board)
2. 16x2 LCD Module
3. Breadboard
4. Connecting Wires
5. Potentiometer (10kΩ) for contrast adjustment
Theory
• A 16x2 LCD has two rows, each capable of displaying 16 characters.
• It operates in either 4-bit mode or 8-bit mode. In 8-bit mode, all 8 data lines
(D0-D7) are used to send data or commands to the LCD.
• The LCD requires three control signals:
o RS (Register Select): Determines whether the data sent is a command
(RS = 0) or data (RS = 1).
o RW (Read/Write): Determines whether the LCD is being read from
(RW = 1) or written to (RW = 0).
o EN (Enable): Used to latch data into the LCD. A high-to-low pulse on
EN triggers the LCD to process the data.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Pin Configuration
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
GND.
4. Connect VSS to GND and VDD to +5V.
5. Connect A (LED+) to +5V and K (LED-) to GND for backlight.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Conclusion:
Interfacing a 16x2 LCD in 8-bit mode provides a simple yet effective way to display alphanumeric
characters in embedded systems. By utilizing 8 data lines, this mode allows faster data transfer
compared to 4-bit mode, making it ideal for applications where speed is a priority. The process
involves sending commands for initialization, cursor positioning, and data writing using a
microcontroller. Proper timing delays and control signals ensure seamless communication.
This interfacing technique is widely used in real-time embedded applications such as sensor data
display, digital clocks, automation systems, and user interfaces. Understanding and implementing
LCD interfacing in 8-bit mode helps in building more advanced projects in the field of
microcontrollers and embedded systems.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
EXPERIMENT: 6
Interfacing DC Motor with AVR Microcontroller
Objective
To interface and control a DC motor using an AVR microcontroller. The
experiment will demonstrate the basic concepts of GPIO (General Purpose
Input/Output) programming, PWM (Pulse Width Modulation), and motor
control.
1. Understand the working principle of a DC motor.
2. Learn how to interface a DC motor with an AVR microcontroller.
3. Write and execute a program to control the speed and direction of the DC
motor.
4. Observe the behaviour of the motor under different output patterns.
Components Require
• ATmega2560 Microcontroller (e.g., on an Arduino Mega board)
• DC Motor
• L293D Motor Driver IC (or equivalent H-Bridge circuit)
• Breadboard and connecting wires
• Power supply (5V for microcontroller, 12V for DC motor)
• Programmer (Arduino IDE for programming)
• Resistors, capacitors, and diodes (if required for protection)
Theory
DC Motor:
o A DC motor converts electrical energy into mechanical energy using
electromagnetic principles.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
H-Bridge (L293D):
• An H-bridge circuit allows bidirectional control of a DC motor by
reversing the polarity of the voltage applied to its terminals.
• The L293D is a dual-channel H-Bridge IC capable of controlling two DC
motors. The L293D can control up to two DC motors rated from 4.5V to
36V.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
• It has input pins for controlling the motor direction and enables pins to
turn the motor on/off or control its speed via PWM signals.
• The schematic diagram below shows a simplified version of the internal
circuitry that controls one motor.
Two pairs of transistors (Q1/Q4 and Q2/Q3) are set up as an H-bridge.
There’s a diode across the emitter and collector of each transistor to
Connection Diagram
• prevent EMF from being backed by the motor and causing damage to the
transistors.
• When transistors Q1 and Q4 are both switched ON, and transistors Q2
and Q3 are OFF, current flows through the motor from Vcc to the ground
like this:
Connect the PORTF pins (PF0-PF7) of the ATmega2560 to the input pins
of the L293D motor driver.
• Example:
o PF0 → Input 1 of L293D
o PF1 → Input 2 of L293D
o PF2 → Input 3 of L293D
o PF3 → Input 4 of L293D
• If using PWM for speed control, connect the enable pin of the L293D to a
PWM-capable pin on PORTF (e.g., PF6 or PF7).
1. Connect the output pins of the L293D to the terminals of the DC motor.
2. Ensure proper power supply and grounding for both the microcontroller
and the motor driver.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184
Conclusion:
• Visual Observation: The DC motor should visibly change its state (stop,
forward rotation, reverse rotation, and custom behaviors) at regular
intervals of 100 milliseconds. The transitions between states should be
smooth and repeat continuously.
• Audible Observation: Depending on the load and speed of the motor,
you may hear a slight hum or whirring sound as the motor changes
direction or speed.
Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation