0% found this document useful (0 votes)
9 views25 pages

ESD All Units

The document provides an overview of microcontrollers, specifically the 8051 architecture and Arduino platform, detailing their components, memory organization, and programming methods. It also introduces embedded systems, their characteristics, applications, and distinctions from general-purpose computing systems. Additionally, it covers various processors, programmable logic devices, and communication interfaces relevant to embedded systems.

Uploaded by

abhishek ch
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)
9 views25 pages

ESD All Units

The document provides an overview of microcontrollers, specifically the 8051 architecture and Arduino platform, detailing their components, memory organization, and programming methods. It also introduces embedded systems, their characteristics, applications, and distinctions from general-purpose computing systems. Additionally, it covers various processors, programmable logic devices, and communication interfaces relevant to embedded systems.

Uploaded by

abhishek ch
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/ 25

ESD All Units

📚 UNIT-1: INTRODUCTION TO MICROCONTROLLERS


Developed by Intel in 1980 for embedded applications.

8-bit microcontroller, based on Harvard architecture (separate program and data memories).

It consists of:

4KB on-chip ROM (program memory)

128 bytes on-chip RAM (data memory)

32 Input/Output (I/O) lines divided into 4 ports

Two 16-bit timers/counters

A full duplex serial communication interface

Five interrupt sources

Mainly used in devices requiring dedicated control operations like washing machines, microwave ovens,
etc.

2. 8051 Architecture
CPU: Manages operations, has ALU, Accumulator (A), B register.

Memory Organization: 4KB ROM, 128B RAM, External Memory Support.

Timers/Counters: Two 16-bit timers for measuring time and event counting.

Serial Port: For serial communication.

Interrupt Control: Handles hardware interrupts.

Oscillator and Clock: Provides internal timing.

I/O Ports: Four parallel ports (P0, P1, P2, P3).

3. Pin Diagram of 8051

ESD All Units 1


40 Pins total:

Power Pins: Vcc (40), GND (20)

I/O Ports:

Port 0 (32–39): multiplexed address/data bus.

Port 1 (1–8): pure I/O port.

Port 2 (21–28): address bus in external memory.

Port 3 (10–17): special functions (serial, interrupts, etc.)

Special Pins:

RST (9): Reset

ALE (30): Address Latch Enable

PSEN (29): Program Store Enable

EA (31): External Access Enable

XTAL1, XTAL2 (18,19): Oscillator connection.

4. Memory Organization
Program Memory (ROM):

4KB internal ROM, expandable to 64KB external memory.

Data Memory (RAM):

128 bytes internal RAM divided as:

Register Banks (0–1FH)

ESD All Units 2


Bit Addressable Area (20H–2FH)

General Purpose RAM (30H–7FH)

SFRs (Special Function Registers):

Located from 80H to FFH for controlling hardware like timers, serial communication, ports.

5. Addressing Modes
Immediate Addressing: Operand given directly. (e.g., MOV A, #55H)

Register Addressing: Operand stored in registers (R0–R7).

Direct Addressing: Address is directly mentioned. (e.g., MOV A, 30H)

Register Indirect Addressing: Address held inside register (e.g., @R0).

Indexed Addressing: Accessing program memory using DPTR and A. (MOVC A, @A+DPTR)

6. Instruction Set of 8051


Data Transfer Instructions: MOV, XCH, PUSH, POP.

Arithmetic Instructions: ADD, SUBB, INC, DEC, MUL, DIV.

Logical Instructions: ANL, ORL, XRL, CLR, CPL.

Branching Instructions: SJMP, LJMP, AJMP, JC, JNC, JZ, JNZ.

Bit Manipulation Instructions: SETB, CLR, CPL bit.

7. Overview of Arduino
Arduino is an open-source platform for developing interactive electronics projects.

Arduino boards are based on microcontrollers (mostly ATmega series).

Arduino uses its own IDE (Integrated Development Environment) for programming in simplified C++.

8. Introduction to ATMEGA 328P


Microcontroller used in Arduino UNO.

Features:

32KB Flash Memory

2KB SRAM

1KB EEPROM

23 programmable I/O lines

10-bit ADC

SPI, I2C, UART interfaces.

9. Arduino Board Introduction

ESD All Units 3


Arduino boards are simple development boards with:

USB interface for programming.

Voltage regulator circuitry.

Power pins, ground pins.

Reset button.

Digital and Analog I/O pins.

10. Arduino Programming

1. setup()

➤ Explanation:
Called once when the program starts.

Used to initialize pin modes, start serial communication, and initialize libraries.

✅ Important:
Without a proper setup() , the hardware might not function correctly.

➤ Example Program:
void setup() {
pinMode(13, OUTPUT); // Set pin 13 as output
}

void loop() {
// Nothing here for now
}

2. loop()

➤ Explanation:
Continuously executes after setup() .

Main logic of the program goes here.

Runs forever until Arduino is turned off/reset.

✅ Important:
If you want repeated tasks (e.g., blinking an LED), place them in loop() .

➤ Example Program:

ESD All Units 4


void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // Turn LED ON
delay(1000); // Wait for 1 second
digitalWrite(13, LOW); // Turn LED OFF
delay(1000); // Wait for 1 second
}

