0% found this document useful (0 votes)
2 views

exp2embedded[1]

Uploaded by

diyamirani06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

exp2embedded[1]

Uploaded by

diyamirani06
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

22BIT184

EXPERIMENT: 2
Programming for Blinking LED, Pattern Generation,
Timing, and Sequence Generation

Objective
To program the ATmega2560 to:

1. Blink two LEDs

2. Generate a specific LED pattern.

3. Generate a specific LED pattern.

Components Require
1. Proteus Software (for simulation).

2. ATmega2560 microcontroller module in Proteus library.

3. LEDs (virtual in Proteus).

4. Resistors (220 Ω for current limiting).

5. Arduino IDE for code generation

Key Concepts

Blink an LED at regular intervals

Code & Output:


1. Blink two LEDs

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

2. Generate a specific LED pattern.

Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184

3. Generate a specific LED pattern

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:

1. Display numbers on a multi-digit 7-segment display.


2. Implement a counter that increments and displays the count on the 7-segment
display

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.

Task 1: Counter - Single Digit - Common Cathode 7-Segment


Display

Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184

Task 2: Counter - Double Digit - Common Cathode 7-Segment


Display

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:

• Pressed: The circuit is closed, and current flows.

• Released: The circuit is open, and no current flows.


2. Pull-Down Resistor
A pull-down resistor ensures that the input pin reads a LOW signal when the button is not
pressed. Without it, the pin may float between HIGH and LOW states, causing unpredictable
behavior.
3. GPIO Pins
General Purpose Input/Output (GPIO) pins are used to interface external devices with the
microcontroller. In this experiment:
• One GPIO pin will be configured as an input to read the state of the push button.
• Another GPIO pin will be configured as an output to control an LED.
4. Interrupts (Optional)
Interrupts can be used to detect changes in the state of the push button without continuously
polling the input pin. This concept can be explored additionally.

Task 1: Make the push button

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

LCD 16x2 Commands

While interfacing an LCD16x2 with any microcontroller, firstly we need to


initialize the LCD. For that, we need to send some commands. Similarly, to
clear the display or to change the position, we need to send commands. So
basically, we can say that LCD16x2 is controlled by using commands.

• Now, while printing a character on LCD16x2, we need to send the ASCII


code of that character to LCD16x2.
• Suppose we want to print a character ‘H’ on the LCD, then we should send
0x48 (ASCII code of ‘H’) data to the LCD16x2. The LCD16x2 has its
controller, which does the printing job on the LCD16x2.

Lab 2 - Programming for Blinking LED, Pattern Generation, Timing, and Sequence Generation
22BIT184

Commonly Used LCD16x2 Commands

Order to configure LCD:


1. Initialize the LCD in 8-bit mode
2. Display ON, Cursor OFF, Blink OFF
3. Increment cursor, No display shift
4. Clear display
5. Print data
Circuit Diagram
1. Connect the data lines (D0-D7) of the LCD to PORTF (PF0-PF7) of the
ATmega2560.
2. Connect the control lines as follows:
o RS -> PK0
o RW -> PK1
o EN -> PK2
3. Connect the contrast pin (VO) to the middle pin of a 10kΩ potentiometer.
The other two pins of the potentiometer should be connected to +5V and

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.

Code & Output:

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

o The speed of the motor is controlled by varying the voltage applied to


its terminals.
o The polarity of the applied voltage determines the direction of
rotation.
o DC motors generate back EMF when spinning, which can cause
voltage spikes. Protection components like flyback diodes are used to
safeguard connected circuits.

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

Code & Output:

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

You might also like