KEMBAR78
Lab File937 | PDF | Sampling (Signal Processing) | Arduino
0% found this document useful (0 votes)
30 views52 pages

Lab File937

This document outlines a series of lab experiments focused on data structures and algorithms using MATLAB and Simulink. It covers the installation and setup of simulation software, the creation of digital circuits, and the integration of Android devices for real-time applications. Each experiment includes objectives, theoretical background, procedures, and conclusions, highlighting the practical applications of the software in engineering tasks.

Uploaded by

dimihik120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views52 pages

Lab File937

This document outlines a series of lab experiments focused on data structures and algorithms using MATLAB and Simulink. It covers the installation and setup of simulation software, the creation of digital circuits, and the integration of Android devices for real-time applications. Each experiment includes objectives, theoretical background, procedures, and conclusions, highlighting the practical applications of the software in engineering tasks.

Uploaded by

dimihik120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

LAB

FILE

OF

DATA STRUCTURES AND

ALOGORIHIMS (CSBB-

151)

BACHELOR OF TECHNOLOGY

In

COMPUTER SCIENCE & ENGINEERING

Submitted

by KATAM

VEERA NAVEEN

(241210056)

1st

Year

Submi

tted to

DR.GULAB SAH (ASSISTANT PROFESSOR, CSE DEPT.)


DEPARTMENT OF COMPUTER

SCIENCE AND ENGINEERING

NATIONAL INSTITUTE OF

TECHNOLOGY DELHI (MAY 2025)


Sr.N Dat Sig

Experim
o e n

1.
ent
Study about simulation software: LabVIEW and
Simulink
2. Introduction to MATLAB and Simulink

3. Generate a 3 bit adder/subtractor and 2 bit


comparator circuit in Simulink

4. Installation and environmental setting of


simulink hardware support package for
android/ios devices

5. Accessing android camera using simulink

6. Converting RGB image to black and white and


gray scale using android hardware support
package

7. Implement Audio Signal Processing Using


Android Devices with simulink

8. Implement a user defined function in simulink


using the matlab function block and S-
function block for custom computations.

9. Installation of Arduino hardware support


package and LED Blinking using Arduino.

10. Temperature Monitoring using Arduino and


LM35 Sensor
11. Implement decision logic for Traffic light
negotiation
Lab experiment:1
AIM:
To explore and compare the functionalities of two simulation software
tools, LabVIEW and MATLAB Simulink, and identify their respective
strengths and use-cases in system design, simulation, and hardware
interfacing.

THEORY:
1. LabVIEW (Laboratory Virtual Instrument Engineering Workbench):
 Developed by National Instruments.
 A system-design platform used for:
o Data acquisition
o Instrument control

o Industrial automation
o Simulation, testing, and measurement
 Programming is done using a graphical language (G) by connecting
visual components known as Virtual Instruments (VIs).
Key Features:

 Real-time system simulation


 Strong hardware integration
 Efficient in laboratory and hardware control applications
 May face performance issues with large datasets or complex simulations
 More cost-effective for hardware-focused users
2. MATLAB Simulink:
 Developed by MathWorks.

 A model-based design environment used for:


o Simulating and analyzing dynamic systems
o Control systems, signal processing, and communications
 Uses a graphical block diagram interface for model creation.
Key Features:
 Tight integration with MATLAB

 Allows high-level modeling with complex mathematical simulations


 Suitable for real-time systems and embedded hardware
 Code generation in C, C++, and HDL is supported
 Common in automotive, aerospace, and communications industries
 Requires a MATLAB license

Comparison Table:

Feature LabVIEW Simulink (MATLAB)

Graphical language (G) using


Interface Block-diagram-based interface
Virtual Instruments

Hardware control and real-time Algorithm-based simulation and


Focus
testing system modeling

Strong with sensors, actuators, Strong with embedded systems


Integration
and instruments and MATLAB
Feature LabVIEW Simulink (MATLAB)

May degrade with large Can handle large multi-domain


Performance
datasets systems

More cost-effective Requires MATLAB license


Cost
for hardware tasks (higher cost)

Embedded systems, Aerospace, automotive,


Application
robotics, automated testing control systems