3. digitalRead(pin)

➤ Explanation:
Reads a digital input pin: returns either HIGH or LOW .

Useful for reading switches, sensors, etc.

✅ Important:
Before using digitalRead() , set the pin as INPUT with pinMode() .

➤ Example Program:
int buttonPin = 2;
int ledPin = 13;
int buttonState = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn ON LED
} else {
digitalWrite(ledPin, LOW); // Turn OFF LED
}
}

ESD All Units 5


4. digitalWrite(pin, value)

➤ Explanation:
Sets a digital output pin to HIGH (5V) or LOW (0V).

Used for controlling LEDs, buzzers, relays, etc.

✅ Important:
The pin must be set as OUTPUT before using digitalWrite() .

➤ Example Program:
void setup() {
pinMode(8, OUTPUT);
}

void loop() {
digitalWrite(8, HIGH); // Turn ON LED
delay(500);
digitalWrite(8, LOW); // Turn OFF LED
delay(500);
}

5. analogRead(pin)

➤ Explanation:
Reads an analog input value between 0 to 1023.

Used for reading sensors like potentiometers, temperature sensors, etc.

Pins A0 to A5 are used on Arduino UNO.

✅ Important:
The value is proportional to input voltage (0–5V for UNO).

➤ Example Program:
int sensorPin = A0;
int sensorValue = 0;

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

void loop() {
sensorValue = analogRead(sensorPin);

ESD All Units 6


Serial.println(sensorValue);
delay(500);
}

6. analogWrite(pin, value)

➤ Explanation:
Generates PWM (Pulse Width Modulation) signal.

Used to control brightness of LEDs, speed of motors, etc.

Value between 0 (0% duty cycle) and 255 (100% duty cycle).

✅ Important:
Only specific pins (like 3, 5, 6, 9, 10, 11 on UNO) support analogWrite() .

➤ Example Program:
int ledPin = 9;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
analogWrite(ledPin, 255); // Full brightness
delay(1000);
analogWrite(ledPin, 128); // Half brightness
delay(1000);
analogWrite(ledPin, 0); // LED OFF
delay(1000);
}

📚 UNIT-2: INTRODUCTION TO EMBEDDED SYSTEMS


1. Definition of Embedded Systems
An Embedded System is an electronic system that combines hardware and software to perform a
specific dedicated function.

It is not a general-purpose computing system.

The software (firmware) is embedded permanently in the hardware.

ESD All Units 7


Examples: Microwave oven controllers, Digital watches, ATM machines.

2. Embedded Systems vs General Purpose Computing Systems


Embedded Systems:

Application-specific (designed for one task only).

Highly reliable and often work in real-time.

Limited user interface.

Example: Automatic Washing Machine.

General Purpose Computing Systems:

Designed to perform multiple tasks.

User-driven and flexible.

Complex operating systems like Windows/Linux.

Example: Laptop, Desktop PC.

3. History of Embedded Systems


Early 1960s:
First embedded systems used in space applications (Apollo Guidance Computer).

1961:

Autonetics D-17 missile guidance computer — first mass-produced embedded system.

1970s:

Development of microcontrollers (combining CPU, RAM, ROM in one chip).

1980s and beyond:

Growth of embedded systems in consumer electronics, automotive industries.

Today:
Embedded systems are integrated with IoT, Artificial Intelligence, and Smart Devices.

4. Classification of Embedded Systems


