Lab 6: Signal Processing With Nodemcu and Matlab
Lab 6: Signal Processing With Nodemcu and Matlab
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.
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
2. MATLAB code
3. A screenshot of your real-time graph
References:
https://www.youtube.com/watch?v=0F-VjddQG8o