0% found this document useful (0 votes)
50 views12 pages

EEE - Unit 2 - Notes - Peripheral Interface

Uploaded by

dp9405791781
Copyright
© © All Rights Reserved
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)
50 views12 pages

EEE - Unit 2 - Notes - Peripheral Interface

Uploaded by

dp9405791781
Copyright
© © All Rights Reserved
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/ 12

Unit 2

Peripheral Interface
CO2: DEVELOP interfacing of different types of sensors and other hardware devices with
Atmega328 based Arduino Board

ATMega328 Pinout Configuration

ATMEGA328P is a 28 pin chip as shown in pin diagram above. Many pins of the chip here have
more than one function. We will describe functions of each pin in below table.

Pin Pin name Description Secondary Function


No.

1 PC6 (RESET) Pin6 of PORTC Pin by default is used as RESET pin. PC6 can only be
used as I/O pin when RSTDISBL Fuse is
programmed.

2 PD0 (RXD) Pin0 of PORTD RXD (Data Input Pin for USART)

USART Serial Communication Interface

[Can be used for programming]

3 PD1 (TXD) Pin1 of PORTD TXD (Data Output Pin for USART)

USART Serial Communication Interface

[Can be used for programming]

INT2( External Interrupt 2 Input)

4 PD2 (INT0) Pin2 of PORTD External Interrupt source 0


5 PD3 Pin3 of PORTD External Interrupt source1
(INT1/OC2B)

OC2B(PWM - Timer/Counter2 Output Compare


Match B Output)

6 PD4 (XCK/T0) Pin4 of PORTD T0( Timer0 External Counter Input)

XCK ( USART External Clock I/O)

7 VCC Connected to positive voltage

8 GND Connected to ground

9 PB6 Pin6 of PORTB XTAL1 (Chip Clock Oscillator pin 1 or External clock
(XTAL1/TOSC1) input)

TOSC1 (Timer Oscillator pin 1)

10 PB7 Pin7 of PORTB XTAL2 (Chip Clock Oscillator pin 2)


(XTAL2/TOSC2)
TOSC2 (Timer Oscillator pin 2)

11 PD5 Pin5 of PORTD T1(Timer1 External Counter Input)

(T1/OC0B)

OC0B(PWM - Timer/Counter0 Output Compare


Match B Output)

12 PD6 Pin6 of PORTD AIN0(Analog Comparator Positive I/P)


(AIN0/OC0A)

OC0A(PWM - Timer/Counter0 Output Compare


Match A Output)

13 PD7 (AIN1) Pin7 of PORTD AIN1(Analog Comparator Negative I/P)

14 PB0 Pin0 of PORTB ICP1(Timer/Counter1 Input Capture Pin)


(ICP1/CLKO)

CLKO (Divided System Clock. The divided system


clock can be output on the PB0 pin)

15 PB1 (OC1A) Pin1 of PORTB OC1A (Timer/Counter1 Output Compare Match A


Output)

16 PB2 (SS/OC1B) Pin2 of PORTB SS (SPI Slave Select Input). This pin is low when
controller acts as slave.

[Serial Peripheral Interface (SPI) for programming]

OC1B (Timer/Counter1 Output Compare Match B


Output)

17 PB3 Pin3 of PORTB MOSI (Master Output Slave Input). When controller
(MOSI/OC2A) acts as slave, the data is received by this pin. [Serial
Peripheral Interface (SPI) for programming]

OC2 (Timer/Counter2 Output Compare Match


Output)

18 PB4 (MISO) Pin4 of PORTB MISO (Master Input Slave Output). When controller
acts as slave, the data is sent to master by this
controller through this pin.

[Serial Peripheral Interface (SPI) for programming]

19 PB5 (SCK) Pin5 of PORTB SCK (SPI Bus Serial Clock). This is the clock shared
between this controller and other system for
accurate data transfer.

[Serial Peripheral Interface (SPI) for programming]

20 AVCC Power for Internal ADC Converter

21 AREF Analog Reference Pin for ADC

22 GND GROUND

23 PC0 (ADC0) Pin0 of PORTC ADC0 (ADC Input Channel 0)

24 PC1 (ADC1) Pin1 of PORTC ADC1 (ADC Input Channel 1)

25 PC2 (ADC2) Pin2 of PORTC ADC2 (ADC Input Channel 2)

26 PC3 (ADC3) Pin3 of PORTC ADC3 (ADC Input Channel 3)

27 PC4 Pin4 of PORTC ADC4 (ADC Input Channel 4)


(ADC4/SDA)
SDA (Two-wire Serial Bus Data Input/output Line)

28 PC5 (ADC5/SCL) Pin5 of PORTC ADC5 (ADC Input Channel 5)

SCL (Two-wire Serial Bus Clock Line)


Interfacing of Atmega328 based Arduino board with LED

Interfacing an Atmega328-based Arduino board with an LED is a common beginner project and a great way to
start learning about microcontrollers and basic digital output. Here's a step-by-step guide to help you get started:
Materials Needed:
1. Atmega328-based Arduino board (e.g., Arduino Uno)
2. LED (any color)
3. 220-330 ohm resistor
4. Breadboard and jumper wires
Steps:
1. Setup the Circuit:
 Insert the Atmega328-based Arduino onto the breadboard. Make sure to align the pins correctly.
 Insert the LED into the breadboard. The longer leg (anode) of the LED should be connected to a
digital pin on the Arduino, and the shorter leg (cathode) should be connected to the resistor.
 Connect one end of the resistor to the cathode of the LED.
 Connect the other end of the resistor to the ground (GND) rail on the breadboard.
 Connect a jumper wire from the anode of the LED to a digital pin of your choice on the Arduino
(e.g., pin 13).
2. Write the Arduino Code:
 Open the Arduino IDE on your computer.
 Write a simple Arduino sketch to control the LED. Here's an example code to turn the LED on and
off in a loop:

const int ledPin = 13; // Pin connected to the LED


void setup()
{
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop()
{
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn off the LED
delay(1000); // Wait for 1 second
}

3. Upload the Code:


 Connect your Arduino board to your computer using a USB cable.
 Select the correct board type and port from the Tools menu in the Arduino IDE.
 Click the "Upload" button (right arrow) to compile and upload the code to your Arduino.
4. Observe the LED:
 Once the code is uploaded, the LED on the breadboard will start blinking on and off with a 1-
second interval.
Interfacing an ATmega328-based Arduino board with an LCD serial monitor involves connecting an LCD display to
the Arduino and then using the Arduino programming environment to send data to the display for visualization.
This can be useful for debugging, displaying sensor data, or creating user interfaces. Here's a step-by-step guide
on how to interface an ATmega328-based Arduino (e.g., Arduino Uno) with an LCD serial monitor:
Components Needed:
1. ATmega328-based Arduino board (e.g., Arduino Uno)
2. LCD display (e.g., 16x2 or 20x4 character LCD)
3. Jumper wires
4. Potentiometer (for contrast control on some LCDs)
5. Breadboard (optional)
Steps:
1. Connect the LCD to the Arduino:
 LCDs typically have 16 or 20 pins, and you need to connect them to your Arduino as follows:
 VCC to 5V on Arduino
 GND to GND on Arduino
 RS (Register Select) to a digital pin (e.g., D12)
 RW (Read/Write) to GND (for write mode)
 E (Enable) to a digital pin (e.g., D11)
 D4 to a digital pin (e.g., D5)
 D5 to a digital pin (e.g., D4)
 D6 to a digital pin (e.g., D3)
 D7 to a digital pin (e.g., D2)
 A (Anode) to 5V through a current-limiting resistor (220-330 ohms)
 K (Cathode) to GND
 If your LCD has a backlight, connect its anode (A) and cathode (K) pins to power (5V) and GND
respectively. Use a current-limiting resistor if needed.
 Adjust the LCD's contrast using a potentiometer (if your LCD has one) by connecting one end of the
potentiometer to 5V, the other end to GND, and the wiper (middle pin) to the V0 pin on the LCD.
2. Install Required Libraries:
 Open the Arduino IDE and go to "Sketch" > "Include Library" > "LiquidCrystal."
3. Write the Arduino Code:
 Here's a simple example code to display "Hello, World!" on a 16x2 LCD. Adjust the pin numbers according
to your connections:
Arduino Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.print("Hello, World!");
}

void loop() {
// Your code here
}

4. Upload the Code:


 Select the correct board and COM port from the "Tools" menu in the Arduino IDE.
 Click the "Upload" button to upload the code to your Arduino.
5. Observe the Output:
 Once the code is uploaded, you should see "Hello, World!" displayed on the LCD.
6. Using Serial Monitor:
 To send data from your Arduino to the serial monitor, you can use the Serial object. For example:

void loop() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
Serial.println("Data to send to serial monitor");
delay(1000); // Wait for 1 second
}

Open the serial monitor in the Arduino IDE (Tools > Serial Monitor) to view the data sent by your Arduino.

What is serial communication using Arduino IDE?


Serial communication using the Arduino IDE refers to the process of sending and receiving data between an
Arduino microcontroller and a computer or another device using a serial connection. The Arduino IDE provides a
simple and convenient way to implement serial communication for tasks like debugging, data logging, or
controlling external hardware. Here's how serial communication works using the Arduino IDE:
1. Serial Library: The Arduino IDE includes a built-in Serial library that simplifies serial communication. This
library provides functions to send and receive data over the serial connection.
2. Hardware Serial Ports: Most Arduino boards, such as the Arduino Uno, have hardware serial ports (e.g.,
Serial, Serial1, Serial2) that can be used for serial communication. These ports are physically connected to
pins on the microcontroller and are accessible through the Arduino IDE.
3. Baud Rate: Serial communication involves specifying a baud rate, which determines the speed at which
data is transmitted and received. Both the Arduino and the connected device must use the same baud
rate to communicate successfully. Common baud rates include 9600, 115200, and 57600 bits per second
(bps).
4. Serial Monitor: The Arduino IDE provides a built-in Serial Monitor tool (located under "Tools" > "Serial
Monitor") that allows you to send and receive data over the serial connection. It's a handy tool for
debugging and monitoring your Arduino code.
Sending Data from Arduino:
To send data from the Arduino to the computer or another device:
1. Initialize serial communication in your Arduino sketch using Serial.begin(baud_rate). For example:

void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
}

2 . Use the Serial.print() or Serial.println() functions to send data to the serial port. For example:

1. }
2. Open the Serial Monitor in the Arduino IDE. You should see the data sent from the Arduino displayed in
the monitor window.
Receiving Data in Arduino:
To receive data from the computer or another device:
1. Initialize serial communication as before.
2. Use the Serial.available() function to check if data is available in the input buffer. You can then use
Serial.read() to read and process the received data.
arduino
void loop() {
if (Serial.available() > 0) {
char receivedChar = Serial.read();
// Process the received character
}
}

When using the Serial Monitor in the Arduino IDE, you can type text or send commands to the Arduino by
entering data in the monitor's input field and clicking "Send" or pressing Enter.
Serial communication using the Arduino IDE is a fundamental tool for debugging and interacting with Arduino
projects. It allows you to exchange data between the Arduino and a computer or other devices, making it versatile
for a wide range of applications, including data logging, sensor reading, and remote control.

Explain the Concept of ADC in Atmega328 based Arduino board.

ADC, or Analog-to-Digital Converter, is a crucial component of the ATmega328 microcontroller, which is


commonly used in Arduino boards like the Arduino Uno. The ADC allows the microcontroller to convert analog
voltage signals into digital values that can be processed and manipulated in code. Here's an explanation of the
concept of ADC in an ATmega328-based Arduino board:
1. Analog and Digital Signals:
 Electronic devices work with both analog and digital signals. Analog signals are continuous and can
represent a range of values, such as varying voltage levels in response to changing conditions (e.g.,
temperature, light, or sound). In contrast, digital signals are discrete and can only represent two values (0
and 1).
2. ADC Purpose:
 Many sensors and real-world signals produce analog voltages that need to be processed by a
microcontroller like the ATmega328. The ADC's primary purpose is to convert these continuous analog
signals into discrete digital values that can be easily manipulated by the microcontroller's digital circuitry.
3. ADC in ATmega328:
 The ATmega328 microcontroller, found in Arduino Uno and similar boards, features a built-in ADC with
several channels (usually six channels). These channels allow you to connect different analog sensors or
signals to the microcontroller for conversion.
4. Voltage Range:
 The ADC in the ATmega328 typically has a voltage reference range of 0 to 5 volts. This means it can
convert any analog voltage within this range into a corresponding digital value.
5. Bit Resolution:
 The ADC's bit resolution determines the number of discrete values the ADC can represent. The
ATmega328's ADC has a 10-bit resolution, which means it can represent analog voltages as one of 1024
(2^10) possible values.
6. Sampling Rate:
 The sampling rate of the ADC determines how frequently it takes measurements. In the case of the
ATmega328, it can sample at different rates depending on your configuration but commonly at rates from
a few thousand to a few hundred thousand samples per second.
7. Voltage Division:
 To measure an analog voltage with the ADC, you typically use a voltage divider circuit or other signal
conditioning methods to scale the input voltage within the 0-5V range. The ADC then converts this scaled
voltage into a digital value.
8. Reading ADC Values in Arduino:
 In the Arduino IDE, you can use the analogRead(pin) function to read the analog voltage on a specific pin
(where pin is the analog input pin number, e.g., A0 to A5 on Arduino Uno). The function returns a digital
value representing the analog voltage.
void setup() {
Serial.begin(9600); // Initialize serial communication
}

void loop() {
int sensorValue = analogRead(A0); // Read analog voltage on pin A0
float voltage = sensorValue * (5.0 / 1024.0); // Convert to voltage
Serial.println(voltage); // Print the voltage to the serial monitor
delay(1000); // Wait for 1 second
}

How to do interfacing of Atmega328 based Arduino board with temperature sensor (LM35)

Interfacing an ATmega328-based Arduino board with a temperature sensor like the LM35 is a common and
straightforward task. The LM35 is an analog temperature sensor that provides an output voltage proportional to
the temperature in Celsius. Here's a step-by-step guide on how to interface an Arduino Uno (ATmega328-based)
with an LM35 temperature sensor:
Components Needed:
1. Arduino Uno or any ATmega328-based Arduino board.
2. LM35 temperature sensor.
3. Breadboard and jumper wires.
4. A 10μF capacitor (optional for noise reduction).
Interfacing Steps:
1. Wiring:
 Connect the LM35 to the Arduino as follows:
 LM35 VCC (Pin 1) to 5V on the Arduino.
 LM35 OUT (Pin 2) to any analog input pin on the Arduino (e.g., A0).
 LM35 GND (Pin 3) to GND on the Arduino.
 Optionally, you can add a 10μF capacitor between the VCC and GND pins of the LM35 to reduce noise in
the sensor readings.
 Make sure your connections are secure and there are no loose wires.
2. Arduino Code:
 Use the Arduino IDE to write code that reads the LM35 sensor data and converts it into a temperature
reading.
 Here's a simple example code to read the LM35 sensor and display the temperature in Celsius on the
serial monitor:
// LM35 Temperature Sensor interface

const int lm35Pin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
// Read the analog value from the LM35 sensor
int sensorValue = analogRead(lm35Pin);

// Convert the analog value to temperature in Celsius


float temperatureCelsius = (sensorValue * 5.0 / 1024.0 - 0.5) * 100.0;
Serial.print("Temperature: ");
Serial.print(temperatureCelsius);
Serial.println(" °C");

delay(1000); // Wait for 1 second before taking another reading


}

 Upload this code to your Arduino board using the Arduino IDE.
3. Monitor the Serial Output:
 Open the Arduino IDE, and go to "Tools" > "Serial Monitor" to open the serial monitor.
 You should see the temperature readings displayed in Celsius, which are continuously updated every
second.
4. Calibration (Optional):
 The LM35 sensor provides a linear output, but you may need to calibrate it for accuracy. To do this,
compare the readings with a known reference temperature and adjust your code accordingly.

How to do interfacing of Atmega328 based Arduino board with LVDT?


Interfacing an ATmega328-based Arduino board with an LVDT (Linear Variable Differential Transformer) requires
additional circuitry and signal conditioning due to the nature of LVDT output. LVDTs are used to measure linear
displacement or position and typically provide an AC output that needs to be rectified and converted to a form
suitable for measurement by the Arduino's ADC. Here's a general guide on how to interface an LVDT with an
ATmega328-based Arduino:
Components Needed:
1. ATmega328-based Arduino board (e.g., Arduino Uno)
2. LVDT sensor (with associated signal conditioning circuitry, if necessary)
3. Analog conditioning circuitry (e.g., diodes, resistors, capacitors)
4. Breadboard and jumper wires
5. Multimeter (for calibration and troubleshooting)
Interfacing Steps:
1. Understand LVDT Output:
 LVDTs generate an AC output voltage proportional to the position of the core within the coil windings.
This output needs to be conditioned for measurement by the Arduino.
2. Signal Conditioning:
 Depending on your specific LVDT and application, you might need to design signal conditioning circuitry.
This typically includes:
 Rectification: Convert the AC output to DC using a diode bridge or precision rectifier circuit. This
ensures that the output voltage is always positive.
 Filtering: Use capacitors and resistors to filter and smooth the rectified output, reducing noise
and providing a stable DC voltage.
 Amplification (if required): Depending on the sensitivity of the LVDT output and the desired
measurement range, you may need an amplifier to scale the signal appropriately.
3. Voltage Reference (Optional):
 For precise measurements, consider using a stable voltage reference (e.g., a voltage reference IC) to
improve measurement accuracy.
4. Wiring:
 Connect the conditioned LVDT output to an analog input pin on the Arduino (e.g., A0).
 Ensure that the ground (GND) of the LVDT circuit is connected to the Arduino's ground (GND) for a
common reference.
5. Arduino Code:
 Write Arduino code to read the analog voltage from the LVDT and convert it to the corresponding position
or displacement. This often involves calibrating the sensor based on its output range and the physical
motion it's measuring.
 For example, if you have a calibrated voltage-to-displacement relationship, you can use the
analogRead() function to read the voltage and convert it to a position in your code.
6. Calibration:
 Calibrate your system by comparing the Arduino's readings with known reference positions. Adjust your
code to account for any deviations or nonlinearities in the LVDT's output.
7. Monitoring and Display (Optional):
 Display the measured position or displacement on the serial monitor or on an external display, such as an
LCD.
8. Testing and Debugging:
 Use a multimeter to verify the LVDT's output voltage and the conditioned signal's accuracy. Ensure that
the Arduino readings match the expected values for different positions.
9. Safety Considerations:
 Be cautious about the power supply and voltage levels, especially when designing the signal conditioning
circuitry. Ensure proper isolation if necessary to avoid electrical hazards.

How to do interfacing of Atmega328 based Arduino board with strain gauge?

Components Needed:
1. ATmega328-based Arduino board (e.g., Arduino Uno)
2. Strain gauge (e.g., a Wheatstone bridge configuration)
3. Amplification and signal conditioning circuitry (e.g., instrumentation amplifier, Wheatstone bridge
completion)
4. Breadboard and jumper wires
5. Multimeter (for calibration and troubleshooting)
Interfacing Steps:
1. Understand Strain Gauge Operation:
 A strain gauge is a sensor that measures strain (deformation) on an object. It typically forms part of a
Wheatstone bridge circuit. When strain is applied, the resistance of the strain gauge changes, causing a
voltage imbalance in the bridge.
2. Wheatstone Bridge Configuration:
 Ensure you have a Wheatstone bridge configuration that includes the strain gauge. This bridge
configuration provides a differential voltage output proportional to the strain.
3. Signal Conditioning:
 Amplify and condition the small differential voltage output from the Wheatstone bridge.
 Use an instrumentation amplifier to amplify the signal while maintaining high common-mode
rejection.
 You may also need to complete the Wheatstone bridge using precision resistors to balance the
circuit.
4. Wiring:
 Connect the conditioned and amplified strain gauge output to an analog input pin on the Arduino (e.g.,
A0).
 Ensure that the ground (GND) of the strain gauge circuit is connected to the Arduino's ground (GND) for a
common reference.
5. Arduino Code:
 Write Arduino code to read the analog voltage from the strain gauge and convert it to a strain or force
value. This conversion often involves calibration based on known reference loads.
 For example, you can use the analogRead() function to read the voltage and convert it to a strain
or force value in your code.
6. Calibration:
 Calibrate your system by comparing the Arduino's readings with known loads or strains. Adjust your code
to account for any deviations or nonlinearities in the strain gauge's output.
7. Monitoring and Display (Optional):
 Display the measured strain or force values on the serial monitor or on an external display, such as an
LCD.
8. Testing and Debugging:
 Use a multimeter to verify the strain gauge's voltage output and the conditioned signal's accuracy. Ensure
that the Arduino readings match the expected values for different loads or strains.
9. Safety Considerations:
 Be cautious about the power supply and voltage levels, especially when designing the signal conditioning
circuitry. Ensure proper grounding and electrical safety practices.

You might also like