Week16 - System Integration
Writing on '2025.5.14'.
The task of the assignment
- Design and document the system integration for your final project
Progress of my Final Project
Lots of progresses are recorded in my page of final project.
The following works are recorded for my final project:
- Cat shelter Modeling and layout
- System Design
- User Interface
Struture of my final project
Here's first struture design of my final project.
In my version 1 design, pressure sensors are used for sensing the weight of food and water to estimate the remaining food and water, and the environment sensing data such as temperature, position, water level in bowl will be transferred to the PC laptop through ESP-NOW protocol.
After studying for networks and interface, I can transfer the sensing data or control the hardware through MQTT protocol. Then I can display the sensing data on the website.
Here's my new structure design of my final project.
I divided the final project in two parts:
- Environment sensing
- Auto Feeder
Cat Shelter Modeling and Layout
Based on the week7 assignment, a cat shelter is milled as parts of my final project.
The auto feeder/water bowl will be placed in inner part of the shelter. The environment sensing part will be placed at the top part of the shleter.
System Design
Here's the material list of my system.
Sensor/Microcontroller | Function | Price | Count | Link |
---|---|---|---|---|
XIAO ESP32C3 | Controllers for getting sensor data | 9.99 | 2 | link |
RYS352A GNSS Antennia | Getting position data | 10.00 | 1 | link |
HX711 load cell sensor | Sensing remain cat food | 6.79 | 1 | link |
WWZMDiB 12 Water level sensor | Sensing remain water | 6.99 | 1 | link |
HC-SR504 Ultrasonic sensor | Detect the cat inside the shelter | 9.99 | 1 | link |
28BYJ-48 Stepper Motor | For activator of auto feeder | 14.59 | 1 | link |
In environment sensing part, BDS Antennia, Ultransonic sensor and temperature sensor are used for sensing the position data, cat is inside the shleter or not, the environment temperature, respectively. The sensing data will be uploaded to my website page through MQTT protocol.
In Auto Feeder part, there are two bowls for food and water. A cell load sensor is used for sensing the weight of remaining food. A water level sensor is used for sensing the water level of remaining water. The auto feeder can feed the food automatically when the weight of food bowl is less than 20% full-weight of food bowl or activate the auto feeder by a button in my website page.
Interface
Environment sensing
The sensing data of environment sensing part is received through MQTT protocol. I can observe the sensing data through MQTTX software.
In this part, 1 HC-SR504 ultrasonic sensor, 1 BDS Antennia and 1 DHT11 Sensor are used for sensing the environment.
In order to tidy up the cables of sensors, a smaller PCB is designed and easier to tidy up the cables.
It's simple design: the pins in left hand side are IO pins, the pins in right hand side are power pins.
It can be used for tidy up the cables, here's a example:
The designed PCB will be inserted into a designed control box. Here's the design in solidworks.
The sensing data of 3 sensors will be transferred through MQTT protocol. I observe the transferred data by MQTTX.
The format of the data sentence is ( temperature cat_state longitude latitude )
.
Environment sensing code
#include "DHT.h"
#include <SoftwareSerial.h>
#include <WiFi.h>
#include <PubSubClient.h>
#define DHTPIN D3
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE); // constructor to declare our sensor
SoftwareSerial MySerial(D2, D1);
int Echo = D4;
int Trig = D5;
int duration=0, distance=0;
bool cat_state = 0;
String NMEA_BD = "";
// Replace the next variables with your SSID/Password combination
const char* ssid = "MSC-Person";
const char* password = "Msc@2333";
// Add your MQTT Broker IP address, example:
//const char* mqtt_server = "192.168.1.144";
const char* mqtt_server = "broker.emqx.io";
WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int value = 0;
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi networka
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(".");
}
randomSeed(micros());
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "XIAO-ESP32-Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
// if (client.connect(clientId.c_str())) {
if (client.connect(clientId.c_str(), "", "")) {
Serial.println("connected");
// Once connected, publish an announcement...
//client.publish("fabacademy/dionTest/Temperature", "hello world");
// ... and resubscribe
client.subscribe("fablab/msc/sensor_series"); //subscribe topic
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
MySerial.begin(9600); //Set 9600 baud rate to get the latitude/longitude information only.
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
dht.begin();
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
}
void loop() {
if(!client.connected()){
reconnect();
}
client.loop();
long now = millis();
if(now - lastMsg > 1000){
lastMsg = now;
digitalWrite(Trig,HIGH);
delayMicroseconds(10);
digitalWrite(Trig,LOW);
duration=pulseIn(Echo,HIGH,4000);
distance=duration*0.0343/2;
if(distance == 0){
cat_state = 0;
}
else if(distance > 0 && distance <= 30){
cat_state = 1;
}
if(MySerial.available()!=0){
NMEA_BD = String(MySerial.readStringUntil('\n'));
}else{
NMEA_BD = "0.0, 0.0";
}
float t = dht.readTemperature();
/*Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" Cat State: ");
Serial.print(cat_state);
Serial.print(" Position Data: ");
Serial.println(NMEA_BD);*/
String output_data = String(t) + " " + String(cat_state) + " " + String(NMEA_BD);
Serial.println(output_data);
client.publish("fablab/msc/sensor_series", output_data.c_str());
}
}
Then, split the data into 4 parts and display on the website.
It may spend lots of time to re-design the UI.