Final Project¶
1.Final Project Presentation¶
1.1 Final Project Slides¶
1.2 Final Project Video¶
2.Final Project Requirements¶
- What does it do? - Answered
- Who’s done what beforehand? - Answered
- What did you design? - Answered
- What materials and components were used? - Answered
- Where did they come from? - Answered
- How much did they cost? - Answered
- What parts and systems were made? - Answered
- What processes were used? - Answered
- What questions were answered? - Answered
- What worked? What didn’t? - Answered
- How was it evaluated? - Answered
- What are the implications? - Answered
2. Where is idea comes from?¶
2.1 Ideas and sketches¶
I tentatively decide that my final project is “The Beauty of Parting and Reuniting”. All inspiration came from the video I saw below.
From a mathematical geometry perspective, we can easily divide a square into different pieces to make the entire shape look like a Tai Chi pattern. Each small piece of graphics in the divided graphics is connected to adjacent graphics. By rotating the center of the figure, you can see the 8 fragment patterns scattered around the center. After the final rotation, a new hexagonal pattern is formed.
I want to express the concepts of division and union in Chinese culture through the transformation of this mathematical geometric pattern.
In fact, at the beginning, I just wanted to make a desktop ornament to prove the completion of the project. Some of the inspiration needs came from when I went home during the Spring Festival. When I found out that when I returned home, my grandparents were living alone, and there were often things that they couldn’t take care of. The inconvenience of the elderly’s legs and feet will have a certain impact on the elderly’s daily health. In order to better take care of the elderly’s home health, I decided to use some Internet of Things monitoring solutions.
2.2 Function and application definition¶
2.2.1 People Fall Detector¶
Thirdly,for another function, I hope that during the day, when the entire device is turned on, the movement status of indoor people can be detected through the mmwave sensor in the middle, as an anti-fall monitoring function.
2.2.2 Remote Alarm Message¶
Finally, the device can send the monitoring results to the cloud or mobile phone to remind people to monitor whether the elderly at home have fallen.
https://wiki.seeedstudio.com/xiao-esp32c3-esphome/
3. How can I make it?¶
3.1 Hero Shot¶
3.2 Materials List¶
Qty | Description | Price | Link | Notes |
---|---|---|---|---|
1 | Seeed Studio XIAO ESP32 | 4.99 $ | Seeed Studio XIAO ESP32 | |
1 | Seeed MR60FDA1 60GHz mmWave Sensor | 37.00 $ | Seeed MR60FDA1 60GHz mmWave Sensor | |
1 | DRV8833 Motor Driver Module | 2.00 $ | DRV8833 Motor Driver Module | |
1 | N20* 65r/min DC Motor | 5.00 $ | N20 DC Motor | |
1 | 24-WS2812 LED Ring | 6.00 $ | 24-WS2812 LED Ring | |
1 | 2*3 Pin SMD Socket | 0.30 $ | 2*3 Pin SMD Socket | |
1 | 2*4 Pin SMD Socket | 0.30 $ | 2*4 Pin SMD Socket | |
10 | M3*8mm Stud | 2.00 $ | M3*8mm Stud | |
14 | M3*22mm screws + M3 Nut | 5.00 $ | M3*22mm screws + M3 Nut | |
1 | 3mm Acrylic Boards | 6.00 $ | 3mm Acrylic Boards | |
1 | Jumping Cables | 0.30 $ | Jumping Cables | |
Total Cost | 69.19 $ |
3.3 Workflow, Timeline and Milestones¶
Phase | Week | Dates | Tasks | Milestones |
---|---|---|---|---|
Planning and Ideas | Week 1 | May 6 - May 12 | - Define project objectives - Gather all necessary components - Install and configure the Arduino IDE - Research and choose the appropriate materials |
May 10: Complete initial preparation |
Mechanical Design | Week 2 | May 12 - May 19 | - Prototype the 2D/3D design - Debug and optimize the 2D & 3D design - Assemble the mechanical parts |
May 17: Finalize the mechanical parts |
Electronic Design | Week 3 | May 19 - May 26 | - Develop schematic design & PCB design - Manufacture the PCB boards - Test and debug the PCB boards |
May 23: Solve the PCB problems |
Software Design | Week 4 | May 26 - June 2 | - Develop the sensor - Debug and refine code for MQTT publish - Optimize performance and power consumption |
June 1: Fully tested and debugged system |
Finalization | Week 5 | June 2 - June 6 | - Finalize the function (software & hardware) - Organize the materials (videos & photos) - Prepare for final presentation and documents |
June 6: Project finalized and ready for presentation |
After the final project presentation, I will need to use two weeks to make the weekly assignment which i didnt finished before.
4.What I have done to accomplish the project?¶
4.1 Electronics Parts Design¶
Since I have previous experience in circuit design and have mastered the use of AD10 EDA software, I wanted to try the new software KiCAD for this circuit design, and finally found that this software is the best choice for embedded engineers.
4.1.1 Hardware Conection Draft¶
The main things is connect the following pins with the microcontroller accoording to the Sensors wiki page.
4.1.2 Schematic Design¶
When designing the schematic diagram, I did not directly connect the various devices. In order to facilitate subsequent inspection, I used a modular design and set mark numbers to connect them to facilitate error checking.
4.1.3 PCB Layout Design¶
When designing the PCB, since we directly used the schematic diagram for wiring, I still retained the XIAO ESP32 module. I drew a notch on the board to clamp the microcontroller, and fixed it through the pads next to it. The connection between the main controller and other devices. The PCB wiring process is a relatively time-consuming process. It must comply with the rules so that all the lines are placed together without interfering with each other, and the board must be beautiful and tidy.
4.2 Electronics Parts Manufacturing¶
4.2.1 Generate manufacturing files¶
I exported the PCB to the corresponding manufacturing file through kicad’s export tool. A total of three files were exported. The three GBR format files of trace, drill and cut respectively correspond to the surface processing, drilling processing and edge cutting processing of PCB processing.
4.2.2 PCB Milling¶
Step 1: I need to convert all manufacturing project GBR files into PNG through the Gerber2PNG tool, as shown below.
Step 2: when the manufacturing file is imported, you can see the entire PCB pattern displayed.
Step 3: we need to obtain three separate manufacturing and processing PNG images of PCB trace, drill, and cut by selecting and outputting different files.
Step 4: Send the generated manufacturing files through the modsproject website and output them into corresponding NC processing files for CNC machine processing. When you need to pay attention here, you need to select the resolution of the PNG file, as well as the tool speed and depth of the drilling process.
Step 5: Import the following successfully converted NC processing files into the CNC machine for processing.
Step 6: The final circuit board produced is as follows.
4.2.3 Debug, Simulate,Test Board.¶
I did not conduct a virtual program simulation of the board’s functions. I just checked the design rules after drawing the drawings. Here is ERC running resulf with not faluts
But this also caused me a fatal design error. Since I did not simulate and check carefully, I only discovered when I actually made the circuit and downloaded the program for testing that I had connected the RX and TX interfaces of the main sensor with the RX of XIAO. , the TX interface was connected incorrectly, which resulted in me having to use flying wires to make modifications before finding the error, and then making modifications in subsequent secondary manufacturing. This process wasted a lot of time and energy on my part.
This is normal mistakes that I miss connected with the RX&TX ports with micro controller boards and sensors. The correct should be as follows.
Under my mentor Salman‘s help, He helped me to sold to jumping cable to make it connect in a right way.
Finally it comes with result when i conenct the boards with my laptop from Serial monitor.
4.2.4.Rework, Optimize Final Board¶
In fact, the optimized version of this part is the final circuit optimization plan decided after I tested the first version and installed it.
In the final version, I made the following optimizations to the PCB:
1. Increase the trace width: In order to make the processed circuit traces more obvious, I increased the width of the circuit traces from 0.8mm to 1mm;
2. Adjust the connection port:In order to facilitate wiring, I plan to use the soft serial port that comes with XIAO ESP32 in subsequent changes, so I modify the sensor’s connection interface and add additional pad interfaces;
3. Adjust the size and thickness of the mark silk screen: In order to make the pattern more obvious, I modified the position and size of the silk screen;
4. Add fixing holes on the PCB board: In order to make the board and structural parts more stable in the future, I added 5 M3 screw positioning holes;
5. Modify the SMD socket of the sensor to a direct plug-in socket: In order to facilitate the fixation and welding of the sensor, and thus more convenient for stable signal transmission, I modified the socket model.
4.3 Appearance 2D/3D Design and Manufacturing¶
At first, I used the new software Onshape for structural design, but due to network speed limitations and operating habits, I switched back to solidworks for appearance design.
In the structural part, I mainly need to solve three main problems:
1. Rotating opening and closing structure plan
2. Electric transmission structure plan;
3. Device fixing plan;
4.3.1 Rotating opening and closing structure solution¶
At the beginning, I wanted to make an opening and closing art installation based on my original idea, but later I found that it was difficult to produce and process a discrete pattern.
In the end, I referred to many mechanisms of opening and closing devices and chose one for production and processing. At first, I just drew the device according to the size of the PCB to realize the rotation opening and closing function.
The final complete mechanical structure is shown below. By rotating and fixing, the device can be opened and closed, and the leakage sensor can be used for measurement.
4.3.2 Electric transmission structure plan;¶
This transmission mechanism is actually the most difficult part of the entire design. I need to solve 3 problems:
a. How to fix the motor to the entire mechanism? I designed a third version to fix the motor by designing a motor fixing hole;
b. How to make the motor rotate to rotate the entire mechanism? I designed a gear meshing mechanism, and the outermost opening and closing mechanism must be rotated to complete the rotation.
c. How to make the gear meshing mechanism more perfect? I originally wanted to use the size generation tool that comes with Solidworks, but because the size I needed was too small, I could only design it myself according to the rules of the basic size asymptote.
4.3.3 Device fixing and assembling plan;¶
Because my final design is a component that can support a rotating plane. So I used 3D printing to process it. I need to design a stand that is not vertical, but a base that is tilted at an angle of 25 degrees to the proof, with 4 fixed slanted openings on the front of the base. So I used 3D printing to machine my base.
Step1: I drawed a cube as 65 mm * 65mm,then make it into 5mm thickness as the basic platform.
Step2: I seletected the front side and make the upder stand as a 25degree angle.
Step3: Adjust some right-angle parts to a radius of 15mm, especially make arc supports on the supporting parts to increase the stability of the base.
Step4: Four circular holes with a diameter of 3 mm were made by extrusion cutting.
Issues: Becuase I was set the support in this 3D printing. It makes the 4 holes is not easy to clean.
3D Design Stand STL File
4.3.4 Final 2D/3D Design Confirmation and Optimization¶
The final mechanical structure is shown below. For most of the components, I used a laser cutting machine to cut 3mm acrylic plates. After three revisions, I got the final solution, which uses a small motor to control the gear meshing to control the rotation. combination device. In addition, I also used 3D printing to make the bracket of the device, and reserved an installation position for the decorative LED light ring at the back.
5. Software and Funtion Design¶
5.1 Funtion Defination¶
- The human mmwave sensor can detect the following states:
- When the sensor is working normally and no one is detected, the sensor will report a relatively low data value, and the LED light ring will light up green to indicate the working status.
- When the sensor starts to detect that someone is passing or staying, the sensor will report the data value and give a text reminder in the data column of MQTT, and the LED light ring will light up yellow to indicate that a person is detected.
- When the sensor surface has detected that someone has appeared or stayed, if this process lasts for more than 20 seconds, the sensor will remind that someone has fallen, and will issue a remote alarm message, and the LED light ring will light up red to indicate the status of fall detection.
- When the human mmwave sensor does not detect any object for a long time, it can turn off the opening and closing mechanism of the sensor by rotating the motor and enter sleep mode. Of course, people can also remotely control the switch through the mobile phone.
- The LED light ring will display the working status of the sensor and the detected information. It should display different colors of yellow/red/green to respectively show the three states of someone being present, someone falling, or no one in front of the sensor.
- It should send alarm data to the mobile phone and leave sensor records to check the status.
- It should remotely control the opening or closing of the rotating part.
5.2 Software Workflow¶
Software Workflow¶
|-------------------------| |+-----------------------+| | Setup | +-------------------------+ | - Initialize Serial | | - Initialize WiFi | | - Initialize MQTT | | - Set up motor pins | | - Set up LED strip | | - Set up radar module | +-----------+-------------+ | V +-------------------------+ | Loop | +-------------------------+ | - Check MQTT connection | | - Check radar data | | - Handle radar report | +-------------------------+ | V +-------------------------+ | Handle Radar Report | +-------------------------+ | - Check radar report | | - Send corresponding | | MQTT message | | - Set LED color | | - Delay for 0.2s | +-------------------------+ | V +-------------------------+ | MQTT Callback | +-------------------------+ | - Check if message | | is for motor control | | - Run or stop motor | | sequence accordingly | +-------------------------+ | V +-------------------------+ | Run Motor Sequence | +-------------------------+ | - Ramp motor speed up | | - Ramp motor speed down | | - Stop motor | +-------------------------+ | V +-------------------------+ | Stop Motor | +-------------------------+ | - Ramp motor speed down | | - Ramp motor speed up | | - Stop motor | +-------------------------+ | V +-------------------------+ | Publish MQTT | +-------------------------+ | - Check MQTT connection | | - Publish message | +-------------------------+ | V +-------------------------+ | Setup WiFi | +-------------------------+ | - Connect to WiFi | | - Print IP address | +-------------------------+ | V +-------------------------+ | Reconnect MQTT | +-------------------------+ | - Attempt MQTT | | connection | | - Subscribe to topics | +-------------------------+ | V +-------------------------+ | Set Color | +-------------------------+ | - Set LED strip color | +-------------------------+ | V +-------------------------+ | Set Motor Current | +-------------------------+ | - Set motor direction | | and speed using PWM | +-------------------------+ | V +-------------------------+ | Spin and Wait | +-------------------------+ | - Set motor speed | | - Delay for duration | +-------------------------+
5.3.Code & Explanation¶
The software is designed to perform fall detection using a 60GHz radar sensor and control a motor based on commands received via MQTT (Message Queuing Telemetry Transport). The system also uses an LED strip to visually indicate the status detected by the radar sensor.
5.3.1 Detailed Working Principle
¶
Initialization (setup()):
- Serial Communication: Initializes serial communication for debugging (Serial.begin(115200)) and the radar sensor (mySerial.begin(115200)).
- WiFi Setup: Connects to the WiFi network using the provided SSID and password.
- MQTT Setup: Connects to the MQTT broker, sets up the server, and subscribes to the motor control topic.
- LED Strip Setup: Initializes the LED strip and sets its brightness.
- Motor Control Setup: Configures the pins for motor control and sets the initial state of the motor to off.
Main Loop (loop()):
- MQTT Connection Check: Ensures the device stays connected to the MQTT broker. If disconnected, it attempts to reconnect.
- Radar Data Processing: Continuously checks for radar data and processes it. If a radar report is available, it handles the report accordingly.
Handling Radar Reports (handleRadarReport(uint8_t report)):
- Interpretation: Interprets the radar report to determine if there’s no one, someone, or a specific activity (e.g., fall, movement).
- MQTT Messaging: Publishes corresponding messages to different MQTT topics based on the radar report.
- LED Indication: Sets the color of the LED strip based on the type of activity detected.
- Delay: Introduces a short delay to prevent rapid flashing of the LED strip.
MQTT Callback (mqttCallback(char topic, byte payload, unsigned int length)):
- Message Parsing: Parses incoming MQTT messages and converts them into a string.
- Motor Control: If the message is for motor control, it runs or stops the motor sequence based on the message content (“ON” or “OFF”).
Motor Control Sequences:
- Run Motor Sequence (runMotorSequence()):
- Ramps up the motor speed in increments, then reverses the speed back to a stop.
- Stop Motor (stopMotor()):Ramps down the motor speed in increments, then reverses the speed back to a stop.
- Set Motor Speed (set_motor_pwm(int pwm, int IN1_PIN, int IN2_PIN) and set_motor_current(int pwm_A)):
- Controls the motor speed and direction using PWM signals.
- Sets the motor speed and prints the status to the serial console.
MQTT Publishing (publishMQTT(const char* topic, String message)):
- Ensures the MQTT connection is active.
- Publishes the message to the specified MQTT topic.
WiFi Setup (setup_wifi()):
- Connects to the WiFi network and prints the IP address once connected.
MQTT Reconnection (reconnect()):
- Attempts to reconnect to the MQTT broker if the connection is lost.
- Subscribes to the necessary MQTT topics upon successful reconnection.
LED Control (setColor(uint32_t color)):
- Sets the color of all LEDs in the strip to the specified color and updates the strip.
Motor Speed Control (spin_and_wait(int pwm_A, int duration)):
- Sets the motor speed to the specified value and waits for the specified duration.
5.3.2 Working Principle Summary
¶
The software initializes various components (WiFi, MQTT, radar, LEDs, motor) and then continuously operates in a loop. It ensures persistent MQTT connectivity, processes radar data to detect human presence or falls, publishes relevant messages to MQTT topics, controls the LED strip for visual feedback, and controls the motor based on incoming MQTT commands.
5.3.3 Source Code
¶
#include "Arduino.h"
#include <60ghzfalldetection.h>
#include <SoftwareSerial.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>
// Define the pins for SoftwareSerial
#define RX_Pin A2
#define TX_Pin A3
#define LED_PIN 9
// Define the control inputs for a single motor
#define MOT_A1_PIN D0
#define MOT_A2_PIN D1
// MQTT Broker Details
const char* ssid = "Crail"; // WiFi Name
const char* password = "4646995a"; // WiFi Password
const char* mqtt_server = "mqtt.fabcloud.org"; // MQTT Broker Name
const char* mqtt_username = "fabacademy"; // MQTT Username
const char* mqtt_password = "fabacademy"; // MQTT Password
const char* mqtt_topic = "fabacademy/chaihuo/crail/sensor"; // MQTT Topic
const char* mqtt_topic1 = "fabacademy/chaihuo/crail/rawdata"; // MQTT Topic1
const char* mqtt_topic_fall = "fabacademy/chaihuo/crail/fall"; // MQTT Topic for Fall
const char* mqtt_topic_motor = "fabacademy/chaihuo/crail/motor"; // MQTT Topic for Motor Control
WiFiClient espClient;
PubSubClient client(espClient);
SoftwareSerial mySerial(RX_Pin, TX_Pin);
FallDetection_60GHz radar = FallDetection_60GHz(&mySerial);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, LED_PIN, NEO_GRB + NEO_KHZ800);
bool motorSequenceExecuted = false;
void setup() {
Serial.begin(115200);
mySerial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(mqttCallback);
client.subscribe(mqtt_topic_motor);
strip.begin();
strip.setBrightness(50);
// Motor control setup
pinMode(MOT_A1_PIN, OUTPUT);
pinMode(MOT_A2_PIN, OUTPUT);
// Turn off motor - Initial state
digitalWrite(MOT_A1_PIN, LOW);
digitalWrite(MOT_A2_PIN, LOW);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
radar.HumanExis_Func();
if (radar.sensor_report != 0x00) {
handleRadarReport(radar.sensor_report);
}
}
void mqttCallback(char* topic, byte* payload, unsigned int length) {
String message;
for (unsigned int i = 0; i < length; i++) {
message += (char)payload[i];
}
Serial.print("Message arrived on topic: ");
Serial.print(topic);
Serial.print(". Message: ");
Serial.println(message);
if (String(topic) == mqtt_topic_motor) {
if (message == "ON") {
runMotorSequence();
} else if (message == "OFF") {
stopMotor();
}
}
}
void runMotorSequence() {
Serial.println("Running motor sequence...");
// Ramp speed up.
for (int i = 0; i < 6; i++) {
spin_and_wait(25 * i, 150);
}
// Ramp speed into full reverse.
for (int i = 0; i < 6 ; i++) {
spin_and_wait(135 - 25 * i, 150);
}
// Stop.
spin_and_wait(0, 100);
Serial.println("Motor sequence completed.");
}
void stopMotor() {
Serial.println("Stopping motor...");
for (int i = 0; i < 6; i++) {
spin_and_wait(-25 * i, 150);
}
// Ramp speed into full reverse.
for (int i = 0; i < 6 ; i++) {
spin_and_wait(-135 + 25 * i, 150);
}
Serial.println("Motor stopped.");
}
void handleRadarReport(uint8_t report) {
String message;
String message1;
uint32_t color;
switch (report) {
case NOONE:
message = "Nobody here.";
color = strip.Color(0, 0, 0); // Off
publishMQTT(mqtt_topic, message);
break;
case SOMEONE:
message = "Someone is here.";
color = strip.Color(255, 255, 255); // White
publishMQTT(mqtt_topic, message);
break;
case NONEPSE:
message = "No human activity messages.";
color = strip.Color(0, 0, 0); // Off
publishMQTT(mqtt_topic, message);
break;
case STATION:
case MOVE:
message = "Someone moving or stopped.";
color = strip.Color(255, 255, 0); // Yellow
publishMQTT(mqtt_topic, message);
break;
case BODYVAL:
message1 = String(radar.bodysign_val, DEC);
color = strip.Color(0, 255, 0); // Green
publishMQTT(mqtt_topic1, message1);
break;
case FALL:
message = "Someone fell!";
color = strip.Color(255, 0, 0); // Red
publishMQTT(mqtt_topic, message);
publishMQTT(mqtt_topic_fall, message);
break;
}
Serial.println(message);
if (report == BODYVAL) {
Serial.println(message1);
}
setColor(color); // Set LED color
delay(200); // Delay for 0.2 seconds to prevent rapid flashing
}
void publishMQTT(const char* topic, String message) {
if (!client.connected()) {
reconnect();
}
client.loop();
if (client.connected()) {
client.publish(topic, message.c_str());
}
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
String clientId = "XIAO-ESP32-Client-";
clientId += String(random(0xffff), HEX);
if (client.connect(clientId.c_str(), mqtt_username, mqtt_password)) {
Serial.println("connected");
client.subscribe(mqtt_topic_motor); // Subscribe to the motor control topic
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void setColor(uint32_t color) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}
strip.show();
}
/// Set the current on the motor using PWM and directional logic.
///
/// \param pwm PWM duty cycle ranging from -255 full reverse to 255 full forward
/// \param IN1_PIN pin number xIN1 for the given channel
/// \param IN2_PIN pin number xIN2 for the given channel
void set_motor_pwm(int pwm, int IN1_PIN, int IN2_PIN) {
if (pwm < 0) { // reverse speeds
analogWrite(IN1_PIN, -pwm);
digitalWrite(IN2_PIN, LOW);
} else { // stop or forward
digitalWrite(IN1_PIN, LOW);
analogWrite(IN2_PIN, pwm);
}
}
/// Set the current on the motor.
///
/// \param pwm_A motor A PWM, -255 to 255
void set_motor_current(int pwm_A) {
set_motor_pwm(pwm_A, MOT_A1_PIN, MOT_A2_PIN);
// Print a status message to the console.
Serial.print("Set motor A PWM = ");
Serial.println(pwm_A);
}
/// Simple primitive for the motion sequence to set a speed and wait for an interval.
///
/// \param pwm_A motor A PWM, -255 to 255
/// \param duration delay in milliseconds
void spin_and_wait(int pwm_A, int duration) {
set_motor_current(pwm_A);
delay(duration);
}
6.Oringinal Design and Manufacture Files.¶
6.1 3D Printing Parts¶
6.2 Laser Cutting Parts¶
6.3 Schematic & PCB Design¶
Download my Schematic Design
Download my PCB Design
Download Oringinal Schematic & PCB Files