ES Practical
ES Practical
Certificate
This is to certify that Mr. / Miss
Roll No. of B.Sc. IT Semester IV has successfully completed all the
Practical Work in the Subject of “Introduction to Embedded Systems” during the
academic year 2023-2024 under the guidance of Prof.Mrs.Vanita Sharma being
the partial requirement for the fulfillment of the curriculum of Degree of Bachelor
of Science in Information Technology Practical Exam.
- Introduction to Arduino
1 Blinking of LED’s
INTRODUCTION TO ARDUINO:
SY BSC IT
Introduction to Embedded System 2023 - 24
Tx and Rx are serial UART pins used for RS-232 and USB
communications.
SPI is another serial communications method that uses one line for
the master to transmit (MOSI—Master Out Slave In), another for the
master to receive (MISO), and a third as a clock (SCK).
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To study the basics of Arduino circuits and bread-boarding blinking
of LEDs
Components Used:
Arduino UNO
Breadboard
LED
Resistor (330 Ω)
Theory:
Arduino UNO is used to blink the LED continuously, we connect pin
13 to the anode of the LED and the cathode of the LED is connected
to a resistor (330 Ω) to limit the current passing through the LED.
If a large current flows through the LED then it may damage the
LED (in real world environment).
The other end of the LED is terminated to the ground connection of
the Arduino to complete the Circuit.
SY BSC IT
Introduction to Embedded System 2023 - 24
Code:
// C++ code
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To study the working of Light sensors using Arduino Simulation
Environment TinkerCAD.
Components:
Arduino UNO
LED
Photodiode
Resistors
Theory:
The goal of this practical is to create a system that can
automatically control the brightness of an LED based on the light
detected by a photodiode.
This project leverages the principles of light sensing and feedback
control.
Working Principle:
The working principle of a photoelectric sensor is based on the
photoelectric effect. i.e., whenever an object is exposed to light or
whenever a light incident on a material then it emits some
electrons.
These electrons excite the phototransistor or receiver which
generates a voltage or current signal proportionally to the intensity
of light.
If an object interrupts the light, then the electrons received by the
phototransistor will be reduced. Which further changes the output
voltage and current signal.
Then the sensor senses the change and reacts accordingly. This
change in output signal indicates the presence or absence of an
object.
SY BSC IT
Introduction to Embedded System 2023 - 24
Pin Connections:
Code:
int lightSensorValue = 0; // Variable to store the light sensor
reading
void setup() {
pinMode(A0, INPUT); // Set A0 pin as an input for the light sensor
pinMode(9, OUTPUT); // Set pin 9 as an output to control the LED
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop() {
lightSensorValue = analogRead(A0); // Read the light sensor value
Serial.println(lightSensorValue); // Print the sensor value to the
Serial Monitor
int ledBrightness = map(lightSensorValue, 0, 1023, 0, 255); // Map
the sensor value to LED brightness
analogWrite(9, ledBrightness); // Control LED brightness based on
the sensor reading
delay(100); // Wait for 100 milliseconds before the next loop
iteration
}
SY BSC IT
Introduction to Embedded System 2023 - 24
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To study the working of Temperature sensors using Arduino
Components: Arduino UNO, Temperature Sensor TMP 36 Theory:
The temperature sensor in Arduino converts the surrounding
temperature to voltage. It further converts the voltage to Celsius,
Celsius to Fahrenheit, and prints the Fahrenheit temperature on
the LCD screen.
Working :
The measurement of the temperature sensor is about the coolness
or hotness of an entity.
The working of the sensor is the voltage that reads across to the
diode. If increment in voltage, then the temperature increases and
there is a voltage decrement between the transistor’s terminals of
the emitter & base. That data is saved by the sensor.
If the voltage difference is amplified, then an analog signal is
generated by the device, and it is directly proportional to the
temperature.
SY BSC IT
Introduction to Embedded System 2023 - 24
Pin Connections:
5V Left pin
A1 Center pin
Code:
char degree = 176; // ASCII Value of Degree
const int sensor = A1;
void setup()
{
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop()
{
int tmp = analogRead(sensor); // Read data from the sensor. This
voltage is stored as a 10-bit number.
float voltage = (tmp * 5.0) / 1024; // Convert the 10-bit number to a
voltage reading.
float tmpCel = (voltage - 0.5) * 100.0; // Convert voltage to Celsius.
Serial.print("Celsius: ");
Serial.print(tmpCel);
Serial.println(degree);
delay(1000);
}
SY BSC IT
Introduction to Embedded System 2023 - 24
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To study the working of Humidity sensors using Arduino
Components: Arduino UNO, Potentiometer (wiper).
Theory:
Humidity Sensor is one of the most important devices that has been
widely in consumer, industrial, biomedical, and environmental etc.
applications for measuring and monitoring Humidity.
Humidity is defined as the amount of water present in the
surrounding air. This water content in the air is a key factor in the
wellness of mankind.
Potentiometer as a Sensor:
A potentiometer, often referred to as a "pot," is a variable resistor
with three terminals.
It consists of a resistive track and a wiper that moves along the
track. By adjusting the wiper's position, you can vary the
resistance.
In this demonstration, the potentiometer is used to simulate a
variable sensor input.
Arduino:
Arduino is a versatile microcontroller platform commonly used for
various electronic projects.
It can read analog voltage levels from sensors, including
potentiometers, and convert them into digital values for
processing.
Pin Connections:
Arduino Potentiometer
5v Left pin
GND Right pin
A1 Center pin
SY BSC IT
Introduction to Embedded System 2023 - 24
Code:
const int analogIn = A1; // Connect the humidity sensor to this pin
int humiditySensorOutput = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
humiditySensorOutput = analogRead(analogIn);
int humidityPercentage = map(humiditySensorOutput, 0, 1023, 10,
70);
Serial.print("Humidity: "); // Printing out Humidity Percentage
Serial.print(humidityPercentage);
Serial.println("%");
delay(5000); // Iterate every 5 seconds
}
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To study the working of Ultrasonic sensors using Arduino
Components:
Arduino UNO
HC-SR04 sensor
Theory:
Ultrasonic sensors work by emitting sound waves at a frequency
too high for humans to hear. They then wait for the sound to be
reflected back, calculating the distance based on the time required.
This is similar to how radar measures the time it takes a radio wave
to return after hitting an object.
Working:
Ultrasonic sensors measure distance by sending and receiving the
ultrasonic wave. The ultrasonic sensor has a sender to emit the
ultrasonic waves and a receiver to receive the ultrasonic waves.
The transmitted ultrasonic wave travels through the air and is
reflected by hitting the Object. Arduino calculates the time taken by
the ultrasonic pulse wave to reach the receiver from the sender.
We know that the speed of sound in air is nearly 344 m/s,
So, the known parameters are time and speed (constant). Using
these parameters, we can calculate the distance traveled by the
sound wave.
SY BSC IT
Introduction to Embedded System 2023 - 24
Pin Connections:
Arduino HC-SR 04
Sensor
5V VCC
GND GND
Pin 9 TRIG
Pin 10 ECHO
Code:
// Define the pins for the ultrasonic sensor
const int trigPin = 9; // Arduino digital pin for the trigger
const int echoPin = 10; // Arduino digital pin for the echo
void setup()
{
// Initialize serial communication for debugging
Serial.begin(9600);
void loop()
{
// Trigger a pulse to the sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
SY BSC IT
Introduction to Embedded System 2023 - 24
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To control the motion of a Servo motor using Arduino
Components:
Arduino UNO
Servo motor
Theory:
A servo motor is an electromechanical device that produces torque
and velocity based on the supplied current and voltage. A servo
motor works as part of a closed-loop system providing torque and
velocity as
commanded from a servo controller utilizing a feedback device to
close the loop.
Working:
The servo motor has some control circuits and a potentiometer (a
variable resistor, aka pot) connected to the output shaft. In the
picture above, the pot can be seen on the right side of the circuit
board. This pot allows the control circuitry to monitor the current
angle of the servo motor.
Pin Connections:
Arduino Servo
Motor
5V Power
GND Ground
Pin A1 Signal
SY BSC IT
Introduction to Embedded System 2023 - 24
Code:
// Include the Servo library
#include <Servo.h>
Servo servoBase; // Create a Servo object and assign it a specific
name
void setup()
{
servoBase.attach(A1); // Specify the pin to use for the servo
servoBase.write(0); // Set the servo motor to the 0-degree
position
}
void loop()
{
// Sweep the servo from 0 to 180 degrees in steps of 10 degrees
for (int i = 0; i <= 180; i += 10) {
servoBase.write(i); // Set the servo to the current angle
delay(2000); // Pause for 2000 milliseconds (2 seconds)
}
}
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To control the motion of a Servo motor using Arduino
Components: Arduino UNO, Servo motor
Theory:
The human body, with a surface temperature between 27°C and
36°C, emits most of its radiant energy in the wavelength range of 8
μm to 12 μm.
In the detection area, the PIR sensor’s lens receives infrared
radiation energy emitted by the human body, even through clothing.
Working:
The passive infrared sensor does not radiate energy to space. It
receives infrared radiation from the human body to make an alarm.
Any object with temperature is constantly radiating infrared rays
to the outside world. The surface temperature of the human body
is between 36° C – 27 ° C and most of its radiant energy is
concentrated in the wavelength range of 8 um-12 um.
Pin Connections:
Arduino PIR Sensor LED
5V Power
GND Ground
Pin 2 Signal
Cathode through
GND (digital)
the resistor
Pin 13 Anode
SY BSC IT
Introduction to Embedded System 2023 - 24
Code:
// C++ code //
int sensorState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
//Read the state of the sensor/digital input
sensorState = digitalRead(2);
// check if sensor pin is HIGH. if it is, set the LED on.
if (sensorState == HIGH) {
digitalWrite(LED_BUILTIN, HIGH);
}
else
{
digitalWrite(LED_BUILTIN, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
SY BSC IT
Introduction to Embedded System 2023 - 24
Output:
SY BSC IT
Introduction to Embedded System 2023 - 24
Aim:
To detect smoke/fire using a Gas sensor
Components:
Arduino UNO
Gas sensor
LED
Resistor
Breadboard
Theory:
Gas sensors are devices designed to detect and measure the
concentration of gases in the surrounding environment. They are
widely used in various applications, including industrial safety,
environmental monitoring, medical diagnostics, and home
automation. Gas sensors play a crucial role in ensuring the safety
of individuals and detecting potential hazards.
Working:
The working principle of gas sensors can vary depending on the
type of sensor and the specific gas it is designed to detect.
The basic principle used in a smoke detector, whether in a real-
world device or a simulated one in TinkerCAD, is the change in
electrical conductivity or resistance in the presence of smoke
particles.
SY BSC IT
Introduction to Embedded System 2023 - 24
Pin Connections:
Arduino Gas sensor Led Resistor
B1
B2
5V
B3
GND H1 Cathode Other end
A1 Other end
A0 A2
A1 Anode
Code:
int LED = A1;
const int gas = 0;
int MQ2pin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
float sensorValue,MQ2pin;
sensorValue = analogRead(MQ2pin); // read analog input pin 0
if(sensorValue>= 470){
digitalWrite(LED,LOW);
Serial.print(sensorValue);
Serial.println(" |SMOKE DETECTED");
}
else{
digitalWrite(LED,HIGH);
Serial.println("Sensor Value: ");
Serial.println(sensorValue);
}
delay(1000);
}
float getsensorValue(int pin){
return (analogRead(pin));
}
SY BSC IT
Introduction to Embedded System 2023 - 24
Output:
SY BSC IT