PROCEDURE:
1. Launch LabVIEW and Simulink on the system.
2. Explore the Interface:
o LabVIEW: Navigate through the VI components, learn how
to connect instruments and test data flows.
o Simulink: Use the block library, drag and drop different blocks,
and simulate system behaviors.
3. Create Basic Simulations:
o Simulate a simple sensor input system using LabVIEW.
o Simulate a basic dynamic system (e.g., a control loop)
using Simulink.
4. Analyze Performance and Flexibility of both tools.
5. Compare Outputs, Usability, and Application Scope.

OUTPUT / CONCLUSION / RESULT:


✔ Simulink was found to be more suitable for simulation purposes due to:

 Easy-to-understand block diagram interface


 Extensive library components
 High flexibility in creating various models
 Efficient handling of complex and dynamic systems

 Capability of automatic code generation and real-time deployment


✔ LabVIEW is ideal for:

 Hardware-intensive applications
 Real-time testing and control
 Instrumentation and data acquisition

 Laboratory-based or embedded hardware tasks


Lab Experiment-2

AIM:
To understand the basics of MATLAB and Simulink, learn how to use their
interfaces, create and simulate simple models, and visualize outputs using
blocks like Sine Wave and Scope.

THEORY:
MATLAB:

 MATLAB is a high-performance language for technical


computing developed by MathWorks.
 It integrates computation, visualization, and programming in an easy-
to- use environment.
 The Command Window is used to execute commands line by line.
 Files can be created using the "New" icon, and variables
are automatically stored in the workspace.
 The command clc is used to clear the Command Window.
SIMULINK:
 Simulink is a graphical programming environment for
modeling, simulating, and analyzing multidomain dynamic
systems.
 Can be opened in two ways:
1. Clicking on the Simulink icon in MATLAB.
2. Typing simulink in the Command Window.
 Upon opening, a Blank Model can be chosen for creating simulations.

 Library Browser gives access to different blocks, categorized as:


o Sources (e.g., Sine Wave, Constant)
o Sinks (e.g., Scope, Display, Floating Scope)
 Blocks can be dragged from the library into the workspace to
create models.
PROCEDURE / CODE:

A. Working with MATLAB:


1. Open MATLAB.
2. Use the Command Window for executing line-by-line instructions.
3. Create new script files from the toolbar.
4. Use clc to clear the Command Window.

5. Save files and observe their path on the left side of the interface.
B. Working with Simulink:
1. Open Simulink by:
o Clicking the Simulink icon OR
o Typing simulink in the MATLAB command window.
2. Select Blank Model to start building.

3. Use the Library Browser to add components:


o Sine Wave Block from Sources
o Scope Block from Sinks
4. Connect the output of the Sine Wave to the input of the Scope
by clicking and dragging.
5. Press the Run button to simulate the model.
6. Observe the output in the Scope window.
C. Building a Basic Calculator (Conceptual Outline):
 A subsystem is used to encapsulate a part of the model (e.g., addition
or multiplication of values).
 The subsystem can receive inputs, perform operations, and
return results.
OUTPUT:
 The simulation displays waveforms on the Scope.
 Example Output:

o Blue Curve: Represents the Sine Wave.


o Yellow Curve: Represents the Cosine Wave (if added in parallel).
 Successfully built and simulated a basic sine wave model.
 Understood the working of input and output blocks.

CONCLUSION / RESULT:
->Gained hands-on experience with MATLAB and Simulink interfaces.
->Learned how to create and simulate models using blocks from the library.
->Successfully visualized sine wave outputs using the Scope block.
->Understood how to build subsystems like a basic calculator using input/output
blocks and operations.
-> This forms the foundation for more complex simulations and control system designs.
Lab Experiment-3
AIM:
To understand the working of basic digital circuits such as a 3-bit adder, 3-bit
subtractor, and 2-bit comparator by constructing their truth tables and
simulating the circuits using MATLAB Simulink.

THEORY:
1. 3-Bit Full Adder:
 A Full Adder adds three binary inputs: A, B, and Carry-in (Cin).
 It generates two outputs: Sum (S) and Carry-out (Cout).

 Used in multi-bit binary addition circuits.


Truth Table:

A B Cin Sum Cout

000 0 0

001 1 0

010 1 0

011 0 1

100 1 0

101 0 1

110 0 1

111 1 1
2. 3-Bit Full Subtractor:
 A Full Subtractor subtracts three binary inputs: Minuend (A),
Subtrahend (B), and Borrow-in (Bin).
 It gives two outputs: Difference (D) and Borrow-out
(Bout). Truth Table:

A B Bin D Bout

0 0 0 0 0

0 0 1 1 1

0 1 0 1 1

0 1 1 0 1

1 0 0 1 0

1 0 1 0 0

1 1 0 0 0

1 1 1 1 1
3. 2-Bit Comparator:
 A Comparator compares two binary values A and B and gives
three outputs:
o A>B
o A=B
o A<B
 It compares each bit starting from MSB to LSB.

Truth Table:

ABA<BA=BA>B

000 1 0

011 0 0

100 0 1

110 1 0

PROCEDURE / CODE:

1. Launch MATLAB and open Simulink.


2. Create a New Blank Model.
3. Use the Library Browser to find and drag necessary components:
o Logic gates (AND, OR, XOR, NOT)
o Add/Subtract Blocks
o Relational Operator Blocks (for Comparator)

o Input/Output Blocks (e.g., Constant, Scope, Display)


4. Construct the circuits:
o For Adder: Use logic gates to simulate sum and carry outputs.
o For Subtractor: Use logic gates to simulate difference and
borrow outputs.
o For Comparator: Use Relational Operator blocks to
determine comparisons.
5. Connect the blocks using signal lines.
6. Run the simulation using the Run button.
7. Observe the results in the Scope or Display blocks.

OUTPUT:
 The Simulink models for all three circuits (3-bit Adder, 3-bit
Subtractor, and 2-bit Comparator) were successfully created.
 Simulation results matched the expected truth table outputs.

CONCLUSION / RESULT:

->Understood the construction and working of digital logic circuits: 3-bit


Adder, 3-bit Subtractor, and 2-bit Comparator.
->Designed and simulated each circuit using MATLAB Simulink.
->Verified correctness using truth tables.
-> Gained practical experience with digital system design and Simulink modeling
Lab Experiment -4
AIM:

To set up the required development environment for Android-based


Simulink applications by installing Android Studio, the necessary SDK, NDK,
and build tools, and the Simulink Support Package for Android Devices.

THEORY:
Simulink allows deployment of models directly onto Android devices. To
achieve this, certain tools and packages need to be installed:
 Android Studio provides the platform, SDKs, NDKs, and build
tools needed for Android app development.
 Simulink Support Package for Android Devices integrates
Simulink models with Android devices, enabling real-time testing
and deployment.
The installation includes:
 Android Studio (Electric Eel – 2022.1.1)
 SDK Platform 33, Build Tools 33.0.1, NDK version 25.1.8G373G3
 Simulink Android Support Package via MATLAB Add-On Explorer

PROCEDURE:
Step 1: Install Android Studio (Electric Eel - 2022.1.1)
1. Download the installer from the official Android Studio website.
2. Follow the OS-specific setup instructions.
3. During installation, ensure SDK, NDK, and Emulator components
are selected.
4. Launch Android Studio after installation.
Step 2: Install Required SDK, NDK, and Build Tools
1. Open Android Studio and navigate to:
o File > Settings (Windows/Linux) or Android Studio >
Preferences (macOS).
o Go to System Settings > Android SDK.
2. Under SDK Platforms tab:
o Install Android 13 (API level 33).
3. Under SDK Tools tab:
o Install:

 Build Tools 33.0.1


 Android SDK Command-line Tools
 Android Emulator (optional)
 NDK (Side by Side) – version 25.1.8G373G3

Step 3: Install Simulink Support Package for Android Devices


1. Open MATLAB.
2. Go to Home tab > Add-Ons > Get Hardware Support Packages.
3. Search for "Simulink Support Package for Android Devices" and click
Install.
4. Follow the guided installer to complete the package installation.

Step 4: Connect and Set Up Android Device


1. Enable Developer Mode on your device:
o Settings > About Phone > Tap 'Build Number' 7 times.
2. Enable USB Debugging:

o Settings > Developer Options > USB Debugging.


3. Connect the Android device via USB.
4. MATLAB will attempt to detect the device. If not recognized:
o Restart both MATLAB and the Android device.

Step 5: Install and Verify Test App


1. After successful connection, Simulink installs a test app on the
Android device.
2. This confirms proper communication and readiness for
model deployment.
OUTPUT:

 Android Studio (Electric Eel) installed successfully with SDK, NDK,


and Build Tools.
 Simulink Support Package for Android Devices was installed via
MATLAB Add-On Explorer.
 Android device was successfully detected in MATLAB.

 Test app was installed and verified.

CONCLUSION / RESULT:
✔ Successfully set up the Android development environment with Android
Studio Electric Eel (2022.1.1).
✔ Installed SDK Platform 33, Build Tools 33.0.1, and NDK 25.1.8G373G3.
✔ Installed Simulink Support Package for Android Devices via MATLAB.
✔ Android device was connected, detected, and configured properly for model
deployment.
✔ Simulink is now ready to build, simulate, and deploy models onto Android
hardware.
Lab Experiment -5
AIM:

To learn how to access and utilize an Android device's camera in Simulink by


building a model that captures video feed and displays it using Android Support
Package.

THEORY:
Simulink provides Android Support Blocks that allow communication
between Simulink and Android hardware. One such block is the Android
Camera block, which captures real-time images or video feed from a
connected Android
device. This feed can then be used for image processing, video display, or
other applications directly from the Simulink model.

PROCEDURE:
Step 1: Set Up Simulink Model
1. Open MATLAB and launch Simulink by typing simulink in the
command window or by clicking the Simulink icon.
2. Create a new model via File > New > Model.
Step 2: Add the Android Camera Block
1. Open the Simulink Library Browser.
2. Navigate to the Android Support Package section.
3. Drag and drop the Android Camera block into your model.
Step 3: Configure the Camera Block
1. Double-click the Android Camera block.

2. Set the following configurations:


o Resolution: e.g., 640x480 or 1280x720
o Video Format: e.g., MJPEG or YUV420
o Additional options: Exposure, Flash Mode, etc., can be
customized as needed.

Step 4: Add Display or Processing Blocks (Optional)


 To visualize the camera feed, add a Video Display block.
 Optionally, other image processing blocks can be added for
advanced tasks.
Step 5: Deploy the Model to Android Device
1. Click on the Deploy to Hardware button (green arrow in Simulink).
2. MATLAB will compile the model and transfer it to the connected
Android device.
3. On successful deployment, the Android device will launch the
camera and begin streaming.
OUTPUT:
 Simulink model successfully built and deployed to Android hardware.
 After deployment, the camera feed opened on the Android device.
 Real-time video feed was either displayed on the device or
processed based on model configuration.
 The Simulink model included a connection between the Android
Camera block and Video Display block.

CONCLUSION / RESULT:
->Understood how to configure and use the Android Camera block in
Simulink.
->Successfully created and deployed a Simulink model to access the live
camera feed on an Android device.
->Gained hands-on experience with real-time hardware interfacing through
Simulink.
->This activity is foundational for future applications in mobile image
processing, augmented reality, and computer vision projects using
MATLAB/Simulink.
Lab Experiment-6
AIM:

To convert an RGB image to grayscale and black & white using Simulink blocks
from the Computer Vision Toolbox, and simulate the process using Android
Hardware Support Package.

THEORY:
Digital images are typically stored in RGB (Red, Green, Blue) format. For many
image processing tasks, it is more efficient to work with grayscale or black-and-
white versions of the image:
 Grayscale: Converts the RGB image to shades of gray by removing
hue and saturation while retaining luminance.
 Black & White (Binary): Converts an image to only two colors —
black and white — based on a threshold.
In Simulink, this task is achieved using the Computer Vision Toolbox, which
includes blocks such as:
 Image From File: Reads an image into the model.
 Color Space Conversion: Converts RGB to grayscale or other
color spaces.
 Video Viewer: Displays image output.

PROCEDURE:
1. Open Simulink:
o Launch MATLAB.

o Open Simulink by typing simulink in the command window


or clicking the Simulink icon.
2. Create a New Model:
o Go to File > New > Model.

o Open the Simulink Library Browser.


3. Add Required Blocks from Computer Vision Toolbox:
o Image From File: Select an image to load.
o Color Space Conversion:
 Set Conversion to “RGB to Grayscale” or “RGB to
Binary” depending on the desired output.
o Video Viewer: Used to display the image output.

4. Connect the Blocks:


o Connect Image From File → Color Space Conversion →
Video Viewer.
5. Configure the Blocks:

o Set the file path in the Image From File block to your input image.
o In the Color Space Conversion block:
 Choose either Grayscale or Binary (black & white) as
the output format.

o No special configuration is needed for the Video Viewer.


6. Run the Simulation:
o Click the Run button
o The output image will appear in the Video Viewer.

OUTPUT:

 The selected RGB image was successfully loaded and converted:


o One output showed the grayscale version of the image.
The other output demonstrated black & white (binary) conversion.
 Images were visualized using the Video Viewer block in real-time.
 Block selection screenshots
 Block configuration screenshots

 Input RGB image


 Grayscale output image
CONCLUSION / RESULT:
->Successfully converted RGB images into grayscale and black & white
formats using Simulink’s Computer Vision Toolbox.
->Learned how to configure and connect relevant blocks in a Simulink model.
->Practiced basic image processing using Android-compatible blocks, preparing
for advanced tasks like object detection and filtering.
-> This technique is useful in various applications such as surveillance, mobile
vision, and pattern recognition.
Lab Experiment-7
AIM:

To perform real-time audio signal processing using Simulink with Android


support package by capturing, analyzing, and playing back audio signals on an
Android device.

THEORY:
Audio signal processing is the manipulation and analysis of sound waves using
software and hardware tools. Simulink, with its DSP System Toolbox and
Android Support Package, enables audio signal input, modification, and output
via Android devices.
Key concepts involved:
 Sine wave generation for synthetic audio signals.

 Microphone input capture using Android.


 Real-time signal visualization via Time Scope and Spectrum Analyzer.
 Nyquist Criterion: To avoid aliasing, the sampling frequency must be
at least twice the input signal frequency.

APPARATUS / SOFTWARE REQUIRED:

 MATLAB with Simulink


 Simulink Support Package for Android Devices
 DSP System Toolbox
 Android Studio (installed previously)
 Android smartphone with developer mode enabled

 USB cable
 Headphones with microphone

PROCEDURE:

Step 1: Pre-Setup
 Ensure all required toolboxes and support packages are installed.
 Connect the Android device via USB with Developer Mode and
USB Debugging enabled.
 Connect headphones with a mic to the Android device.

Step 2: Simulink Model Overview


The model includes:
 Sine Wave Generator (Simulation Source)
 Audio Capture Block (Microphone Input)
 Manual Switch (To toggle between sine wave and microphone input)

 Time Scope & Spectrum Analyzer (For visualization)


 Audio Playback Block (To hear the output)

Step 3: Configuring the Sine Wave Block


 Amplitude: 1
 Frequency: 1000 Hz

 Sample Time: 1/44100


 Samples per Frame: 4410
 Frequency slider panel is added for interactive frequency control.

Step 4: Audio Capture Block


 No special configuration needed. Defaults are used for live
microphone input.

Step 5: Run the Simulation with Pacing

 Set the manual switch to sine wave.


 Enable Simulation Pacing under Simulation > Run > Pacing.
 Adjust pacing slider for real-time viewing.
 Observe the waveform and frequency peaks change when
frequency slider is moved.

Step 6: Nyquist Sampling Criterion Experiments

A. Low Sampling (1500 Hz):


 Sample Time: 1/1500
 Samples per Frame: 150
 Result: Aliased waveform visible in Time Scope.
B. Moderate Sampling (10,000 Hz):
 Sample Time: 1/10000

 Samples per Frame: 1000


 Result: Improved waveform reconstruction.
C. High Sampling (44,100 Hz - CD Quality):
 Sample Time: 1/44100
 Samples per Frame: 4410
 Result: Clear sine wave without distortion.

Step 7: External Mode Testing (Real-Time Monitoring)


 Switch input to Sine Wave.
 Go to Hardware > Monitor & Tune.
 Simulink launches the androidAudioGettingStarted app.
 Adjust slider to change frequency in real-time and hear audio
through device.
Step 8: Deploying the Model to Android
 Set switch to Sine Wave → Go to Build, Deploy & Start.

 After deployment, control the signal on the Android device using


the slider.
 Switch to Microphone input → Deploy again to test live audio
capture and playback.
OUTPUT:
 Successfully captured microphone input using Audio Capture block.

 Sine wave output was generated and controlled in real-time using


slider panel.
 Aliasing observed at lower sampling rates, validating Nyquist Theorem.
 High-quality audio reconstruction was achieved at 44.1 kHz
sampling rate.
 Real-time playback through Android was tested and verified
using external mode and deployment.

CONCLUSION / RESULT:
✔ Gained hands-on experience in audio signal processing using Simulink.
✔ Understood the effects of sampling frequency on signal reconstruction and
distortion.

✔ Learned to use Time Scope and Spectrum Analyzer for signal analysis.
✔ Successfully deployed a real-time audio processing model to an Android
device.
✔ Extended functionality to microphone input, enabling real-world
applications like audio filtering and sound analysis.
Lab Experiment-8
Aim

To implement a custom user-defined function using the S-Function block in


Simulink and simulate a mathematical operation (e.g., squaring the input) using
a MATLAB-based S-Function.

Theory
Simulink provides a powerful environment to model and simulate dynamic
systems. For custom computations not covered by standard blocks, User-
Defined Functions can be implemented using:
 MATLAB Function Block
 S-Function Block
An S-Function (System Function) is a computer language description of a
Simulink block written in MATLAB, C, C++, or Fortran. It provides the flexibility
to define customized behavior for simulation.
In this experiment, we create a Level-1 MATLAB S-Function to square the input
value and output the result. The function is triggered at each simulation step
based on the input signal.

Procedure
Step 1: Open Simulink
 In the MATLAB Command Window, type:
 simulink
 Press Enter to open the Simulink Library Browser.

 Create a new blank


model. Step 2: Add the S-
Function Block
 Navigate to:
Simulink > User-Defined Functions > S-Function
 Drag the S-Function block into the blank model.

Step 3: Create the MATLAB S-Function File


 Open a new script in MATLAB, name it my_sfun.m.
 Enter the following code:
function [sys,x0,str,ts] = my_sfun(t,x,u,flag)

switch flag

case 0 % Initialization

sizes = simsizes;

sizes.NumContStates = 0;
sizes.NumDiscStates = 0;

sizes.NumOutputs = 1;

sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;

sizes.NumSampleTimes = 1;
sys = simsizes(sizes);

x0 = [];

str = [];
ts = [0 0];

case 3 % Output

sys = u.^2; % Custom computation: square the input


case {1, 2, 4, 9} % Other flags

sys = [];

otherwise

error(['Unhandled flag = ', num2str(flag)]);

end

 Save the file in the current working directory.

Step 4: Configure the S-Function Block


 Double-click the S-Function block.
 Set S-function name to:
my_sfun
 Click OK.

Step 5: Connect Input and Output Blocks


 Add a Constant block or Signal Generator for input.
 Add a Scope block or Display block for output.

 Connect them as follows:


[Constant] → [S-Function] →
[Display] Step 6: Run the Simulation
 Click the Run button or press Ctrl+T.
 Observe the output on the Display or Scope.
Output / Results
For a Constant input = 3, the S-Function computes:
Output=32=9\text{Output} = 3^2 = 9
The output observed in the Display block or Scope will be:
9
Conclusion
 A MATLAB-based S-Function was successfully implemented in Simulink.
 The custom function squared the input signal as intended.

 This approach allows for integrating custom algorithms into Simulink


models, making it useful for advanced simulations and modeling
real- world logic.
Lab Experiment-9
AIM:
To install the Arduino Hardware Support Package in MATLAB and perform a basic
LED blinking operation using Arduino, thereby understanding the process of
interfacing hardware with MATLAB.

THEORY:
Arduino is an open-source electronics platform based on easy-to-use hardware
and software, widely adopted for building interactive projects. MATLAB,
developed by MathWorks, allows users to control Arduino hardware through the
Arduino Hardware Support Package. This integration enables MATLAB to
communicate with and control Arduino boards directly, using high-level
commands.
Key Concepts:
 Arduino Hardware Support Package:
A collection of drivers and APIs that facilitate MATLAB–Arduino
communication.
 LED Blinking:
A fundamental operation in Arduino programming, typically used as a preliminary
test to confirm hardware setup and code functionality.

REQUIREMENTS:
 MATLAB (with internet access)
 Arduino board (UNO, Mega, Nano, etc.)

 USB cable
 Breadboard (optional)
 LED (optional)
 220Ω resistor (optional)

PROCEDURE:

Part 1: Installing Arduino Hardware Support Package


1. Open MATLAB.
2. In the Command Window, type:
3. In the Support Package Installer window:
o Select Install from Internet.
o Choose Arduino Hardware from the list.

o Follow the prompts to complete installation (make sure


Arduino drivers are also installed).
o Once done, MATLAB will be ready to communicate with
Arduino boards.

Part 2: LED Blinking using MATLAB and Arduino


Method 1: Using On-Board LED (Pin 13)
1. Connect the Arduino to your PC using the USB cable.
2. In MATLAB, create an Arduino object:
a = arduino();
3. Use the following code to blink the onboard LED:
for i = 1:10
writeDigitalPin(a, 'D13', 1); % Turn ON
LED pause(1); % Wait 1 second
writeDigitalPin(a, 'D13', 0); % Turn OFF
LED pause(1); % Wait 1 second
end
Method 2: Using External LED (Pin 9)
1. Connect the longer leg (anode) of the LED to digital pin 9 through a
220Ω resistor.

2. Connect the shorter leg (cathode) of the LED to GND.


3. Use this MATLAB code:
a=
arduino(); for
i = 1:10
writeDigitalPin(a, 'D9', 1); % Turn
ON LED pause(0.5); % Wait
0.5 seconds writeDigitalPin(a, 'D9', 0);
% Turn OFF LED pause(0.5); %
Wait 0.5 seconds
end

OUTPUT / RESULTS:
 The onboard or external LED blinks ON and OFF at 1-second or
0.5- second intervals.
 MATLAB successfully communicates with the Arduino board.
 Users can control physical Arduino hardware directly from
MATLAB scripts.
CONCLUSION:
This experiment successfully demonstrated the installation and use of the
Arduino Hardware Support Package in MATLAB to perform a basic LED
blinking task. The process highlighted the ease of integrating MATLAB with
Arduino for real-time hardware control. The activity also reinforced
foundational
electronics concepts and provided a base for future explorations in real-time
data acquisition, HIL simulations, and embedded systems prototyping using
MATLAB and Arduino.
Lab Experiment-10
AIM:

To design and implement a temperature monitoring system using an Arduino


Uno and an LM35 analog temperature sensor, and to display the
temperature readings on the Serial Monitor.

THEORY:
Temperature monitoring is a key feature in many applications, including:

 Weather stations
 Industrial automation
 Medical devices
 Home automation
The LM35 is a precision analog temperature sensor that outputs a voltage
linearly proportional to the temperature in degrees Celsius. It does not require
external calibration and has low self-heating.
Working Principle of LM35:
 The LM35 provides 10 mV per °C.
 Example: An output of 0.25V corresponds to 25°C.
 Arduino reads this analog voltage via its analog input pins and
converts it into temperature using the formula:
Temperature (°C) = Voltage (in volts) × 100

COMPONENTS REQUIRED:
Component Quantity

Arduino Uno 1

LM35 Temperature Sensor 1

Breadboard 1

Jumper Wires As needed

USB Cable 1

16x2 LCD Display (I2C) (Optional) 1

CIRCUIT DIAGRAM / CONNECTIONS:


LM35 to Arduino:

LM35 Pin Arduino Pin

VCC  5V

GND  GND

OUT  A0

LCD Pin Arduino Pin

VCC  5V

GND  GND

SDA  A4

SCL  A5
PROCEDURE:
1. Connect the LM35 sensor to the Arduino Uno as per the circuit diagram.
2. Open the Arduino IDE on your computer.
3. Write or paste the following code into the editor.

4. Connect the Arduino Uno to your PC using a USB cable.


5. Go to Tools > Board and select Arduino Uno.
6. Go to Tools > Port and choose the correct COM port.
7. Click the Upload button to upload the code.
8. Open the Serial Monitor (Ctrl + Shift + M) to observe real-time
temperature readings.
ARDUINO CODE:
const int sensorPin = A0;
float temperatureC;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue =
analogRead(sensorPin); float voltage =
sensorValue * (5.0 / 1023.0);
temperatureC = voltage * 100.0;
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000);
}

OUTPUT / RESULTS:
Once the code is uploaded and the Serial Monitor is open, the temperature will
be displayed in degrees Celsius, updating every second.
Sample Output:

Temperature: 28.65 °C
Temperature: 28.70 °C
Temperature: 28.72 °C
 The readings reflect real-time changes in the surrounding environment.
 Sensor accuracy and data update interval are suitable for
basic monitoring.

CONCLUSION:
The temperature monitoring system using Arduino Uno and the LM35 sensor
was successfully designed and implemented. The LM35 sensor accurately
detected environmental temperature and provided corresponding voltage
readings. Arduino processed these readings and displayed the temperature
values on the Serial Monitor.
Possible Extensions:
 Displaying temperature on a 16x2 LCD display
 Adding audible or visual alerts for high/low temperature
 Data logging to SD card or cloud

 Sending real-time temperature readings via Wi-Fi or Bluetooth


for remote monitoring
Lab Experiment-11
AIM:

To design and implement a basic traffic light decision system in Simulink that
takes into account the traffic signal state and vehicle speed to output
driving decisions.

THEORY:
Traffic light negotiation is a key part of autonomous driving and intelligent
transportation systems. A vehicle must decide whether to stop, slow down,
or go based on:
 Current traffic light state (Green, Yellow, Red)
 Vehicle speed
This simulation uses:

 Clock and math operations to simulate the changing state of a


traffic light.
 Multiport switch to switch between signal states.
 MATLAB Function block to apply decision logic based on light state
and vehicle speed.
 Display block to visualize the output decision.

PROCEDURE:
Step 1: Open Simulink
 Launch MATLAB.
 Type simulink in the command window.
 Open a Blank Model.
Step 2: Add a Clock Block
 Go to Simulink Library → Sources.
 Drag and drop the Clock block into the model.

Step 3: Add Floor, Modulus, and Constant Blocks


 From Math Operations, add:
o Floor block (rounds time).
o Mod block (cycles traffic light states).
o Constant block (set value = 3).

 Connect:
o Clock → Floor → Mod
o Constant (3) → Mod

Step 4: Traffic Light Switching Setup

 Add Constant Blocks for:


o Green (Value = 1)
o Yellow (Value = 2)
o Red (Value = 3)
 From Signal Routing, add a Multiport Switch.
 Connect:

o Green, Yellow, and Red → inputs of Multiport Switch.


o Mod Output → +1 Block → Control Input of Switch
(because switch uses 1-based index).
o Output of switch represents current light state.
Step 5: Vehicle Speed Input
 Add a Constant block with value (e.g., 600).
 Label it Vehicle Speed.

Step 6: Add MATLAB Function Block (Decision Logic)


 From User-Defined Functions, add a MATLAB Function Block.
 Double-click and enter the following code:
function decision = fcn(light, speed)
% light: 1 = Green, 2 = Yellow, 3 = Red
% speed: Vehicle speed in some units

if light == 1
decision = "GO";
elseif light == 2
if speed >
500
decision = "SLOW DOWN";
else
decision = "STOP";
end
else
decision = "STOP";
end
end

 Connect:
o Multiport Switch output → light input
o Vehicle Speed → speed input

Step 7: Display Output

 From Sinks, add a Display block.


 Connect output of MATLAB Function block → Display block.

Step 8: Run the Simulation


 Click Run.
 Observe the traffic decision logic in the Display block, which may show:

o "GO"
o "SLOW DOWN"
o "STOP"

OUTPUT:
 The model simulates a changing traffic light every 3 seconds.
 Based on the current light and speed (e.g., 600), the MATLAB
Function block outputs:
o "GO" if green,
o "SLOW DOWN" if yellow and speed > 500,
o "STOP" for red or yellow with speed ≤ 500.
 Display block dynamically updates with the correct driving instruction.

CONCLUSION / RESULT:
✔ Successfully implemented a traffic light negotiation system using Simulink.
✔ Developed logic that dynamically responds to traffic signal changes and
vehicle speed.
✔ Understood real-time signal processing and logical flow control using
MATLAB Function blocks.
✔ Can be extended to real-world embedded systems for smart vehicle control
and intersection safety.

You might also like