A. Based on Generation:

First Generation:
8-bit microcontrollers (simple devices).

Second Generation:
16-bit processors, better performance.

Third Generation:

32-bit and DSP processors.

Fourth Generation:

ESD All Units 8


SoCs, FPGAs, AI-enabled embedded systems.

B. Based on Complexity:

Small Scale: Simple functionality (e.g., MP3 players).

Medium Scale: Complex applications with RTOS (e.g., Smart Meters).

Large Scale: Very complex systems (e.g., Airplane autopilot systems).

C. Based on Real-Time Requirements:

Hard Real-Time: Strict timing (e.g., Anti-lock Braking System).

Soft Real-Time: Some delays tolerable (e.g., Streaming video players).

D. Based on Triggering:

Event Triggered Systems: React on external events.

Time Triggered Systems: Execute based on timer or clock signals.

5. Major Application Areas of Embedded Systems


Consumer Electronics:
Mobile phones, Smart TVs, Cameras.

Home Appliances:
Microwave ovens, Refrigerators, Washing Machines.

Automotive:

ABS systems, Airbags, Engine Management Systems.

Industrial Automation:

Robotic arms, Process control.

Healthcare:
Medical instruments like ECG, infusion pumps.

Telecommunications:
Routers, Mobile base stations.

Banking:
ATM machines, Smart Card readers.

6. Purpose of Embedded Systems


Data Collection:

Sensors collect environmental data (e.g., temperature sensor).

Data Storage and Display:


Store or display collected data (e.g., Digital meters).

Data Communication:
Transfer data between systems (e.g., Wi-Fi modules).

ESD All Units 9


Monitoring:
Monitor parameters without controlling them (e.g., Heart rate monitors).

Controlling Devices:
Activate actuators based on sensed inputs (e.g., Air conditioners adjusting temperature).

User Interface:
Accept commands and display responses (e.g., ATM touch screen).

7. Characteristics and Quality Attributes of Embedded Systems


Characteristics:

Single Functionality:

Performs a dedicated task.

Reactive and Real-Time:

Must respond immediately to external inputs.

Low Power Consumption:


Designed for efficient power use.

Reliability:
Must work continuously and correctly.

Compact Size:
Small, portable, and integrated.

Quality Attributes:

Operational Quality:

Response time

Reliability

Throughput

Maintainability

Security

Non-Operational Quality:

Testability

Portability

Scalability

Evolvability (future upgrades)

✅ Tip:
Always remember — Embedded systems are designed for efficiency, reliability, and specific functionality.

ESD All Units 10


📚 UNIT-3: TYPICAL EMBEDDED SYSTEM
1. Core of Embedded System
The core is the heart of the embedded system that processes data and controls hardware.

It mainly includes:

Processor (CPU): Executes instructions.

Memory: Stores program code and data.

Input Devices: Take input from the environment.

Output Devices: Give output to users or control external systems.

Application Software: The specific embedded program.

✅ Key Tip:
Core = Processor + Memory + I/O Devices + Software.

2. General Purpose and Domain-Specific Processors


A. General Purpose Processors:

Microcontrollers (MCUs):

Small computer on a single chip.

Example: 8051, ATmega328P.

Microprocessors (MPUs):

Powerful CPU chip, needs external memory and I/O.

Example: Intel 8086, ARM Cortex-A9.

B. Domain-Specific Processors:

Digital Signal Processors (DSPs):

Specially designed to process real-time audio, video, or signals.

Example: TMS320 series.

✅ Tip:
Microcontroller = CPU + RAM + ROM + I/O ports together.

Microprocessor = Only CPU, needs external chips for memory/I/O.

3. Programmable Logic Devices (PLDs)


Hardware devices that can be programmed after manufacturing to perform customized logic operations.

Types:

PROM (Programmable ROM)

PAL (Programmable Array Logic)

ESD All Units 11


PLA (Programmable Logic Array)

FPGA (Field Programmable Gate Array)

FPGAs allow complex digital circuits to be designed quickly.

✅ Tip:
PLDs are flexible and cost-effective for small production volumes.

4. Application-Specific Integrated Circuits (ASICs)


Custom-designed integrated circuits made for a particular application.

Used when very high performance and compact size are required.

Cannot be reprogrammed once manufactured.

Example:

ASIC chip inside a mobile phone camera or a smart card.

