Main
Main
work?
Embedded systems always function as part of a complete device --
that's what's meant by the term embedded.
Generally, they comprise a processor, power supply, and memory
and communication ports. Embedded systems use the
communication ports to transmit data between the processor and
peripheral devices.
The processor interprets this data with the help of minimal software
stored on the memory.
Often, embedded systems are used in real-time operating
environments and use a real-time operating system (RTOS) to
communicate with the hardware.
Structure of embedded systems 6
Smartphones:
Incorporate various embedded systems like the processor, memory, and sensors.
Perform functions such as communication, multimedia, and application execution.
Automotive Systems:
Engine control units (ECUs) regulate fuel injection, ignition timing, and emissions.
Anti-lock braking systems (ABS) provide improved vehicle control during braking.
Consumer Electronics:
Digital cameras, MP3 players, and smart TVs utilize embedded systems for image
processing, audio playback, and content streaming.
Medical Devices:
Implantable pacemakers and insulin pumps provide life-saving functionality.
Medical monitoring devices track vital signs and provide real-time feedback.
Application Domains of Embedded 8
Microprocessor Microcontroller
Intel Core i7 Arduino
AMD Ryzen Raspberry Pi
Qualcomm Snapdragon Texas Instruments MSP430
IBM POWER9 Atmel AVR
ARM Cortex-A STMicroelectronics STM32
Difference between 12
Components (COTS)
Commercial Off-the-Shelf (COTS) components refer to ready-made,
pre-built products that are readily available in the market and not
specifically developed for a particular customer or application.
These components are mass-produced by manufacturers and sold
to a wide range of customers for various purposes.
examples of Commercial Off-the-Shelf (COTS) components:
Computer Processors
Memory Modules
Display Panels
Microcontrollers
Sensors and not limited to these.
Microcontrollers on Arduino boards 14
ATmega328P: This is the microcontroller used in Arduino Uno, one of the most widely
used Arduino boards. It offers 32KB of flash memory, 2KB of SRAM, and 1KB of
EEPROM.
ATmega2560: Arduino Mega 2560 utilizes this microcontroller, which provides more
memory and I/O pins compared to Arduino Uno. It has 256KB of flash memory, 8KB of
SRAM, and 4KB of EEPROM.
ATmega32U4: The Arduino Leonardo and Arduino Micro boards feature this
microcontroller. It includes 32KB of flash memory, 2.5KB of SRAM, and 1KB of EEPROM.
The ATmega32U4 also has built-in USB support, allowing the board to appear as a
virtual keyboard or mouse when connected to a computer.
Key features and examples of 16
microcontrollers used in Arduino boards
ARM-based Microcontrollers:
Arduino Due: The Arduino Due is based on the Atmel SAM3X8E microcontroller,
which is powered by an ARM Cortex-M3 processor. It provides 512KB of flash
memory, 96KB of SRAM, and various advanced peripherals.
Arduino MKR Family: Arduino MKR boards, such as MKR1000, MKR WiFi 1010, or
MKR Zero, are based on various ARM Cortex-M0 or Cortex-M4 microcontrollers.
These boards offer different combinations of memory, connectivity options, and
power-saving features, catering to diverse IoT and wireless communication
applications.
Version of Arduino 17
Difference between 8051 and AVR
18
Bus width 8051 microcontrollers have a bus width of 8 bits. AVR microcontrollers have bus width of 8-bit. But, some
AVR microcontrollers also have a bus width of 32 bits.
Developer 8051 microcontroller was developed by Intel. AVR microcontroller was produced by Atmel
Corporation.
Memory 8051 microcontrollers have Von Neumann AVR microcontrollers have Modified Harvard
Architecture architecture. architecture.
Instruction set 8051 microcontrollers are based on CISC (Complex AVR microcontrollers are based on RISC (Reduced
architecture Instruction Set Computer) architecture. Instruction Set Computer) architecture.
Registers 8051 microcontrollers have a smaller number of AVR microcontrollers have a greater number of registers.
registers.
Power consumption The power consumption for 8051 microcontrollers is AVR microcontrollers consume less power than 8051.
average.
19
20
21
When a reset occurs, the system restarts, and the processor initializes
itself, including clearing memory, resetting peripheral devices, and
executing startup routines.
The embedded system components and the microcontroller play a crucial role in
controlling and coordinating the operations of the washing machine, enabling
efficient and automated washing processes.
Program Selection: The user selects a wash program using the control panel. The
microcontroller receives the input and processes it.
Control Algorithm Execution: Based on the selected program and sensor inputs,
the microcontroller executes control algorithms to regulate the motor speed,
water inlet valve, and other components. It ensures the right amount of water is
added, the drum rotates at the desired speed, and the temperature is
maintained as per the program.
washing machine (Cont) 30
The official Arduino IDE is the most commonly used IDE for Arduino
development, but there are also alternative IDEs available, such as
PlatformIO and Visual Studio Code with Arduino extensions.
Key components and functionalities 33
of an Arduino IDE:
Code Editor: The IDE provides a code editor where you can write your Arduino
programs. It offers features like syntax highlighting, auto-completion, and
indentation to assist you in writing clean and error-free code. The code editor is
where you write the instructions that control the behavior of your Arduino board.
Compiler and Uploader: Once you have written your Arduino code, the IDE
compiles it into machine-readable instructions that can be understood by the
Arduino board's microcontroller. The compiler checks for syntax errors and other
issues in your code. After successful compilation, the IDE uploads the compiled
code to the Arduino board, making it ready to run.
Key components and functionalities 34
of an Arduino IDE: (Cont.)
Serial Monitor: The IDE provides a serial monitor tool that allows you
to communicate with your Arduino board through the serial port. It
displays the data sent by the Arduino and allows you to send
commands or instructions from the computer to the board. The serial
monitor is useful for debugging and monitoring the behavior of your
Arduino programs.
following code:
Summary:
Analog Input: 40
On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte)
value.
This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum
value of (2^15) - 1).
On the Arduino Due and SAMD based boards (like MKR1000 and Zero), an int stores a
32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum
value of -2^31 and a maximum value of (2^31) - 1).
int’s store negative numbers with a technique called (2’s complement math). The
highest bit, sometimes referred to as the "sign" bit, flags the number as a negative
number. The rest of the bits are inverted and 1 is added.
The Arduino takes care of dealing with negative numbers for you, so that arithmetic
operations work transparently in the expected manner. There can be an unexpected
complication in dealing with the bitshift right operator (>>) however.
Syntax 43
Parameters
var: variable name.
val: the value you assign to that variable.
Example Code
44
This code creates an integer called 'countUp', which is initially set as the
number 0 (zero).
The variable goes up by 1 (one) each loop, being displayed on the serial
monitor.
void setup() {
Serial.begin(9600); // use the serial port to print the number
}
void loop() {
countUp++; //Adds 1 to the countUp int on every loop
Serial.println(countUp); // prints out the current state of countUp
delay(1000);
}
Notes and Warnings 45
DIY
https://docs.arduino.cc/learn/starting-guide/getting-started-arduino
For more data types and examples, refer above link
bool 48
Description
A bool holds one of two values, true or false. (Each bool variable
occupies one byte of memory.)
Syntax
bool var = val;
Parameters
var: variable name.
val: the value to assign to that variable.
Code shows how to use the bool datatype. 49
Syntax
float var = val;
Parameters
var: variable name.
val: the value you assign to that variable.
z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)
Example Code 51
float myfloat;
float sensorCalbrate = 1.117;
int x;
int y;
float z;
x = 1;
y = x / 2; // y now contains 0, ints can't hold fractions
z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)
unsigned char 52
Description
An unsigned data type that occupies 1 byte of memory. Same as the
byte datatype.
The unsigned char datatype encodes numbers from 0 to 255.
For consistency of Arduino programming style, the byte data type is to
be preferred.
Syntax
unsigned char var = val;
Parameters
var: variable name.
val: the value to assign to that variable.
char 53
Parameters
var: variable name.
val: the value to assign to that variable.
Example Code 55
Syntax
byte var = val;
Parameters
var: variable name.
val: the value to assign to that variable.
void 57
The void keyword is used to indicate that a function does not return
a value.
This is particularly useful in embedded systems when you have
functions that perform actions but don't need to provide a result.
Example Code 58
void setup() {
// ...
}
void loop() {
// ...
}
Example Code 59
Serial.print("Counter: "); }
Serial.println(counter);
}
Arduino void setup 60
As the void setup function is called only once at the very beginning
of the program, this will be the place to:
Now, in the void loop you’ll write your main program, knowing that
the initialization is already done. In this function, always keep in mind
that the last line is followed by the first line!
Also, any variable you’ve declared inside the void loop will be lost
when the program exits and enters the function again. So, if you
want to be able to keep data between 2 void loop, make sure to
declare variables in a more global scope.
Arithmetic & Logical Operators 62
Addition: +
Subtraction: -
Multiplication: *
Division: /
Modulus (remainder): %
Simple Calculator using Arithmetic 64
Operators
Introduction to 4x4 keypad 65
Scan Keys:
To detect a pressed key, the microcontroller grounds all rows by
providing 0 to the output latch, and then it reads the columns shown in
above fig.
Yes…..
The code lacked a debounce mechanism after detecting a key
press. This meant that the code might interpret a single key press as
multiple presses due to bouncing.
Without a debounce delay, a key press might generate multiple
state changes in a short period.
Modified Code 74
void loop() {
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns char key = getKey();
char keys[ROWS][COLS] = { if (key) {
{'1','2','3','A'}, Serial.println(key);
{'4','5','6','B'}, }
{'7','8','9','C'}, }
{'*','0','#','D'} char getKey() {
}; static char lastKey = 0;
byte rowPins[ROWS] = {13, 12, 11, 10}; keypad char currentKey = 0;
byte colPins[COLS] = {9, 8, 7, 6}; void setup() {
for (byte i = 0; i < ROWS; i++) { for (byte c = 0; c < COLS; c++) {
pinMode(rowPins[i], INPUT_PULLUP); digitalWrite(colPins[c], LOW);
} for (byte r = 0; r < ROWS; r++) {
for (byte i = 0; i < COLS; i++) { if (digitalRead(rowPins[r]) == LOW) {
pinMode(colPins[i], OUTPUT); currentKey = keys[r][c];
} }
Serial.begin(9600); //initialize serial communication }
} digitalWrite(colPins[c], HIGH);
}
static char lastKey = 0;: Introduces a static variable 75
lastKey to store the last detected key. This variable
will persist its value between function calls, allowing
us to compare the current key with the last key.
Connect the pins of the LCD module to the Arduino Uno as follows:
Potentiometer Setup:
The potentiometer is used to adjust the contrast of the LCD. Connect its
outer pins to +5V and GND, and the middle pin to VEE on the LCD.
Library Installation:
You need the "LiquidCrystal" library to control the LCD. Install it via the
Arduino IDE: Sketch > Include Library > LiquidCrystal.
Initialization: 81
In your Arduino sketch, include the LiquidCrystal library and initialize the
LCD with the appropriate parameters:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 6, 7, 8); // RS, E, D4, D5, D6, D7
Setup Function: 82
void setup()
{
lcd.begin(16, 2); // Set the LCD size (columns x rows)
lcd.clear(); // Clear the display
lcd.print("Hello, World!");
}
Writing Text:
You can use functions like lcd.print() and lcd.setCursor() to write text
and position the cursor.
Other Functions:
Explore the library for additional functions like scrolling, custom
characters, and more.
Loop Function: 84
void loop()
{
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("Arduino Uno");
delay(1000); // Wait for a second
lcd.clear(); // Clear the display
delay(500); // Wait for half a second
}
Temperature Converter 85
void setup() {
Serial.begin(9600);
}
void loop() {
float celsius, fahrenheit;
Serial.println("Enter temperature in Celsius:");
while(!Serial.available()); // Wait for user input
celsius = Serial.parseFloat(); // Read temperature in Celsius
fahrenheit = (celsius * 9.0 / 5.0) + 32.0; // Celsius to Fahrenheit
conversion formula
Serial.print("Temperature in Fahrenheit: ");
Serial.println(fahrenheit);
}
Display the temperature conversion 86
Do it yourself
Ultrasonic sensor to measure distances and 89
display the distance on an LCD or through the
serial monitor.
HC SR-04 90
Components Needed:
Arduino board (e.g., Arduino Uno)
HC-SR04 ultrasonic sensor
Breadboard and jumper wires
Wiring:
Connect VCC on the HC-SR04 to +5V on the Arduino.
Connect GND on the HC-SR04 to GND on the Arduino.
Connect TRIG on the HC-SR04 to a digital pin (e.g., Pin 9) on the Arduino.
Connect ECHO on the HC-SR04 to another digital pin (e.g., Pin 10) on the
Arduino.
const int trigPin = 9;
const int echoPin = 10; 93
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
Now to get the RH and Temperature values, just convert the binary
data to decimal data.
Digital Output: 101
AND: &&
OR: ||
NOT: !
Temperature Alert System 103
const int temperatureThreshold = 30; else
const int fanPin = 9; {
const int buzzerPin = 10; digitalWrite(fanPin, LOW);
void setup() { digitalWrite(buzzerPin, LOW);
pinMode(fanPin, OUTPUT); }
pinMode(buzzerPin, OUTPUT); delay(1000); // Delay to avoid rapid checks
Serial.begin(9600); }
} int readTemperature() {
void loop() { // Replace this function with your actual
temperature reading code
int temperature = readTemperature();
// For simplicity, we return a constant value here.
if (temperature > temperatureThreshold &&
temperature < 100) return 25;
{ }
digitalWrite(fanPin, HIGH);
digitalWrite(buzzerPin, HIGH);
Serial.println("Temperature is too high! Cooling
and sounding the alarm.");
}
Password-Protected Access 104
const int buttonPin = 2;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
Serial.begin(9600); Serial.println("Access granted.");
} delay(2000);
digitalWrite(ledPin, LOW);
while (Serial.available() < 4); // Wait for user input
} else {
for (int i = 0; i < 4; i++) {
}
}
int getPassword() { 105
int password = 0;
Serial.println("Enter the password (4-digit number):");
while (Serial.available() < 4); // Wait for user input
for (int i = 0; i < 4; i++) {
password = password * 10 + (Serial.read() - '0'); // Convert ASCII to
integer
}
return password;
}
pinMode(buttonPin, INPUT_PULLUP);: This line configures the
buttonPin as an input pin with the internal pull-up resistor enabled.
106
The pull-up resistor ensures that the button reads HIGH when not
pressed and LOW when pressed.
Comparison Operators: 107
Equal to: ==
Not equal to: !=
Greater than: >
Less than: <
Greater than or equal to: >=
Less than or equal to: <=
Assignment Operators: 108
Assignment: =
Addition assignment: +=
Subtraction assignment: -=
Multiplication assignment: *=
Division assignment: /=
Modulus assignment: %=
Bitwise Operators: 109
The while loop is useful when the number of iterations is not known in
advance, and the loop continues until a certain condition is met.
Reading Analog Input 113
UNIT-3 114
Parallel Transmission:
Serial Communication Parallel Communication
A single communication link is used Multiple parallels links used to
to transfer data from one end to transmit the data.
another.
Data flows in multiple lines.
Data(bit) flows in bi-direction.
Not cost-efficient.
Cost-efficient.
Eight bits transferred at one clock
One bit transferred at one clock pulse.
pulse.
Fast in comparison of serial
Slow in comparison of parallel transmission.
transmission.
Used for short distance.
Used for long-distance.
Half-duplex since the data is either
Full duplex as sender can send as send or receive.
well as receive the data.
No converters are required.
Converters are required
Communication Protocols 119
Advantages Disadvantages
High-speed data transfer. Lack of in-built error checking.
Full-duplex Communication. Limited scalability.
Versatility and ease of Unsuitable for long-distance
implementation. communication.
Arbitrary data size. More power consumption.
Support for multiple slave devices.
Click the following link and implement the same using tinker Cad
https://circuitdigest.com/microcontroller-projects/arduino-spi-
communication-tutorial
Arduino SPI library used in Arduino IDE.
128
The library <SPI.h> is included in the program for using the following
functions for SPI communication.
SPI.begin()
USE: To Initialize the SPI bus by setting SCK, MOSI, and SS to outputs, pulling
SCK and MOSI low, and SS high.
SPI.setClockDivider(divider)
USE: To Set the SPI clock divider relative to the system clock. The available
dividers are 2, 4, 8, 16, 32, 64 or 128.
Dividers: SPI_CLOCK_DIV2, SPI_CLOCK_DIV4, SPI_CLOCK_DIV8,
SPI_CLOCK_DIV16, SPI_CLOCK_DIV32, SPI_CLOCK_DIV64, SPI_CLOCK_DIV128
SPI.attachInterrupt(handler)
USE: This function is called when a slave device receives data from the
master.
SPI.transfer(val)
USE: This function is used to simultaneously send and receive the data
between master and slave.
SPI Protocol for communication 129
between two Arduinos.
In this tutorial we will use two Arduino Uno,s one as master and other
as slave.
Both Arduino are attached with a LED & a push button separately.
Master LED can be controlled by using slave Arduino’s push button
and slave Arduino’s LED can be controlled by master Arduino’s push
button using SPI communication protocol present in arduino.
Components Required 130
Diagram
Arduino SPI Master Programming Explanation 132
#include<SPI.h>
#define ipbutton 2
int buttonvalue, x;
void setup (void)
{
Serial.begin(115200); //Starts Serial Communication at Baud Rate 115200
pinMode(ipbutton,INPUT); //Sets pin 2 as input
pinMode(LED,OUTPUT); //Sets pin 7 as Output
SPI.begin(); //Begins the SPI commnuication
SPI.setClockDivider(SPI_CLOCK_DIV8);//Sets clock for SPI communication at 8 (16/8=2Mhz)
digitalWrite(SS,HIGH);// Setting SlaveSelect as HIGH (So master doesnt connnect with slave)
}
void loop(void) digitalWrite(SS, LOW);//Starts communication with
Slave connected to master
133
{
Mastersend = x;
byte Mastersend,Mastereceive;
Mastereceive=SPI.transfer(Mastersend); //Send the
buttonvalue = digitalRead(ipbutton);
mastersend value to slave also receives value from
//Reads the status of the pin 2 slave
if(buttonvalue == HIGH) //Logic for if(Mastereceive == 1) //Logic for setting the LED
Setting x value (To be sent to slave) output depending upon value received from slave
depending upon input from pin 2 {
{ digitalWrite(LED,HIGH); //Sets pin 7 HIGH
Serial.println("Master LED ON");
x = 1;
}
} else
else {
{ digitalWrite(LED,LOW); //Sets pin 7 LOW
x = 0; Serial.println("Master LED OFF");
} }
delay(1000);
}
Arduino SPI Slave Programming Explanation 134
#include<SPI.h>
#define LEDpin 7
#define buttonpin 2
volatile boolean received;
volatile byte Slavereceived,Slavesend;
int buttonvalue;
int x;
void setup()
{
Serial.begin(115200);
pinMode(buttonpin,INPUT); // Setting pin 2 as INPUT
pinMode(LEDpin,OUTPUT); // Setting pin 7 as OUTPUT
pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT (Have to Send
data to Master IN
SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
received = false;
SPI.attachInterrupt(); //Interuupt ON is set for SPI
commnucation
}
ISR (SPI_STC_vect) //Inerrrput routine function
{
Slavereceived = SPDR; // Value received from master if store in
variable slavereceived
received = true; //Sets received as True
}
Inter-Integrated Circuit (I2C) 135
he I2C protocol involves using two lines to send and receive data: a
serial clock pin (SCL) that the Arduino Controller board pulses at a
regular interval, and a serial data pin (SDA) over which data is sent
between the two devices.
In I2C, there is one controller device, with one or more peripheral
devices connected to the controllers SCL and SDA lines.
Inter-Integrated Circuit (I2C) 137
As the clock line changes from low to high (known as the rising
edge of the clock pulse), a single bit of information is transferred
from the board to the I2C device over the SDA line.
As the clock line keeps pulsing, more and more bits are sent until a
sequence of a 7 or 8 bit address, and a command or data is
formed.
When this information is sent - bit after bit -, the called upon device
executes the request and transmits it's data back - if required - to
the board over the same line using the clock signal still generated
by the Controller on SCL as timing.
Because the I2C protocol allows for each enabled device to have
it's own unique address, and as both controller and peripheral
devices to take turns communicating over a single line, it is possible
for your Arduino board to communicate (in turn) with many devices,
or other boards, while using just two pins of your microcontroller.
An I2C message on a lower bit-level looks something
like this: 141
The controller sends out instructions through the I2C bus on the data
pin (SDA), and the instructions are prefaced with the address, so
that only the correct device listens.
Then there is a bit signifying whether the controller wants to read or
write.
Every message needs to be acknowledged, to combat
unexpected results, once the receiver has acknowledged the
previous information it lets the controller know, so it can move on to
the next set of bits.
8 bits of data, Another acknowledgement bit, 8 bits of data,
Another acknowledgement bit.
Wire Library 142
But how does the controller and peripherals know where the
address, messages, and so on starts and ends? That's what the SCL
wire is for.
It synchronizes the clock of the controller with the devices, ensuring
that they all move to the next instruction at the same time.
However, you are nearly never going to actually need to consider
any of this, in the Arduino ecosystem we have the Wire library that
handles everything for you.
•onReceive() - Register a function to be called when a peripheral receives a transmission
•onRequest() - Register a function to be called hwen a controller requests data
•setWireTimeout() - Sets the timeout for transmissions in controller mode
Wire Library
•clearWireTimeoutFlag() - Clears the timeout flag
•getWireTimeoutFlag() - Checks whether a timeout has occurred since the last time the flag was cleared.
143
#include <Wire.h>: This line includes the Wire library, which is necessary for I2C
communication.
Wire.begin();: Initializes the Wire library, allowing the Arduino to join the I2C bus. The master
doesn't need a specific address in this case.
Wire.requestFrom(8, 6);: Sends a request to the I2C peripheral device with address 8, asking
for 6 bytes of data.
while (Wire.available()) {: Checks if there is data available to be read from the peripheral.
char c = Wire.read();: Reads a byte of data from the peripheral and stores it in the variable
c.
Serial.print(c);: Prints the received character to the Serial Monitor.
delay(500);: Introduces a delay of 500 milliseconds before the next iteration of the loop. This
delay allows time for the peripheral device to respond and for the Serial Monitor to display
the received data.
Peripheral Sender Sketch 149
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
Wire.begin(8);: Initializes the Wire library and joins the I2C bus with the peripheral
device's address set to 8. This is the address that the master device will use to
communicate with this peripheral.
Wire.onRequest(requestEvent);: Registers the requestEvent function as an event
handler. This function will be executed whenever the master device requests data
from this peripheral.
delay(100);: Introduces a delay of 100 milliseconds between iterations of the loop.
This delay is used to prevent the loop from executing too rapidly.
void requestEvent() {: This is a custom function named requestEvent. It is
automatically called by the Wire library when the master device requests data from
the peripheral.
Wire.write("hello ");: In response to the master's request, this line sends the string "hello
" (containing 6 characters) back to the master using the Wire library's write function.
DIY 151
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
Wire.beginTransmission(4); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
Peripheral Receiver Sketch 154
void loop()
{
#include <Wire.h> delay(100);
}
void setup()
{ // function that executes whenever data is received from master
Wire.begin(4); // join i2c bus with address #4 // this function is registered as an event, see setup()
Wire.onReceive(receiveEvent); // register event void receiveEvent(int howMany)
Serial.begin(9600); // start serial for output {
} while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
Speed or Data rates 155
Advantages Disadvantages
First: The transmitting Second: The transmitting Third: The entire packet is sent
UART receives data in UART adds the start bit, parity serially starting from start bit to stop
parallel from the data bit, and the stop bit(s) to the bit from the transmitting UART to the
bus. data frame. receiving UART. The receiving UART
samples the data line at the
preconfigured baud rate
160
Fourth: The receiving UART discards the start Fifth: The receiving UART converts the
bit, parity bit, and stop bit from the data serial data back into parallel and
frame. transfers it to the data bus on the
receiving end.
Advantages and Disadvantages of UART 161
Advantages Disadvantages
Simple and Easy Implementation. Synchronization Requirement.
Full Duplex Communication. Potential Synchronization Issues.
Independent Operation. Limited Error Detection.
Support for Longer Data Frames. Lack of Addressing.
Point-to-Point Communication. Limited Speed.
Programming Communication
Protocols
SPI, I2C & UART IN ARDUINO-UNO R3
Protocol Pins in Arduino 163
I2C Programming with Arduino 164
https://docs.arduino.cc/learn/communication/wire
UNIT-4 165
Data Converters
Real World Analog Signals and 166
Analog-to-Digital Conversion
Analog Signals: Analog signals are continuous, real-world
representations of physical quantities, such as temperature, voltage,
pressure, etc.
Temperature Signals:
Examples: Weather monitoring (thermometers), industrial processes
(thermal sensors).
Characteristics: Continuous variation, sensitivity to environmental
changes.
Biomedical Signals:
Examples: Electrocardiogram (ECG), electroencephalogram (EEG),
blood pressure.
Clinical Importance: Diagnosis, monitoring, treatment.
Audio Signals:
Examples: Speech, music.
Characteristics: Continuous waveforms, complex frequencies.
Analog-to-Digital Conversion (ADC) 168
Pipeline ADC: Divides the conversion process into stages for higher
speed.
A non-inverting comparator is an
op-amp based comparator for
which a reference voltage is
applied to its inverting terminal
and the input voltage is applied to
its non-inverting terminal.
This op-amp based comparator is
called as non-inverting
comparator because the input
voltage, which has to be
compared is applied to the non-
inverting terminal of the op-amp.
Operation 181
As we have a 4-bit R-2R resistive ladder network, this 312.5 mV voltage change is one-
sixteenth the value of the +5V input (5/0.3125 = 16) voltage so is classed as the Least
Significant Bit, (LSB).
Continue the same for giving weights to each individual bits and find the final
equation for 4 Bit DAC. Also write the generalized equation for n-bit DAC
194