0% found this document useful (0 votes)
8 views31 pages

Embedded File

This document is a course file for the Embedded Systems Lab for B. Tech. CSE students at Birla Institute of Technology, Mesra, Jaipur. It includes a detailed index of experiments covering various topics such as Arduino hardware, basic and advanced I/O functions, timers, serial communication, and interfacing with sensors. Each experiment outlines objectives, theory, and procedures for practical implementation.

Uploaded by

milato3753
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)
8 views31 pages

Embedded File

This document is a course file for the Embedded Systems Lab for B. Tech. CSE students at Birla Institute of Technology, Mesra, Jaipur. It includes a detailed index of experiments covering various topics such as Arduino hardware, basic and advanced I/O functions, timers, serial communication, and interfacing with sensors. Each experiment outlines objectives, theory, and procedures for practical implementation.

Uploaded by

milato3753
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

BIRLA INSTITUTE OF TECHNOLOGY MESRA

OFF CAMPUS JAIPUR

COURSE FILE

Programme : B. Tech.
Semester : VI
Branch : CSE
Course Code : EC 338
Subject Name : Embedded Systems Lab
Prepared By : Dr. Jyoti Sharma & Dr. Puneet Sharma
INDEX
[Link]. Name of Experiment Date of Date of Signature
Experiment Submission
1. Familiarization with the hardware.
(Arduino Boards, driver installation
procedure and IDE)
2. Basic embedded functions - Reading
and Writing digital and analog input
and output pins
3. Advanced I/0 functions

4. Timer and Serial communication


functions

5. Experimentation with Interrupt


functions.

6. Experimentation with light sensitive


sensor and temperature sensor
modules.
7. Experimentation with temperature
and humidity sensor.

8. Experimentation with an ultrasonic


sensor to measure distance of an
object.
9. Experimentation with a digital
infrared motion sensor.

10. Experimentation with a color sensor


to detect color of an object.

11. Experimentation with an analog


sound sensor to detect sound in the
environment.
12. Experimentation with a vibration
sensor to detect vibrations in its
environment.
13. Experimentation with a flame sensor
to detect the presence of a flame in
the surroundings.
14. Experimentation with a touch sensor
to detect contact.
EXPERIMENT-1
Familiarization with Arduino Hardware and Environment

Objective:
To understand the characteristics of different Arduino boards, install drivers, and set up the Integrated
Development Environment (IDE).
Experiment:
Arduino board, computer with Arduino IDE.
Theory:
Few Different Arduino boards characteristics : There are many different Arduino boards available, each
with its own strengths and weaknesses. Here are a few of the most popular types:
1. Arduino Uno: The Uno is the most popular Arduino board and a great choice for beginners. It's
relatively inexpensive, easy to use, and compatible with a wide variety of sensors and other
components.

2. Arduino Mega: The Mega is a more powerful version of the Uno with more pins and memory. It's a
good choice for projects that require a lot of inputs and outputs or for use with complex
components.
3. Arduino Nano: The Nano is a smaller, breadboard-friendly version of the Uno. It's a good choice for
projects where space is limited.

4. Arduino Leonardo: The Leonardo is a similar size to the Uno but has a built-in USB interface, which
allows it to act as a keyboard or mouse. This makes it a good choice for projects that interact with a
computer.

Procedure:
1. Identify the components of the Arduino board.
2. Install necessary drivers for the Arduino board.
3. Download and install Arduino IDE.
4. Connect Arduino board to computer and upload a sample sketch.
5. Verify successful communication between Arduino board and IDE.
EXPERIMENT-2
Basic Embedded Functions

Objective:
To perform basic input and output operations using Arduino.
Experiment:
Arduino board, LED, resistors, push buttons, jumper wires.
Theory:
Microcontrollers use digital and analog I/O pins to interact with external components like sensors and
actuators.
• Digital Read: A digital input pin reads HIGH (1) or LOW (0) signals. This is useful for detecting button
presses, switches, and other binary state devices.
• Digital Write: A digital output pin sets a device HIGH or LOW. This is used for controlling LEDs,
relays, and other digital actuators.
• Analog Read: Some sensors output continuous voltage signals, which can be read using an analog
pin. This is useful for reading data from potentiometers, temperature sensors, and light sensors.
• Analog Write (PWM): Since microcontrollers do not generate true analog output, Pulse Width
Modulation (PWM) is used to simulate varying voltage levels. This is used for motor speed control
and LED brightness adjustment.
Procedure:
1. Program to read digital input and turn on an LED.
int buttonPin = 2;
int ledPin = 13;
void setup() {
pinMode(buttonPin, INPUT); // Set buttonPin as input
pinMode(ledPin, OUTPUT); // Set ledPin as output
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read button state
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED if button is pressed }
else {
digitalWrite(ledPin, LOW); // Turn off LED if button is not pressed
}
delay(100); // Delay for stability
}
Output:
EXPERIMENT-3
Advanced I/O Functions