✅ Tip:
ASICs are optimized for speed, power efficiency, and miniaturization.

5. Commercial-Off-The-Shelf Components (COTS)


Ready-made hardware or software products that can be purchased and used directly.

Saves time and cost compared to designing from scratch.

Examples:

Standard Wi-Fi modules.

GPS receiver chips.

USB communication modules.

✅ Tip:
COTS = "Buy and Use" components for faster development.

6. Sensors and Actuators


A. Sensors:

Devices that sense physical conditions and convert them into electrical signals.

Examples:

Temperature Sensor (LM35)

Light Sensor (LDR)

Pressure Sensor (BMP180)

Work as Input Devices for embedded systems.

B. Actuators:

Devices that convert electrical signals into physical actions (motion, heat, sound).

ESD All Units 12


Examples:

Motors

Heaters

Buzzers

Work as Output Devices.

✅ Tip:
Sensor = Senses input; Actuator = Produces output.

7. Onboard Communication Interfaces


Interfaces used for communication inside the embedded device:

A. I2C (Inter-Integrated Circuit):

2-wire protocol: SDA (Data), SCL (Clock).

Master-slave structure.

Used for sensors, EEPROMs, RTCs.

B. SPI (Serial Peripheral Interface):

4-wire protocol: MOSI, MISO, SCK, SS.

Full duplex communication.

Faster than I2C.

Used for SD cards, displays.

C. UART (Universal Asynchronous Receiver Transmitter):

Asynchronous serial communication.

Only 2 lines: TX (Transmit), RX (Receive).

Used for GPS, Bluetooth modules.

D. Parallel Interface:

Multiple data lines transfer multiple bits simultaneously.

Used for high-speed devices like printers, older LCD modules.

✅ Tip:
I2C = 2 wires (slow),

SPI = 4 wires (fast),

UART = serial with no clock.

8. External Communication Interfaces


Interfaces for communication with external world:

A. RS232:

Standard serial communication (wired).

ESD All Units 13


Old PC COM ports.

B. USB (Universal Serial Bus):

High-speed communication + power supply.

Widely used in computers, mobile chargers.

C. Infrared (IRDA):

Short-range, line-of-sight wireless.

Used in TV remotes.

D. Bluetooth:

Short-range wireless (10m range).

Used in wireless earphones, file transfer.

E. Wi-Fi:

Wireless local area network (LAN) communication.

Used for Internet access.

F. ZigBee:

Low power, low data rate wireless communication.

Ideal for home automation systems.

G. GPRS (General Packet Radio Service):

Mobile network-based communication.

Used for accessing the Internet on mobile devices.

✅ Tip:
RS232, USB = wired.

IR, Bluetooth, Wi-Fi, ZigBee, GPRS = wireless.

📚DEVELOPMENT
UNIT-4: EMBEDDED FIRMWARE DESIGN AND

1. Embedded Firmware Design Approaches

A. Super Loop Based Approach


Simplest and oldest approach.

All tasks are placed inside an infinite loop ( while(1) loop).

Tasks are executed sequentially one after another.

No operating system is used.

Suitable for small, simple, non-real-time systems.

ESD All Units 14


Advantages:

Easy to develop and debug.

No extra cost for OS.

Disadvantages:

Poor management of multiple tasks.

Difficult to handle real-time operations.

Enhancements:

Critical tasks handled using Interrupt Service Routines (ISR).

Use of Watchdog Timer (WDT) to reset system in case of hang.

B. Embedded OS Based Approach


Uses a Real-Time Operating System (RTOS) or simple Embedded OS.

Suitable for complex systems needing real-time task scheduling.

OS handles task switching, priority management, and timers.

Advantages:

Real-time response possible.

Easy to manage multiple tasks.

Dynamic task scheduling.

Disadvantages:

Higher memory and cost.

More complex development.

✅ Tip:
Use Super Loop for simple projects, and Embedded OS for complex, real-time embedded applications.

2. Embedded Firmware Development Languages

A. Assembly Language-Based Development


Low-level programming close to hardware.

Specific to the processor architecture.

Needs knowledge of microcontroller instruction set.

Advantages:

Very fast and optimized code.

Direct hardware control.

Disadvantages:

Hard to write and debug.

ESD All Units 15


Non-portable (specific to one processor).

B. High-Level Language-Based Development


