System Design with Embedded Linux Lab
Lab Manual
[Link] (Embedded Systems)
R-25
Department of Electronics and Communication Engineering
Part-I: (Using Ardiuno Board)
1. Temperature and Humidity Sensor
Aim:
To design and implement a system for measuring temperature and humidity using an Arduino
board.
Components
• Arduino Uno
• DHT11 / DHT22
• 10kΩ resistor
• Jumper wires
Theory
The DHT sensor consists of a thermistor for temperature measurement and a capacitive humidity
sensor. The sensor outputs calibrated digital data, making it suitable for environmental monitoring
applications in embedded systems.
Algorithm
1. Initialize the Arduino and DHT sensor.
2. Read temperature and humidity values.
3. Display the values on the serial monitor.
4. Repeat the process at regular intervals.
Connections
• DHT VCC → 5V
• DHT GND → GND
• DHT DATA → Digital Pin 2 (D2)
Arduino Program
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11 // Change to DHT22 if used
DHT dht(DHTPIN, DHTTYPE);
void setup () {
[Link](9600);
[Link] ();
void loop() {
float humidity = [Link]();
float temperature = [Link]();
if (isnan(humidity) || isnan(temperature)) {
[Link]("Failed to read from DHT sensor!");
return;
[Link]("Humidity: ");
[Link](humidity);
[Link](" %\t");
[Link]("Temperature: ");
[Link](temperature);
[Link](" °C");
delay(2000);
Output :
Temperature and humidity values are displayed on the Serial Monitor.
2. Soil Moisture Sensor
Aim
To measure soil moisture content and classify soil condition.
Components
• Arduino Uno
• Soil Moisture Sensor
• Jumper wires
Theory
The soil moisture sensor works on the principle of electrical resistance variation with water content
in the soil. It is widely used in irrigation control and agricultural automation systems.
Algorithm
1. Read analog output from the soil moisture sensor.
2. Convert the signal into moisture level.
3. Display the reading on the serial monitor.
Connections
• VCC → 5V
• GND → GND
• A0 → Analog Pin A0
Arduino Program
int soilPin = A0;
int soilValue = 0;
void setup() {
[Link](9600);
}
void loop() {
soilValue = analogRead(soilPin);
[Link]("Soil Moisture Value: ");
[Link](soilValue);
if (soilValue < 300)
[Link]("Soil is Wet");
else if (soilValue < 700)
[Link]("Soil is Moist");
else
[Link]("Soil is Dry");
delay(1000);
Output:
Soil condition (Wet/Moist/Dry) displayed on Serial Monitor.
3. Ultrasonic Sensor (HC-SR04) – Distance Measurement
Aim
To measure distance using an ultrasonic sensor.
Components
• Arduino Uno
• HC-SR04 Ultrasonic Sensor
• Jumper wires
Connections
• VCC → 5V
• GND → GND
• TRIG → Pin 9
• ECHO → Pin 10
Theory
The ultrasonic sensor measures distance by emitting ultrasonic waves and calculating the time
taken for the echo to return after reflection from an object.
Algorithm
1. Generate trigger pulse.
2. Measure echo pulse duration.
3. Calculate distance using speed of sound.
4. Display the distance.
Arduino Program
#define trigPin 9
#define echoPin 10
void setup() {
[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration;
float distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
[Link]("Distance: ");
[Link](distance);
[Link](" cm");
delay(1000);
}
Output:
Distance of object measured in centimeters.
4. IR Sensor (Obstacle Detection)
Aim
To detect obstacles using an IR sensor.
Components
• Arduino Uno
• IR Sensor Module
• LED (optional)
• Jumper wires
Connections
• VCC → 5V
• GND → GND
• OUT → Pin 7
Theory
The IR sensor emits infrared radiation and detects reflected signals to identify the presence of an
object. It is commonly used in obstacle detection and automation systems.
Algorithm
1. Read digital output from IR sensor.
2. Detect object presence.
3. Display detection status.
Arduino Program
int irSensor = 7;
void setup() {
pinMode(irSensor, INPUT);
[Link](9600);
}
void loop() {
int status = digitalRead(irSensor);
if (status == LOW) {
[Link]("Obstacle Detected");
} else {
[Link]("No Obstacle");
}
delay(500);
}
Output:
Obstacle detection status displayed on Serial Monitor.
VIVA QUESTIONS & ANSWERS
1. What is an embedded system?
An embedded system is a dedicated computer system designed to perform a specific task with
real-time constraints, integrating hardware and software.
2. Why is Arduino used in Embedded Linux labs?
Arduino is used to understand sensor interfacing, I/O handling, and real-time data acquisition,
which are fundamental before moving to Embedded Linux platforms like Raspberry Pi.
3. Difference between Arduino and Embedded Linux boards?
Arduino Embedded Linux Board
Microcontroller based Microprocessor based
No operating system Runs Linux OS
Low power, real-time High processing power
Simple applications Complex multitasking apps
4. What is a sensor?
A sensor is a device that detects physical parameters such as temperature, humidity, distance, or
motion and converts them into electrical signals.
TEMPERATURE & HUMIDITY SENSOR (DHT11)
5. What is DHT11?
DHT11 is a digital temperature and humidity sensor that provides calibrated digital output.
6. Why is DHT11 preferred over analog sensors?
Because it provides digital output, reduces noise, and eliminates the need for ADC conversion.
7. What is the temperature range of DHT11?
0°C to 50°C.
8. What protocol does DHT11 use?
Single-wire serial communication protocol.
9. What happens if DHT sensor reading fails?
The sensor returns NaN (Not a Number), indicating communication failure.
SOIL MOISTURE SENSOR
10. What is the working principle of soil moisture sensor?
It works on the principle of change in electrical resistance based on soil water content.
11. Why is analog pin used for soil moisture sensor?
Because the sensor produces varying voltage levels proportional to moisture content.
12. Applications of soil moisture sensor?
• Smart irrigation
• Precision agriculture
• Greenhouse monitoring
ULTRASONIC SENSOR (HC-SR04)
13. What is the working principle of ultrasonic sensor?
It works on the echo principle using ultrasonic sound waves.
14. What is the formula used to calculate distance?
Distance=Time×Speed of Sound2\text{Distance} = \frac{\text{Time} \times \text{Speed of
Sound}}{2}Distance=2Time×Speed of Sound
15. Why is division by 2 required?
Because the ultrasonic wave travels to the object and back to the sensor.
16. What is the operating frequency of HC-SR04?
40 kHz.
17. What is the range of HC-SR04?
2 cm to 400 cm.
IR SENSOR
18. What is an IR sensor?
An IR sensor detects objects by emitting and receiving infrared radiation.
19. What are the main components of IR sensor?
• IR LED (Transmitter)
• Photodiode / Phototransistor (Receiver)
20. Why is IR sensor affected by sunlight?
Because sunlight contains infrared radiation, which interferes with sensor readings.
21. Difference between IR sensor and ultrasonic sensor?
IR Sensor Ultrasonic Sensor
Uses infrared light Uses sound waves
Short range Longer range
Affected by light Not affected by light
ARDUINO & PROGRAMMING
22. What is ADC?
ADC (Analog-to-Digital Converter) converts analog signals into digital values.
23. ADC resolution of Arduino Uno?
10-bit (values from 0 to 1023)
24. What is baud rate?
Baud rate is the speed of serial communication, measured in bits per second.
25. Why is delay() used in Arduino programs?
To control timing and allow sensors to stabilize between readings.
26. What is pulseIn() function?
It measures the duration of a pulse (HIGH or LOW) on a pin in microseconds.
27. What is the role of Serial Monitor?
To display sensor readings and debug Arduino programs.
EMBEDDED LINUX LINK
28. How does this lab relate to Embedded Linux?
It builds foundational knowledge of hardware interfacing, which is later implemented using
Linux device drivers and GPIO interfaces.
29. Can Arduino run Linux?
No, Arduino lacks the memory and processing capability to run Linux.
30. What is the next platform after Arduino in this lab?
Raspberry Pi or BeagleBone Black running Embedded Linux.
PART-II: Embedded Linux Programs (Using Raspberry Pi)
1. Servo Motor Control using Raspberry Pi
Aim:
To control the angular position of a servo motor using Raspberry Pi GPIO.
Apparatus Required
• Raspberry Pi
• Servo Motor (SG90)
• External 5V supply
• Jumper wires
Connections
• Servo Red → 5V (External supply)
• Servo Brown → GND
• Servo Yellow → GPIO18 (PWM)
Theory
A servo motor is a position-controlled motor whose angular displacement is controlled using PWM
(Pulse Width Modulation). Raspberry Pi generates PWM signals through GPIO pins to control the
motor position accurately.
Algorithm
1. Configure GPIO pin as PWM output.
2. Generate PWM signal with varying duty cycle.
3. Rotate the servo to desired angles.
4. Stop PWM operation.
Program (Python)
import [Link] as GPIO
import time
[Link]([Link])
[Link](18, [Link])
pwm = [Link](18, 50) # 50Hz
[Link](2.5)
try:
while True:
[Link](2.5) # 0 degree
[Link](1)
[Link](7.5) # 90 degree
[Link](1)
[Link](12.5) # 180 degree
[Link](1)
except KeyboardInterrupt:
[Link]()
[Link]()
Output
Servo motor rotates to different angular positions.
Result
Servo motor rotates to 0°, 90°, and 180° positions.
2. MQ2 Gas Sensor using Raspberry Pi
Aim
To detect the presence of combustible gases using MQ2 gas sensor interfaced with Raspberry Pi.
Apparatus Required
• Raspberry Pi
• MQ2 Gas Sensor
• ADC Module (MCP3008)
• Jumper wires
Connections (MQ2 + MCP3008)
• MQ2 Analog Out → MCP3008 CH0
• MCP3008 SPI → Raspberry Pi SPI pins
Theory
The MQ2 gas sensor detects gases such as LPG, methane, and smoke. Since Raspberry Pi lacks an
internal ADC, an external ADC is used to convert analog signals into digital values.
Algorithm
1. Read analog gas concentration via ADC.
2. Convert ADC value into gas level.
3. Display gas status.
4. Generate alert if threshold exceeds.
Program (Python)
import spidev
import time
spi = [Link]()
[Link](0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
while True:
gas_value = read_channel(0)
print("Gas Sensor Value:", gas_value)
if gas_value > 300:
print("Gas Detected!")
else:
print("Safe Environment")
[Link](1)
Output
Gas concentration values are displayed on the terminal.
Result
Gas detection using MQ2 sensor was successfully demonstrated.
3. LCD Interfacing with Raspberry Pi
Aim
To interface a 16×2 LCD with Raspberry Pi and display text.
Components Required
• Raspberry Pi
• 16×2 LCD with I2C module
• Jumper wires
Theory
LCD modules are used to display alphanumeric data. Raspberry Pi communicates with the LCD
using GPIO pins in 4-bit mode to reduce pin usage.
Algorithm
1. Initialize LCD.
2. Send command instructions.
3. Display characters.
4. Clear display when required.
Connections
• VCC → 5V
• GND → GND
• SDA → GPIO2
• SCL → GPIO3
Program (Python)
import [Link] as GPIO
import time
LCD_RS = 7
LCD_E = 8
LCD_D4 = 25
LCD_D5 = 24
LCD_D6 = 23
LCD_D7 = 18
[Link]([Link])
[Link]([LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7], [Link])
def lcd_cmd(cmd):
[Link](LCD_RS, False)
lcd_byte(cmd)
def lcd_data(data):
[Link](LCD_RS, True)
lcd_byte(data)
def lcd_byte(bits):
for pin, val in zip([LCD_D4, LCD_D5, LCD_D6, LCD_D7], [(bits>>4)&1]*4):
[Link](pin, val)
[Link](LCD_E, True)
[Link](0.0005)
[Link](LCD_E, False)
lcd_cmd(0x28)
lcd_cmd(0x0C)
lcd_cmd(0x06)
lcd_cmd(0x01)
lcd_data(ord('H'))
lcd_data(ord('i'))
[Link]()
Output
Text is displayed on the LCD screen.
Result
LCD interfacing with Raspberry Pi was successfully implemented.
4. Relay Control using Raspberry Pi
Aim
To control electrical appliances using a relay module interfaced with Raspberry Pi.
Components Required
• Raspberry Pi
• Relay Module
• Bulb / Load
• Jumper wires
Theory
A relay acts as an electrically operated switch, allowing low-power Raspberry Pi signals to control
high-voltage devices safely.
Algorithm
1. Configure GPIO pin as output.
2. Activate relay to turn ON load.
3. Deactivate relay to turn OFF load.
4. Repeat operation.
Connections
• Relay IN → GPIO17
• VCC → 5V
• GND → GND
•
Program (Python)
import [Link] as GPIO
import time
relay = 17
[Link]([Link])
[Link](relay, [Link])
try:
while True:
[Link](relay, [Link])
print("Relay ON")
[Link](2)
[Link](relay, [Link])
print("Relay OFF")
[Link](2)
except KeyboardInterrupt:
[Link]()
Output
Relay switches ON and OFF, controlling the connected load.
Result
Relay control using Raspberry Pi was successfully demonstrated.
VIVA-VOCE QUESTIONS & ANSWERS
1. What is Raspberry Pi?
Raspberry Pi is a low-cost, single-board computer capable of running Linux-based operating
systems.
2. Why is Raspberry Pi used in Embedded Linux labs?
Because it supports Linux OS, multitasking, networking, file systems, and GPIO control.
3. Which OS is used in Raspberry Pi?
Raspberry Pi OS (Linux-based).
4. Difference between Arduino and Raspberry Pi?
Arduino Raspberry Pi
Microcontroller Microprocessor
No OS Linux OS
Real-time Not real-time
Simple control tasks Complex applications
SERVO MOTOR
5. What is a servo motor?
A servo motor is a position-controlled motor whose angle is controlled using PWM signals.
6. Why PWM is used to control servo motors?
PWM controls the duty cycle, which determines the angular position of the servo.
7. Typical PWM frequency for servo motor?
50 Hz.
8. Why external power supply is required for servo?
Because Raspberry Pi GPIO pins cannot supply sufficient current.
MQ2 GAS SENSOR
9. What gases are detected by MQ2 sensor?
LPG, methane, hydrogen, smoke, and alcohol vapors.
10. Why ADC is required for MQ2 sensor?
Because MQ2 produces analog output and Raspberry Pi has no internal ADC.
11. Name the ADC used in your experiment.
MCP3008.
12. Working principle of MQ2 sensor?
It uses a heated metal oxide semiconductor whose resistance changes in presence of gases.
LCD INTERFACING
13. What type of LCD is used?
16×2 alphanumeric LCD.
14. Why 4-bit mode is preferred?
To reduce the number of GPIO pins used.
15. What is the role of RS pin in LCD?
RS selects command mode or data mode.
16. What is the function of Enable pin?
It latches data into the LCD.
RELAY
17. What is a relay?
A relay is an electrically operated switch used to control high-voltage devices.
18. Why relay is used instead of direct GPIO connection?
GPIO pins cannot handle high voltage or current.
19. What is the role of opto-isolator in relay module?
To electrically isolate Raspberry Pi from high-voltage circuits.
20. Difference between NO and NC contacts?
NO NC
Normally Open Normally Closed
Circuit open by default Circuit closed by default
EMBEDDED LINUX CONCEPTS
21. What is GPIO?
General Purpose Input Output pins used for interfacing external devices.
22. What library is used for GPIO control in Raspberry Pi?
[Link] library.
23. Is Raspberry Pi a real-time system?
No, Linux is not a real-time operating system by default.
24. What is SPI?
Serial Peripheral Interface, a high-speed communication protocol.
25. Where is SPI used in this lab?
For interfacing ADC (MCP3008) with Raspberry Pi.
CONCLUDING QUESTION
26. How does this lab help in Embedded Linux learning?
It provides practical exposure to Linux-based hardware interfacing, GPIO control, and real-time
sensor applications.
(BeagleBone Black + Debian Linux + Python 3, which is the most commonly accepted
combo.)
PART-III: Embedded Linux Programs (Using Beagle Bone Black)
1. LED Blinking using Beagle Bone Black (BBB)
Aim
To interface an LED with BeagleBone Black and perform LED blinking using Embedded Linux.
Components Required
• Beagle Bone Black
• LED
• 330Ω resistor
• Jumper wires
Theory
LED blinking demonstrates basic GPIO output control. BeagleBone Black GPIO pins are
controlled through Linux sysfs or user-space programs.
Algorithm
1. Configure GPIO pin as output.
2. Turn ON LED.
3. Delay for a fixed time.
4. Turn OFF LED.
5. Repeat the process.
Pin Connection
• LED Anode → P9_12 (GPIO1_28)
• LED Cathode → GND
Program (Python)
import Adafruit_BBIO.GPIO as GPIO
import time
LED = "P9_12"
[Link](LED, [Link])
while True:
[Link](LED, [Link])
[Link](1)
[Link](LED, [Link])
[Link](1)
LED blinking using BeagleBone Black was successfully implemented.
Output
LED blinks at regular intervals.
Output
LED blinks at regular intervals.
Result
LED blinking using BeagleBone Black was successfully implemented.
2. Seven Segment Display using BeagleBone Black
Aim
To interface a seven-segment display with BeagleBone Black and display digits.
Components Required
• Beagle Bone Black
• Common Cathode Seven Segment Display
• 330Ω resistors
• Jumper wires
Theory
A seven-segment display consists of seven LEDs arranged to display numerical digits. Each
segment is controlled individually using GPIO pins.
Algorithm
1. Configure GPIO pins as outputs.
2. Apply logic HIGH to required segments.
3. Display digits from 0 to 9.
4. Repeat the sequence.
Pin Connections
Segment BBB Pin
a P9_11
b P9_12
c P9_13
d P9_14
e P9_15
f P9_16
g P9_17
Program (Python)
import Adafruit_BBIO.GPIO as GPIO
import time
segments = ["P9_11","P9_12","P9_13","P9_14","P9_15","P9_16","P9_17"]
digit_0 = [1,1,1,1,1,1,0]
for seg in segments:
[Link](seg, [Link])
while True:
for i in range(7):
[Link](segments[i], digit_0[i])
[Link](1)
Output
Digit 0 is displayed on the seven-segment display.
Result
Seven-segment display interfacing was successfully demonstrated.
3. LCD Interfacing with BeagleBone Black (16×2 LCD)
Aim
To interface a 16×2 LCD with BeagleBone Black and display messages.
Components Required
• BeagleBone Black
• 16×2 LCD
• 10k potentiometer
• Jumper wires
Theory
LCD modules are used for displaying alphanumeric information. BeagleBone Black controls the
LCD using GPIO pins in 4-bit mode.
Algorithm
1. Initialize LCD.
2. Send command instructions.
3. Send data characters.
4. Display message.
Pin Connections
Segment BBB Pin
RS P8_8
EN P8_10
D4 P8_18
D5 P8_16
D6 P8_14
D7 P8_12
Program (Python)
import Adafruit_BBIO.GPIO as GPIO
import time
RS = "P8_8"
EN = "P8_10"
data = ["P8_18","P8_16","P8_14","P8_12"]
for pin in [RS,EN] + data:
[Link](pin, [Link])
def lcd_command(cmd):
[Link](RS, 0)
for i in range(4):
[Link](data[i], (cmd >> (4+i)) & 1)
[Link](EN,1)
[Link](0.01)
[Link](EN,0)
def lcd_data(msg):
[Link](RS, 1)
for i in range(4):
[Link](data[i], (msg >> (4+i)) & 1)
[Link](EN,1)
[Link](0.01)
[Link](EN,0)
lcd_command(0x28)
lcd_command(0x0C)
lcd_command(0x01)
for ch in "BeagleBone":
lcd_data(ord(ch))
Output
Text is displayed on the LCD screen.
Result
LCD interfacing with BeagleBone Black was successfully implemented.
4. Switch and Buzzer using BeagleBone Black
Aim
To control a buzzer using a switch connected to BeagleBone Black.
Components Required
• BeagleBone Black
• Push Button
• Buzzer
• Jumper wires
Theory
Switches act as digital input devices, while buzzers act as output devices. BeagleBone Black
reads switch status and controls the buzzer accordingly.
Algorithm
1. Configure switch pin as input.
2. Configure buzzer pin as output.
3. Read switch status.
4. Turn buzzer ON/OFF based on switch input.
Pin Connections
• Switch → P9_41
• Buzzer → P9_42
Program (Python)
import Adafruit_BBIO.GPIO as GPIO
import time
SWITCH = "P9_41"
BUZZER = "P9_42"
[Link](SWITCH, [Link])
[Link](BUZZER, [Link])
while True:
if [Link](SWITCH):
[Link](BUZZER, [Link])
print("Buzzer ON")
else:
[Link](BUZZER, [Link])
print("Buzzer OFF")
[Link](0.2)
Output
Buzzer sounds when the switch is pressed.
Result
Switch and buzzer interfacing was successfully demonstrated.
PART-IV: Embedded Linux Programs (Using Embedded Linux Board)
(Assumes Linux OS running on ARM board with GPIO & ADC support)
1. 4×4 Matrix Keypad Interfacing
Aim
To interface a 4×4 matrix keypad with an Embedded Linux board and detect key presses.
Components Required
• Embedded Linux Board (ARM based)
• 4×4 Matrix Keypad
• Jumper wires
Theory
A 4×4 matrix keypad consists of 4 rows and 4 columns, allowing 16 keys to be interfaced using
only 8 GPIO pins. The keypad works on the row–column scanning technique, where rows are
configured as outputs and columns as inputs to detect key presses.
Algorithm
1. Configure row pins as output.
2. Configure column pins as input.
3. Drive one row LOW at a time.
4. Read column status to identify pressed key.
5. Display the pressed key.
6. Repeat continuously.
Keypad Configuration
• Rows: R1–R4 → GPIO Outputs
• Columns: C1–C4 → GPIO Inputs
GPIO Mapping
Function GPIO
R1 GPIO20
R2 GPIO21
R3 GPIO22
R4 GPIO23
C1 GPIO24
C2 GPIO25
C3 GPIO26
C4 GPIO27
Program (Python – sysfs GPIO)
import [Link] as GPIO
import time
rows = [5,6,13,19]
cols = [12,16,20,21]
keys = [
['1','2','3','A'],
['4','5','6','B'],
['7','8','9','C'],
['*','0','#','D']
[Link]([Link])
for r in rows:
[Link](r, [Link])
[Link](r, [Link])
for c in cols:
[Link](c, [Link], pull_up_down=GPIO.PUD_UP)
try:
while True:
for i in range(4):
[Link](rows[i], [Link])
for j in range(4):
if [Link](cols[j]) == [Link]:
print("Key Pressed:", keys[i][j])
[Link](0.5)
[Link](rows[i], [Link])
except KeyboardInterrupt:
[Link]()
Output
Pressed key is displayed on the terminal.
Result
4×4 matrix keypad was successfully interfaced with the Embedded Linux board.
2. Light Dependent Resistor (LDR) Interfacing
Aim
To measure light intensity using a Light Dependent Resistor (LDR) interfaced with an
Embedded Linux board.
Components Required
• Embedded Linux Board
• LDR
• Resistor (10kΩ)
• ADC module (on-board / external)
Connection
• LDR + resistor → Voltage Divider
• Output → ADC Channel (e.g., ADC0)
Program (Python – ADC sysfs)
import spidev
import time
spi = [Link]()
[Link](0,0)
def read_adc(channel):
adc = spi.xfer2([1, (8+channel)<<4, 0])
value = ((adc[1] & 3) << 8) + adc[2]
return value
while True:
light = read_adc(0)
print("Light Intensity:", light)
[Link](1)
Output
Light intensity values are displayed on the terminal.
Result
Light intensity was successfully measured using LDR and Embedded Linux board.
Viva-Voce Questions (Part-IV)
1. What is matrix keypad scanning?
2. Why pull-up resistors are required in keypad?
3. What is sysfs in Linux?
4. Why ADC is necessary for LDR?
5. Difference between GPIO and ADC