Objective:
To use an 8-bit shift register to control multiple LEDs.
Experiment:
Arduino board, shift register (e.g., 74HC595), LEDs, resistors, jumper wires.
Theory:
Advanced I/O functions include handling multiple sensors, actuators, and communication protocols for
more complex applications.
• PWM (Pulse Width Modulation): A method to create varying voltage levels by switching a signal on
and off at high speeds. Used for dimming LEDs and controlling servo motors.
• I2C (Inter-Integrated Circuit): A protocol allowing multiple sensors and devices to communicate
using only two wires (SDA, SCL). Used for modules like OLED displays and advanced sensors.
• SPI (Serial Peripheral Interface): A faster communication protocol compared to I2C, used for high-
speed data transfer between microcontrollers and peripherals like SD cards.
• Shift Registers: Used to expand the number of output pins when controlling multiple LEDs or
displays.
Procedure:
// Experiment 3: Advanced I/O Functions
// Program to use an 8-bit shift register to light up 8 LEDs one by one.
int latchPin = 8; // Connects to RCLK (ST_CP) pin of 74HC595
int clockPin = 12; // Connects to SRCLK (SH_CP) pin of 74HC595
int dataPin = 11; // Connects to SER (DS) pin of 74HC595
void setup() {
pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (int i = 0; i < 256; i++) {
shiftOut(dataPin, clockPin, MSBFIRST, i); digitalWrite(latchPin, HIGH);
delay(100);
}
}
Output:
EXPERIMENT-4
Timer and Serial Communication

Objective:
To use timers and implement serial communication between Arduino boards.
Experiment:
Two Arduino boards, jumper wires.
Theory:
Timers and serial communication are essential for precise control and data exchange.
• Timers: Used for generating delays, measuring time intervals, and creating periodic tasks such as
blinking an LED at regular intervals.
• Serial Communication (UART): Microcontrollers communicate with computers and other devices
using serial protocols (UART, USART). The [Link]() function helps debug sensor data in real
time.
• Interrupts: Special functions that allow the microcontroller to respond to external events
immediately without continuously checking the input states.
Procedure:
//SENDER
String msg = "";
void setup() {
[Link](9600);}
void readSerialPort() {
msg = "";
if ([Link]()) {
delay(30);
while ([Link]() > 0) {
msg += (char)[Link]();
}
[Link]();
}
}
void loop() {
readSerialPort();
if (msg != ""){
char Mymessage = [Link](0);
[Link](Mymessage); //Write the serial data
}
delay(1000);
}
//RECEIVER
char Mymessage[2]; //Initialized variable to store recieved data
void setup() {
// Begin the Serial at 9600 Baud
[Link](9600);}
void loop() {
[Link](Mymessage,2); //Read the serial data and store in var
[Link](Mymessage); //Print data on Serial Monitor
delay(1000);
}

Output:
EXPERIMENT-5
Interrupt Functions

Objective:
To use interrupts for precise timing operations
Experiment:
Arduino board, LED, push button, resistors, jumper wires.
Theory:
Interrupts allow a microcontroller to execute a function immediately when an event occurs. This eliminates
the need for constant polling and improves efficiency.
• External Interrupts: Triggered by external events like button presses or sensor signals (e.g., motion
sensors).
• Timer Interrupts: Automatically triggered at precise intervals, useful for tasks like real-time clock
updates.
• Pin Change Interrupts: Triggered when a specific pin state changes from HIGH to LOW or vice versa.
Example: Using an interrupt to detect a motion sensor’s signal instead of continuously checking it in the
main loop.
Procedure:
// Experiment 5: Interrupt Functions
// Program to blink LED at a given time interval using interrupts.
const int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), blink, FALLING); // Attach interrupt to pin 2
}
void loop() {
// Do nothing in loop, interrupt will handle LED blinking
}
void blink() {
digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle LED state
delay(400); // Delay for 400ms
}
EXPERIMENT-6
Light and Temperature Sensors

Objective:
To interface with light and temperature sensors.
Experiment:
Arduino board, photodiode, LED, temperature sensor, buzzer, jumper wires.

Theory:

DHT11 and DHT22 are digital sensors that measure temperature and humidity.
• Working Principle: The sensor has a thermistor to measure temperature and a capacitive humidity
sensor.
• Data Communication: It uses a one-wire communication protocol to send temperature and
humidity data to the microcontroller.
Application: Used in HVAC systems, greenhouses, and weather stations.