Uses languages like C, C++.

Processor independent (mostly).

Code is compiled using a Cross-Compiler.

Advantages:

Faster development time.

Easier maintenance and debugging.

Code can be ported to other platforms easily.

Disadvantages:

Slightly less efficient compared to pure assembly.

Depends on quality of cross-compiler.

✅ Tip:
Today, most firmware is developed in C language because it balances control and ease.

3. Assembly Language to Hex File Translation Process

Step-by-Step Process:
1. Write Source Code:

Write the program in Assembly language and save it as .asm file.

2. Assemble Source Code:

Use an assembler (e.g., A51) to convert .asm file into .obj file.

Generates List file (.lst) and Object file (.obj).

3. Link and Locate:

If multiple object files exist, link them using a Linker.

Assign absolute memory addresses using Locator.

Output is an absolute object file.

4. Convert to Hex File:

Use an object-to-hex converter (e.g., OH51) to create a .hex file.

Hex file is a machine-readable file that can be loaded into the microcontroller.

✅ Tip:
Final Hex file contains the machine code for programming the microcontroller.

4. Advantages and Drawbacks of Assembly Language

ESD All Units 16


Advantages:
Highly optimized code for speed and memory.

Direct hardware control.

Good for real-time and time-critical tasks.

Efficient use of processor resources.

Drawbacks:
Difficult to understand, write, and debug.

Code is specific to one hardware platform (not portable).

Development time is longer.

Hard to maintain large programs.

5. Advantages and Drawbacks of High-Level Language

Advantages:
Faster application development.

Easy to understand, modify, and maintain code.

Allows code reusability and portability.

Supports complex programming concepts like functions, loops, structures.

Drawbacks:
May produce less optimized machine code.

Cross-compilers and high-level development tools are expensive.

Less control over specific hardware features compared to Assembly.

6. Mixing of Assembly and High-Level Languages

Why Mixing is Needed:


To combine efficiency of assembly with the ease of C programming.

Used when:

Certain parts of the code need speed optimization.

Direct hardware control is required.

Types of Mixing:
A. Mixing Assembly into High-Level Language:

Assembly code can be written inside a C program using special syntax (inline assembly).

Example in C:

ESD All Units 17


c
CopyEdit
#pragma asm
MOV A, #55H
#pragma endasm

B. Mixing High-Level into Assembly Program:

C library functions can be called from Assembly programs when needed.

✅ Tip:
Critical code (like Interrupts) can be written in Assembly, and the rest of the application in C.

📚 UNIT-5: EMBEDDED PROGRAMMING


1. Assembly Language Programming

Overview:
Assembly Language is low-level, hardware-specific programming.

Written using mnemonics (e.g., MOV , ADD , SUB ) directly understood by the microcontroller.

Requires thorough knowledge of the microcontroller architecture (e.g., 8051).

Features:

Close to machine code.

Hard to read and modify.

Faster and efficient execution.

Steps in Assembly Programming:


1. Write Code:

Use a text editor to write .asm file.

2. Assemble:

Assemble using an assembler to generate .lst and .obj files.

3. Link:

Link object files to create .abs file.

4. Object to Hex:

Convert .abs file to .hex using OH tool.

5. Burn to ROM:

Load .hex file into microcontroller using a programmer.

ESD All Units 18


✅ Note:
Modern assemblers can combine steps 2-4 automatically.

Elements of Assembly Programming:


Assembler Directives: ( ORG , DB , EQU , END )

Instruction Set: (MOV, ADD, SUB, etc.)

Addressing Modes:

Immediate

Register

Direct

Indirect

Base Index

✅ Tip:
Always end the program with the END directive.

Example Programs:

A. Addition (with Carry Detection):

PIN1 BIT P1.0


MAIN: CLR PIN1
MOV A, 30H
ADD A, 31H
JNC MAIN ; No Carry
SETB PIN1 ; Carry occurred
END

B. Subtraction of 16-bit Numbers:

CLR C
MOV A, R4
SUBB A, R6
MOV 20H, A
MOV A, R5
SUBB A, R7
MOV 21H, A

C. Multiplication:

ORG 00H
MOV A, 51H
MOV B, 52H

ESD All Units 19


MUL AB
MOV 53H, A
MOV 54H, B
END

D. Division:

MOV A, R0
MOV B, R1
DIV AB
MOV R2, A ; Quotient
MOV R3, B ; Remainder

2. Interfacing LED, LCD, and Keypad with 8051 Microcontroller

A. Interfacing LED with 8051:


LED is a simple output device.

LED Anode connected to MCU pin through resistor.

Program to Blink Single LED:

LEDPIN BIT P2.0


BLINK: CPL LEDPIN
MOV R3, #10
MOV R2, #0
MOV R1, #0
LOOP: DJNZ R1, LOOP
DJNZ R2, LOOP
DJNZ R3, LOOP
SJMP BLINK
END

Program for 8 LEDs Blinking:

BLINK: MOV P1, #0FFH


MOV A, P1
CALL DELAY
CPL A
MOV P1, A
CALL DELAY
SJMP BLINK

B. Interfacing LCD with 8051:


LCD is used for displaying characters.

ESD All Units 20


Important pins: RS, R/W, E, and D0-D7.

Basic LCD Commands:

RS=0 → Command mode

RS=1 → Data mode

E → Enable latch pulse

Program to Display 'NO':

ORG 00H
MOV A, #38H
ACALL COMNWRT
ACALL DELAY
MOV A, #0EH
ACALL COMNWRT
ACALL DELAY
MOV A, #'N'
ACALL DATAWRT
ACALL DELAY
MOV A, #'O'
ACALL DATAWRT
AGAIN: SJMP AGAIN

Subroutines:

COMNWRT: Send command to LCD.

DATAWRT: Send data to LCD.

DELAY: Time delay generation.

C. Interfacing Keypad with 8051:


Hex Keypad: 4×4 matrix (16 keys).

Rows (R1–R4) and Columns (C1–C4).

Key detection via Row Scanning and Column Reading.

Keypad Scanning Logic:

Make one row LOW.

Check which column is LOW → identifies pressed key.

✅ Tip:
Use Look-Up Table (LUT) to convert key press into display output.

3. Embedded C Programming

Overview:
Embedded C extends standard C to control hardware devices.

ESD All Units 21


Supports direct I/O port access, fixed-point arithmetic, and memory management.

A. Interfacing LED to Arduino UNO


Blinking LED Program:

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

B. Interfacing RGB LED to Arduino UNO


Program:

int redPin = 11;


int greenPin = 10;
int bluePin = 9;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
setColor(255, 0, 0); delay(1000);
setColor(0, 255, 0); delay(1000);
setColor(0, 0, 255); delay(1000);
}

void setColor(int r, int g, int b) {


analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
}

C. Interfacing LCD to Arduino UNO


Basic Setup:

ESD All Units 22


#include <LiquidCrystal.h>

const int rs=12, en=11, d4=5, d5=4, d6=3, d7=2;


LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
lcd.begin(16,2);
lcd.print("Hello World!");
lcd.setCursor(0,1);
lcd.print("LCD Tutorial");
}

void loop() {}

D. Interfacing Switch with Arduino UNO


Program to Control LED with Switch:

int buttonState = 0;
int ledPin = 13;
int switchPin = 2;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}

void loop() {
buttonState = digitalRead(switchPin);
if(buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

E. Interfacing Buzzer to Arduino UNO


Program:

const int buzzer = 9;

void setup() {
pinMode(buzzer, OUTPUT);
}

ESD All Units 23


void loop() {
tone(buzzer, 1000);
delay(1000);
noTone(buzzer);
delay(1000);
}

4. Serial Communication Programming with Arduino

Overview:
Arduino uses UART for Serial Communication.

Communicates via TX (D1) and RX (D0) pins.

Basic Functions:

Serial.begin(baudrate)

Serial.print()

Serial.println()

Serial.read()

Serial.available()

Example Programs:

A. Sending Data to PC:

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

void loop() {
Serial.println("Hello World");
delay(1000);
}

B. Receiving Data from PC:

int incomingByte = 0;

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

void loop() {
if (Serial.available() > 0) {

ESD All Units 24


incomingByte = Serial.read();
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}

C. Serial Reading Digital Input:

int pushButton = 2;

void setup() {
Serial.begin(9600);
pinMode(pushButton, INPUT);
}

void loop() {
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(100);
}

✅ Tip:
Use Serial Monitor in Arduino IDE to view sent and received data.

ESD All Units 25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy