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

Embedded Systems Module2 by Manigandan

Embedded Systems Module2 by Manigandan

Uploaded by

Mridula Prasad
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)
3 views

Embedded Systems Module2 by Manigandan

Embedded Systems Module2 by Manigandan

Uploaded by

Mridula Prasad
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/ 37

PROGRAMMING KEYPAD & DISPLAY

7-SEGMENT DISPLAY:

Output display devices that provide a way to display information in the form
of alphanumeric characters and digits.

Consist of 7-segments (indicated as A-G) of light emitting diodes (LEDs)


and that is assembled into a structure like numeral 8.

An extra 8th segment is used to display dot (indicated as H/DP), which is


useful while displaying non integer number.

10 pin package, 8 pins relate to the 8 LEDs, the remaining 2 pins at middle are internally shorted.

Two outlines they are common cathode and common anode:

Cathode Anode
All LED’s negative terminals are connected to The common pin is given to a logic HIGH and the
the common ground pin hence HIGH on pins of the LED are given LOW to display a
corresponding positive pin glow particular LED. number.

Write a program to display hexadecimal values from 0 to 9 on the 7-segment display interfaced with
digital pins of Arduino Uno board.

int segPins[] = {4,5,7,8,9,11,10,6; // { a b c d e f g . )

int segCode[10][8] = {

// a b c d e f g

{ 0, 0, 0, 0, 0, 0, 1, 1}, // 0

{ 1, 0, 0, 1, 1, 1, 1, 1}, // 1

{ 0, 0, 1, 0, 0, 1, 0, 1}, // 2

{ 0, 0, 0, 0, 1, 1, 0, 1}, // 3

{ 1, 0, 0, 1, 1, 0, 0, 1}, // 4

{ 0, 1, 0, 0, 1, 0, 0, 1}, // 5
{ 0, 1, 0, 0, 0, 0, 0, 1}, // 6

{ 0, 0, 0, 1, 1, 1, 1, 1}, // 7

{ 0, 0, 0, 0, 0, 0, 0, 1}, // 8

{ 0, 0, 0, 0, 1, 0, 0, 1}, // 9

};

void displayDigit(int digit) {

for (int i=0; i < 8; i++) digitalWrite(segPins[i], segCode[digit][i]);

void setup() {

for (int i=0; i < 8; i++) pinMode(segPins[i], OUTPUT);

void loop() {

for (int n = 0; n < 10; n++) {

// display digits 0 - 9

displayDigit(n);

delay(1000);

LCD DISPLAY:

In the normal state, the crystals inside the liquid are twisted, and light can pass through. Once the
crystals are subjected to an electrical current, they untwist, blocking the light and making the portion of
the screen black.

Does not have specific resolution and are usually differentiated based on the number of letters.

16 x 2 means 16 letters on two lines

Every single letter in the alphabet and numbers can be displayed but it is not possible to display
graphics on this type of screen.

LiquidCrystal lcd(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);

Advantages of LCD display

• It does not have image burn-in phenomenon

• It is thinner and more compact than traditional display system

• LCD provide sharp image resolution with no bleeding

• They are not affected by the earth’s magnetic field


Disadvantages

• LED technology is more efficient than LCD as they do not use fluorescent bulb

• More energy efficient than LCD

Code an Arduino board to display “Hello! Testing” in the first line and “arduino lcd” in the second line.
Also display a smiley in the second line.
KEYPAD:

An array of switches that simplifies the interface to the microcontroller.

Keyboards are organized in a matrix of rows and columns; When a key is pressed, a row and a column
make contact.

Columns are connected to logic HIGH and are connected to an input port. Rows are connected to logic
LOW and are connected to an output port .

Code an Arduino board to display a key press on a 4x4 keypad on a 16x2 LCD screen.
SENSORS AND ACTUATORS:
Actuators Sensors

• DC Motor • Phototransistor

• Servo Motor • Reflectance Sensor

• Stepper Motor • IR Distance Sensor

• Contact Switch

• Bend Sensor

• Other Sensors

SERVO MOTOR:

Can turn from 0 degrees to 180 degrees; and the position is determined by pulses on control wires.

Pulse width modulation:


STEPPER MOTOR:

Motor advances in discrete steps based on the input pulses.

Stepper motors fall somewhere between a conventional DC motor and a servo motor. They can rotate
continuously like DC motors and be positioned precisely (in discrete steps) like servo motors.
ULTRASONIC SENSOR:

An ultrasonic sensor comprises several essential components that work together to measure
distances or detect objects using high-frequency sound waves.

At its core is the transducer, typically made of a piezoelectric crystal, which both emits and receives
ultrasonic waves. The receiver converts the reflected waves into electrical signals
DHT TEMP SENSOR:

They provide temperature and humidity readings accurate to within one decimal place.
LIGHT SENSORS:

1. PHOTODIODES:

Similar to phototransistors but Lower sensitivity

2. CADMIUM SULFIDE (CDS) CELL

Resistance changes with light; From > 1 M in dark to 200  in full light

Slow response time


3. PHOTOTRANSISTOR:

Converts light to electrical current.

• Vout = 5 – Iphoto  330 k

• In dark, Vout ≈ 5 V

• For Iphoto > 15 A, Vout drops to approx 0

Large resistor gives sensitivity to weak light.

MEMORY INTERFACE:
SPI: SERIAL PERIPHERAL INTERFACE:

It is a synchronous serial data protocol used by Microcontrollers for communicating with one or more
peripheral devices quickly over short distances.

There is always one master device (usually a microcontroller) which controls the peripheral devices.

Typically, there are three lines common to all the devices,


• Master In Slave Out (MISO) - The Slave line for sending data to the master.
EEPROM pin 2 to Arduino pin 12
• Master Out Slave In (MOSI) - The Master line for sending data to the peripherals.
EEPROM pin 5 to Arduino pin 11
• Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the
master.
EEPROM pin 6 to Arduino pin 13
• Slave Select (SS) - Allocated on each device which the master can use to enable and disable
specific devices and avoid false transmissions due to line noise.
EEPROM pin 1 to Arduino pin 10
All SPI settings are determined by the Arduino SPI Control Register (SPCR). Each bit in a control
register effects a particular setting, such as speed or polarity.

Data registers simply hold bytes. SPDR holds the byte which is about to be shifted out the MOSI line,
and the data which has just been shifted in the MISO line.

Status registers change their state based on various microcontroller conditions. The 7th bit of the SPI
status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI.

EEPROM INTERFACE USING SPI:

The device is enabled by pulling the Chip Select (CS) pin low.

It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data, so a 10ms pause
should follow each EEPROM write routine.

Connect EEPROM pins 3, 7 and 8 to 5v and pin 4 to ground.


The eighth bit disables the SPI interrupt, the seventh bit enables the SPI, the sixth bit chooses
transmission with the most significant bit going first, the fifth bit puts the Arduino in Master
mode, the fourth bit sets the data clock idle when it is low, the third bit sets the SPI to sample
data on the rising edge of the data clock, and the second and first bits set the speed of the SPI to
system speed / 4 (the fastest)
UART: UNIVERSAL ASYNCHRONOUS
RECEIVER/TRANSMITTER
It is used to transmit and receive serially and asynchronously. Two wires are required to transmit and
receive data Tx and Rx Pin.

A specific frequency is used for data communication known as baud rate. Baud rate is expressed as
bits per second (bps). It is a measure of speed of data transfer. Both receiving and transmitting UART
should work in same baud rate.

No clock signal i.e., Asynchronous data communication; Instead Start and stop bits are added to data
packet for identifying beginning and end of data packet. After detecting start bit UART starts to read the
incoming data packet.

Steps of UART Transmission

1. The transmitting UART receives data in parallel from the data bus:

2. The transmitting UART adds the start bit, parity bit, and the stop bit(s) to the data frame:

3. The entire packet is sent serially from the transmitting UART to the receiving UART. The receiving
UART samples the data line at the pre-configured baud rate:
4. The receiving UART discards the start bit, parity bit, and stop bit from the data frame:

5. The receiving UART converts the serial data back into parallel and transfers it to the data bus on the
receiving end:

Arduino functions for USB serial communication:

1. USART - UCSRnA - USART Control and Status Register A: This register provides status
information and controls some aspects of UART operation.

2. UCSRnB - USART Control and Status Register B: This register is used to enable/disable
USART features like interrupts and transmitter/receiver functionality.
3. UCSRnC - USART Control and Status Register C: This register configures the
communication mode, frame format, and parity settings.

4. UDRn - USART Data Register: The UDR0 register is used for both transmitting and receiving
data. Writing to UDR0 places data into the transmit buffer. Reading from UDR0 retrieves data
from the receive buffer.

• if (Serial) – indicates whether the USB serial connection is open or not.

• Serial.available()-Get the number of bytes available for reading from the serial port.

• Serial.begin()-Sets the data rate in bits per second (baud) for serial data transmission.

• Serial.end()-Disables serial communication, allowing the RX,TX to be used for input & output.

• Serial.find()-reads data from the serial buffer until the target is found.

• Serial.println()-Prints data as ASCII text followed by a carriage return and newline character.

• Serial.read()-Reads incoming serial data.

• Serial.readString() - reads characters from the serial buffer into a String.

• Serial.write() - Writes binary data to serial port. This data is sent as a byte or series of bytes
Print data received through serial communication on to the serial monitor of Arduino

Arduino code for serial interface to blink switch ON LED when “a” is received on serial port

Software Serial Library:

SoftwareSerial() – Need to enable serial communication

avaialble() – gets the no of bits available for reading from serial port
begin() – sets the speed of serial communication

overflow() – checks the serial buffer overflow has occurred

peek() – returns the character received in the serial port

read() - returns the character that was received on the Rx pin of serial port

Print() – works same as serial.print

Listen() – enables the selected serial port to listen

Write() – print data to transmit pin of software serial

Arduino code to Receives from the hardware serial, sends to software serial and Receives from
software serial, sends to hardware serial.

ENCODER & DECODER:


The encoder is a device or a transducer or a circuit that converts the information from one format to
another format, i.e., like electrical signals to counters or a PLC.

The feedback signal of the encoder will determine the position, count, speed, and direction. The
control devices are used to send commands to a particular function.
Decoder:
Applications:

1. War- Field -Flying Robot with a Night Vision Flying Camera

2. Speed Synchronization of Multiple Motors in Industries


PROGRAMMING TIMERS & COUNTERS:
Most embedded systems have a time component within them such as

• Timing references for control sequences

• To provide system ticks for operating systems

• Even the generation of waveforms

• Serial port baud rate generation and audible tones.

Timer – Periodic Signal

Counter – Aperiodic signal


1. The clock may be divided using a simple divider; a pre-scalar - effectively divides the clock by
the value that is written into the pre-scalar register. (Arduino Uno has a 16MHz internal
clock. It takes 62 nano seconds for a single count.)
2. The divided clock is then passed to a counter which performs count-down operation or count-
up operation
3. When a zero count is reached, an event occurs; such as an interrupt of an external line
changing state. The final block is an I/O control block. It generates interrupts and can control
the counter based on external signals

The Arduino Uno has 3 timers: Timer0, Timer1 and Timer2

1. Timer 0 – 8 bit timer ; Functions – delay(), millisec().

2. Timer 1 – 16 bit timer; Servo library

3. Timer 2 – 8 bit timer; Function – tone()

Key Registers in Timers:

Timer/Counter Control Registers (TCCRnA/B): Controls the mode and pre-scalar of timers.
Prescalars of 1, 8, 64, 256, 1024
Output Compare Registers (OCRx): Set the compare match value for timers, controls frequency and

+clock cycles.

Interrupt Registers (TIMSKx: Enables interrupts for overflow, TIFRx: Flags to indicate interrupt events)

Timer/Counter Register (TCNTn): Controls the counter value, timer increments/decrements and Sets
the pre-loader value.

Timer Modes:
1. Normal Mode: Timer counts from 0 to its max value (255 for 8-bit, 65535 for 16-bit).
Overflows trigger an interrupt if enabled.

Example: Timer1 Overflow Interrupt

2. CTC Mode (Clear Timer on Compare Match): Timer resets when it matches a value in OCRx.
Useful for generating precise frequencies.
Example: Mode to Generate 1 kHz Signal

3. PWM Modes (Fast PWM and Phase-Correct PWM): Generate PWM signals by setting the duty
cycle in OCRx. Used for motor control, LEDs, etc.

Example: Timer2 Fast PWM on Pin 3

To calculate preloader value for timer1 for time of 2 Sec:

TCNT1 = 65535 – (16x106x2 / 1024) = 34285

Using Timers as Counters:


Timer Interrupts:
• could check for serial or other input on a regular basis
• could read analog signal for regular sampling
• could produce custom signal at specific frequency
• and resets counter to zero so cycle begins anew

Code an Arduino board to read a pushbutton connected to a digital input to display millis() when
ON and display micros() when OFF. Blink an LED connected to a digital output with 500 ms delay.
Interrupt-Driven LED blink
A Custom PWM

PWM GENERATION:
Pulse width modulation (PWM) create simple square wave b varying the duty cycle.

Controls an analog variable, usually voltage or current.

The pulse width (also called a period) is a short duration of time in which the duty cycle will operate.

• 100% duty cycle - continuously on

• 0% duty cycle - continuously off

Code an Arduino board to control the brightness of an LED. Monitor the PWM waveform in an
oscilloscope and interface a buzzer to listen to different tones.
Code an Arduino board to control the speed of a DC motor using potentiometer.

ANALOG TO DIGITAL (ADC) CONVERTER:


Program an Arduino board to read analog values from an analogy input pin, convert the value into
digital value and display it in a serial window.
Code an Arduino board to read a temperature sensor connected to an analog input A0 and display
the temperature value in serial window. Each time the value goes beyond 40 degree Celsius an
LED connected to a digital output glow as warning.
DIGITAL TO ANALOG (DAC) CONVERTER:
A digital-to-analog converter is a circuit which converts a binary input number into an analog output.
The number of possible output values is given by 2n.

The step size by Vr/2n is called the resolution.

The maximum possible output value occurs when D = (2n-1), so the value of Vr as an output is never
quite reached.

You might also like