Procedure:

// Program to control an LED based on ambient light conditions using a photodiode.


//Experiment 6a Light Sensor
int photoPin = A0; // Analog pin for photodiode
int ledPin = 13; // LED pin
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int lightValue = analogRead(photoPin); // Read light value
if (lightValue < 500) {
digitalWrite(ledPin, HIGH); // Turn off LED in bright light
} else {
digitalWrite(ledPin, LOW); // Turn on LED in dark conditions
}
delay(100); // Delay for stability
}
// Program to trigger a buzzer alarm when temperature exceeds a threshold using a digital
temperature sensor.
#include <Wire.h>
#include <Adafruit_MCP9808.h>
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() { [Link](9600); if
(![Link]()) {
[Link]("Couldn't find MCP9808 sensor!"); while (1);
}
}
void loop() {
float tempC = [Link]();
if (tempC > 26) {
[Link]("Temperature above threshold! Alarm activated!");
}delay(1000);

Output:
EXPERIMENT-7
Temperature and Humidity Sensor

Objective:
To read temperature and humidity values using a sensor.

Experiment:
Arduino board, temperature and humidity sensor (e.g., DHT11), jumper wires.
Theory:
An ultrasonic sensor (HC-SR04) measures distance by emitting ultrasonic waves and calculating the time
taken for the echo to return.
• Working Principle:
1. The sensor emits a sound pulse.
2. The pulse reflects off an object.
3. The sensor detects the reflected pulse and calculates the distance using:
Distance=(Speed of Sound×Time)/2
Application: Used in obstacle detection, robotics, and parking assistance systems.
Procedure:
// Experiment 7: Temperature and Humidity Sensor
// Program to read temperature and humidity values using DHT11 sensor.
#include <DHT.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
[Link](9600);
[Link]();
}
void loop() {
delay(2000); // Wait for sensor to stabilize
float tempC = [Link]();
float humidity = [Link]();
[Link]("Temperature: ");
[Link](tempC);
[Link](" °C, Humidity: ");
[Link](humidity);
[Link](" %");
}
Output:
EXPERIMENT-8
Ultrasonic Sensor

Objective:
To measure the distance of an object using an ultrasonic sensor.

Experiment:
Arduino board, ultrasonic sensor (e.g., HC-SR04), jumper wires.
Theory:
PIR (Passive Infrared) sensors detect movement by sensing infrared radiation from objects.
• Working Principle: The sensor has two IR-sensitive elements; a change in infrared radiation triggers
a HIGH signal.
• Sensitivity: Adjustable with onboard potentiometers.
Application: Used in security systems, automatic lighting, and occupancy detection.
Procedure:
1. Wire the ultrasonic sensor to the Arduino board.

//Program to measure and display the distance of a moving object using an ultrasonic sensor.

#define trigPin 9 // Trigger pin of ultrasonic sensor


#define echoPin 10 // Echo pin of ultrasonic sensor
void setup() {
[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1; // Calculate distance in centimeters
[Link]("Distance: ");
[Link](distance);
[Link](" cm");
delay(1000); // Delay between readings
}

Output:
EXPERIMENT-9
Infrared Motion Sensor

Objective:
To detect motion using an Infrared Motion Sensor.

Experiment:
Arduino board, Infrared Motion Sensor , LED , Jumper Wires.
Theory:
A color sensor like TCS3200 detects colors by using an array of photodiodes with red, green, blue, and clear
filters.
• Working Principle: The sensor outputs frequency signals based on the intensity of each color.
• Data Processing: The microcontroller calculates the dominant color by comparing RGB values.
Application: Used in industrial sorting, color recognition in robotics, and quality control in manufacturing.
Procedure:
// Program to illuminate an LED when motion is detected using an infrared motion sensor
int pirPin = 2; // PIR sensor connected to digital pin 2
int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
[Link](9600);}
void loop() {
int motion = digitalRead(pirPin); // Read PIR sensor value
if (motion == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn LED on
[Link]("Motion detected!");} else {
digitalWrite(ledPin, LOW); // Turn LED off}
delay(500); // Wait for 500ms before next reading
}

Output:
EXPERIMENT-10
Color Sensor

Objective:
To detect the color of an object using a color sensor

Experiment:
Arduino board, color sensor (e.g., TCS3200), jumper wires.
Theory:
A sound sensor detects ambient sound levels using a microphone.
• Working Principle:
o The microphone converts sound waves into electrical signals.
o The onboard amplifier boosts the signal, which is then read as an analog or digital value.
o Some modules have a potentiometer to adjust sensitivity.
Application: Used in voice-activated devices, noise monitoring, and security systems.
Procedure:
1. Wire the color sensor to the Arduino board.
// Experiment 10: Color Sensor
// Program to identify and display the color of an object using a color sensor.
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
[Link](9600);
if (![Link]()) {
[Link]("Color sensor not found!");
while (1);}
[Link]("Color sensor found!");}
void loop() {
uint16_t r, g, b, c;
[Link](&r, &g, &b, &c);
uint32_t color = [Link]();
[Link]("Color Temperature: ");
[Link](color);
delay(500);}
Output:
EXPERIMENT-11
Sound Sensor

