0% found this document useful (0 votes)
34 views5 pages

Lab 6: Signal Processing With Nodemcu and Matlab

Uploaded by

Androw Shonoda
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)
34 views5 pages

Lab 6: Signal Processing With Nodemcu and Matlab

Uploaded by

Androw Shonoda
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/ 5

Lab 6: Signal processing with NodeMCU and

MATLAB

Names IDs
Androw shonoda twfeek beniameen 320210333

320210344
Abdelrahman Mohammed Anwar

Objectives:
In this lab we will learn how to integrate NodeMCU with MATLAB for real-time
signal processing.

Introduction to MATLAB
- MATLAB is a versatile tool for numerical computation, data analysis,
visualization, and algorithm development. Originally designed for matrix
computations, it excels at handling numerical data with built-in functions for
matrix manipulation, linear algebra, and statistics.
- Users can perform real-time calculations, visualize data in 2D and 3D, and develop
algorithms efficiently, facilitating rapid prototyping and development. Its powerful
visualization tools aid in gaining insights from data and effectively communicating
findings.

Why acquire data with MATLAB?


- Understanding: It provides insights into real-world phenomena, aiding decision-
making and process improvement.
- Monitoring and Control: Enables real-time system monitoring and control to
maintain desired conditions.
- Validation and Verification: Validates models and verifies experimental results for
accuracy.
- Optimization and Improvement: Identifies inefficiencies and drives process
optimization.

For installing MATLAB, please follow this link


https://www.youtube.com/watch?v=eIQ1KbRTC8Q&t=880s

Task: Plotting Real-Time Serial Data from NodeMCU in MATLAB


In this task you use MATLAB to take real-time values from a sensor and plot the data,
enabling you to monitor and analyze sensor measurements in real-time.

Procedure:
1. Select a sensor for real-time data collection, like a temperature sensor, altrasonic
sensor, or any sensor you used before.
2. Implement Arduino IDE code to read data by ESP8266.
3. Write MATLAB code to read data from the sensor continuously.
4. Use MATLAB's plotting functions to create a live plot of the sensor data.
5. Add labels, titles, and customize the plot appearance.
Code
#define TRIG_PIN D6// ESP32 pin GPIO12 connected to
Ultrasonic Sensor's TRIG pin
#define ECHO_PIN D5 // ESP32 pin GPIO14 connected to
Ultrasonic Sensor's ECHO pin
#define RELAY_PIN D1 // ESP32 pin GPIO5 connected to
Relay's pin
#define DISTANCE_THRESHOLD 50 // centimeters
// variables will change:
float duration_us, distance_cm;
void setup() {
Serial.begin (9600); // initialize serial port
pinMode(TRIG_PIN, OUTPUT); // set ESP32 pin to output mode
pinMode(ECHO_PIN, INPUT); // set ESP32 pin to input mode
pinMode(RELAY_PIN, OUTPUT); // set ESP32 pin to output
mode
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(ECHO_PIN, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
if (distance_cm < DISTANCE_THRESHOLD)
digitalWrite(RELAY_PIN, HIGH); // turn on Relay
else
digitalWrite(RELAY_PIN, LOW); // turn off Relay
// print the value to Serial Monitor
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
delay(500);
Requirements:
1. Arduino IDE code
#define TRIG_PIN D6// ESP32 pin GPIO12 connected to Ultrasonic Sensor's TRIG pin

#define ECHO_PIN D5 // ESP32 pin GPIO14 connected to Ultrasonic Sensor's ECHO pin

#define RELAY_PIN D1 // ESP32 pin GPIO5 connected to Relay's pin

#define DISTANCE_THRESHOLD 50 // centimeters

// variables will change:

float duration_us, distance_cm;

2. MATLAB code
3. A screenshot of your real-time graph

References:
https://www.youtube.com/watch?v=0F-VjddQG8o

You might also like