Project finished product image:

Bilibili video link:
https://www.bilibili.com/video/BV1sPDVYLEpW/?share_source=copy_web&vd_source=097fdeaf6b6ecfed8a9ff7119c32faf2
(For material sharing, see the end of the article)
01
—
Project Introduction
1. Function Details
STM32 Intelligent Water Quality Detection System
The functions are as follows:
-
The main control chip is the STM32 microcontroller;
2. DS18B20 temperature sensor measures water temperature
3. TDS conductivity sensor measures the conductivity of water
4. PH sensor detects the acidity and alkalinity of water
5. Turbidity sensor measures the turbidity of water
6. OLED display shows the current water temperature, conductivity, turbidity, and pH value in real-time
7. Buttons can set thresholds, triggering a buzzer alarm when exceeded
8. Under abnormal alarm conditions, a relay can be controlled to execute operations
9. Connect to the Gizwits cloud platform, allowing remote viewing of water quality data via the Gizwits mobile app
10. The mobile app displays information and completes control
2. Bill of Materials
-
STM32F103C8T6 microcontroller
-
OLED screen
-
DS18B20 digital temperature sensor
-
TDS conductivity sensor
-
PH sensor
-
Turbidity sensor
-
Relay
-
Buzzer
02
—
Schematic Design

03
—
PCB Hardware Design
PCB Diagram


04
—
Program Design
#include "main.h"// All header files are included for easy management and calling
#define turbidity_K 2047.19// Function declaration
void Key_Init(void);// Key function declaration
void display(void);
u8 b_1s, eer_f, smart_config;
u8 mod=0;// Display mode
short set_f; // Primary directory number, set data bit marker
u32 begin_code[21] = {0, 30, 500, 4, 10, 500, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66};// Backup array
set_code[19] verification bit
u32 set_code[21];// Set parameters
char str[32];// Display buffer
short beep_io_flag; // Buzzer flag
u32 set_code[21];// Parameter storage array
u8 run_mod;// Working mode
float PH, PH_temp;// PH variable
u16 temperature;// Temperature storage variable
float TDS_DAT;
float temperature_temp; // Temporary variable for temperature storage
float turbidity, turbidity_temp;// PH value and turbidity value storage variable
float T;
short set_f; // Primary directory number, set data bit marker
int main(void){
u8 i;
DelayInit();// System delay function initialization
DelayMs(500);
usart2_init(9600);// Serial port 2 initialization
ADC1_DMA_Config();
Gizwits_Init();// Gizwits initialization
Key_Init();// Key pin initialization
TIM2_Int_Init(10000, 3600);// Output timer, using timer 2 as the 0.5-second interrupt source
TIM_Cmd(TIM2, ENABLE);// Enable timer 2
OLED_Init();// OLED screen initialization
OLED_CLS();// Clear screen
OLED_ShowCC(0, 0, "====LOADING====");// Display title
mod = 0;// Boot display boot interface
DS18B20_Init();// Initialize temperature and humidity sensor
DelayMs(100);
Readflash(set_code, 0, 20); // Read internal saved data
DelayMs(10);
if(set_code[19] != 66)// Compare if internal data has been overwritten
{
OLED_ShowStr(0, 0, "===NO FLASH===", 2);
Writeflash(0, begin_code, 0, 20);// Write initialization data
DelayMs(500);
Readflash(set_code, 0, 20);// Read written data
sprintf(str, "Init System [%2d]", set_code[19]);// Display verification data
OLED_ShowStr(0, 4, (unsigned char *)str, 2);
DelayMs(100);
OLED_CLS();// Clear screen
}
gizwitsHandle((dataPoint_t *)&currentDataPoint);// Gizwits protocol processing
gizwitsSetMode(WIFI_AIRLINK_MODE);// Connect in WIFI_AIRLINK_MODE
DelayMs(1000);
userInit();
OLED_CLS();// Clear screen
while (1)
{
PH = (float)ADCConvertedValue[1]; // PH corresponding AD value
PH = PH * (3.3/4096) * 2;// PH data processing
PH = PH * (-5.7541) + 16.654; // PH data processing
if(PH > 14.0) PH = 14.0;
if(PH < 0) PH = 0.0;
PH_temp = PH ;// Assign to temporary variable
turbidity = (float)ADCConvertedValue[0]*3.3/4096;// Turbidity corresponding AD value, data processing
turbidity = turbidity_K - turbidity*865.68; // Data conversion
turbidity = turbidity - 200;// Data conversion
if(turbidity < 35) turbidity = 0; // Turbidity less than 0 equals 0
turbidity_temp = turbidity;// Assign to temporary variable
TDS_DAT = (ADCConvertedValue[2]/4095.0)*3.3;
TDS_DAT = 66.71*TDS_DAT*TDS_DAT*TDS_DAT-127.93*TDS_DAT*TDS_DAT+428.7*TDS_DAT;
if(TDS_DAT < 20) TDS_DAT = 0;
temperature = DS18B20_Get_Temp();// Read temperature and humidity
temperature_temp = (float)temperature/10;// Assign to temporary variable
display();// Display program
key();// Key program
if(mod==0) run();// Logic control
userHandle(); // User data collection
gizwitsHandle((dataPoint_t *)&currentDataPoint);// Gizwits protocol processing
}
}
05
—
Experimental Results


Material Sharing (Baidu Cloud)
https://pan.baidu.com/s/1_ryza528-IJxOIwjxS8oXA?pwd=vmca Extraction code: vmca
(Or scan the QR code below to obtain)
For physical purchase, scan the QR code below