Objective:
To detect sound using a sound sensor

Experiment:
Arduino board, sound sensor, jumper wires.

Theory:
A vibration sensor detects mechanical vibrations using a spring-based switch or a piezoelectric element.
• Working Principle:
o When vibrations exceed a threshold, the internal contact closes, sending a signal.
o Some sensors provide an analog output proportional to the intensity of vibrations.
Application: Used in earthquake detection, industrial machine monitoring, and security alarms.
Procedure:
1. Wire the sound sensor to the Arduino board
// Experiment 11: Sound Sensor
// Program to detect and display sound levels using an analog sound sensor.
int soundPin = A0; // Sound sensor connected to analog pin A0
void setup() {
[Link](9600);
}
void loop() {
int soundLevel = analogRead(soundPin); // Read sound level
[Link]("Sound Level: ");
[Link](soundLevel);
delay(1000); // Delay between readings
}

Output:
EXPERIMENT-12
Vibration Sensor

Objective:
To detect vibrations using a vibration sensor.

Experiment:
Arduino board, vibration sensor, LED, jumper wires.
Theory:
A flame sensor detects fire using infrared or ultraviolet light emitted by flames.
• Working Principle:
o The sensor contains a photodiode sensitive to specific wavelengths of fire.
o It provides a digital or analog signal when a flame is detected.
Application: Used in fire detection systems, industrial safety, and gas leak monitoring.
Procedure:
1. Wire the vibration sensor to the Arduino board.
// Experiment 11: Sound Sensor
// Program to detect and display sound levels using an analog sound sensor.
int soundPin = A0; // Sound sensor connected to analog pin A0
void setup() {
[Link](9600);
}
Void loop() {
int soundLevel = analogRead(soundPin); // Read sound level
[Link]("Sound Level: ");
[Link](soundLevel);
delay(1000); // Delay between readings
}

Output:
EXPERIMENT-13
Flame Sensor

Objective:
To detect the presence of a flame using a flame sensor

Experiment:
Arduino board, flame sensor, buzzer, jumper wires.
Theory:
A touch sensor detects physical contact or proximity.
• Working Principle:
o It uses capacitive sensing to detect a change in electric field when touched.
o When a conductive object (finger) comes near, the capacitance changes, triggering a HIGH
signal.
Application: Used in touch buttons, interactive displays, and smart home automation.

Procedure:
1. Wire the flame sensor to the Arduino board.
2. Program to sound a buzzer and display sensor values when a flame is detected.
// Experiment 11: Sound Sensor
// Program to detect and display sound levels using an analog sound sensor.
int soundPin = A0; // Sound sensor connected to analog pin A0
void setup() {
[Link](9600);
}
Void loop() {
int soundLevel = analogRead(soundPin); // Read sound level
[Link]("Sound Level: ");
[Link](soundLevel);
delay(1000); // Delay between readings
}
Output:
EXPERIMENT-14
Touch Sensor

Objective:
To detect the presence of a flame using a flame sensor To detect contact using a touch sensor

Experiment:
Arduino board, touch sensor, LED, jumper wires.
Theory:
A touch sensor detects physical contact or proximity.
• Working Principle:
o It uses capacitive sensing to detect a change in electric field when touched.
o When a conductive object (finger) comes near, the capacitance changes, triggering a HIGH
signal.
Application: Used in touch buttons, interactive displays, and smart home automation.
Procedure:
1. Wire the touch sensor to the Arduino board.
2. Program to illuminate an LED when the sensor is touched.
// Experiment 11: Sound Sensor
// Program to detect and display sound levels using an analog sound sensor.
int soundPin = A0; // Sound sensor connected to analog pin A0
void setup() {
[Link](9600);}
Void loop() {
int soundLevel = analogRead(soundPin); // Read sound level
[Link]("Sound Level: ");
[Link](soundLevel);
delay(1000); // Delay between readings}

Output:

You might also like