Embedded Systems Module2 by Manigandan
Embedded Systems Module2 by Manigandan
7-SEGMENT DISPLAY:
Output display devices that provide a way to display information in the form
of alphanumeric characters and digits.
10 pin package, 8 pins relate to the 8 LEDs, the remaining 2 pins at middle are internally shorted.
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 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 setup() {
void loop() {
// 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.
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);
• LED technology is more efficient than LCD as they do not use fluorescent bulb
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:
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
• 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.
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:
Resistance changes with light; From > 1 M in dark to 200 in full light
• In dark, Vout ≈ 5 V
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.
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.
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.
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.
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:
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.
• 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.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
avaialble() – gets the no of bits available for reading from serial port
begin() – sets the speed of serial communication
read() - returns the character that was received on the Rx pin of serial port
Arduino code to Receives from the hardware serial, sends to software serial and Receives from
software serial, sends to hardware serial.
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:
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.
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.
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.
The pulse width (also called a period) is a short duration of time in which the duty cycle will operate.
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.
The maximum possible output value occurs when D = (2n-1), so the value of Vr as an output is never
quite reached.