Course design of wireless transmission, design of water quality monitoring system based on ZigBee

foreword

The course design report, IAR file and C# host computer are at the end of the article.


1. Design content and requirements

        ZigBee is divided into a coordinator and a terminal. The terminal sends the data collected by the sensor to the coordinator, and the coordinator sends the data to the host computer. The host computer displays the data in real time to achieve the purpose of monitoring water quality.

2. System hardware design

  • The transmission node is CC2530, one as a coordinator and two as terminals
  • DS18B20 (temperature sensor): used to measure the temperature of water body

  • TSW-30 (turbidity sensor): used to measure water turbidity

2.1 CC2530

 Figure 2-1 CC2530 pin diagram

2.2   DS18B20

Figure 2-2 DS18B20 hardware wiring diagram

pin name

Function

GND

ground wire

DQ

Single-bus communication interface, power supply port in parasitic mode

VDD

Power line (grounded during 2-wire communication to ensure correct identification of VDD state in the chip)

Table 2-1 DS18B20 pin description

        DS18B20 temperature reading function code segment, digital reading

void Temp_test(void) //温度读取函数  
{  
  uint8 V1,V2;  
   
  Ds18b20Initial();  
  Ds18b20Write(0xcc);  
  Ds18b20Write(0x44);  
    
  Ds18b20Initial();  
  Ds18b20Write(0xcc);  
  Ds18b20Write(0xbe);  
    
  V1 = Ds18b20Read();  
  V2 = Ds18b20Read();  
  temp = ((V1 >> 4)+((V2 & 0x07)*16));    
} 

2.3 TSW-30

pin definition

Functional description

Remark

VCC

Positive power supply voltage, 5V

3.3V not available

TO THE

Analog signal output

Output voltage range 0-5V

DO

digital output

If it is less than the set value, output high level; if it is greater than the set value, output low level

GND

Negative pole of supply voltage

Table 2-2 TSW-30 pin description

        TSW-30 temperature reading function code segment, analog reading

uint16 ReadData( void )  
{  
  uint16 reading = 0;  
    
  P0DIR &= ~0x20;  // 设置P0.5为输入方式  
    
  //asm("NOP");asm("NOP");  
    
  /* Clear ADC interrupt flag */  
  ADCIF = 0;  
    
  ADCCON3 = (0x20 | HAL_ADC_DEC_064 | HAL_ADC_CHANNEL_5);  
    
  /* Wait for the conversion to finish */  
  while ( !ADCIF );  
    
  asm("NOP");asm("NOP");  
    
  /* Read the result */  
  reading = ADCL;  
  reading |= (int16) (ADCH << 8);  
  reading >>= 8;  
    
  return reading;  
} 

3. System software design

3.1 System Flow Diagram

Figure 3-1 System flow chart

4.2 Host computer programming

4.2.1 Cutting data

        Since the data receiving time of different terminal nodes cannot be fully synchronized, the source of the data cannot be accurately distinguished. Therefore, the flag bit is used. When the terminal sends data, the flag bits '/c' and '/d' are added immediately after the data, by This can determine the source of the data.

        Cut the data by combining the flag bits '/c' and '/d' of the sent data, see line 14 of the following code segment for details, and separate the desired data bits.

4.2.2 Display data

Different data is obtained according to different flag bits, and the data obtained by separation is displayed specifically. For details, see lines 15-42 of the following code segment.

        private void SerialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                string data = string.Empty;

                this.Invoke((EventHandler)(delegate
                {
                    data = serialPort1.ReadExisting();

                    byte[] decBytes = System.Text.Encoding.Default.GetBytes(data);
                    string str1 = System.Text.Encoding.Default.GetString(decBytes);

                    string[] info = data.Split('/');
                    try
                    {
                        for (int i = 0; i < info.Length; i++)
                        {

                            if (info[i] == "c")
                            {
                                //浊度
                                float f1 = Convert.ToSingle(info[i + 1]);
                                label6.Text = Convert.ToString((int)f1 * 50 / 127);
                                chart1.Series["浊度"].Points.AddXY(zdx++, (int)f1 * 50 / 127);
                                if (zdx > 20)
                                    chart1.Series["浊度"].Points.Clear();
                                this.listBox1.Items.Add(Time_Count.Text + "," + "浊度," + Convert.ToString((int)f1 * 50 / 127));

                            }
                            else if (info[i] == "d")
                            {
                                //温度
                                float f1 = Convert.ToSingle(info[i + 1]);
                                label7.Text = Convert.ToString(f1);
                                chart1.Series["温度"].Points.AddXY(wdx++, f1);
                                if (wdx > 20)
                                    chart1.Series["浊度"].Points.Clear();
                                this.listBox2.Items.Add(Time_Count.Text + "," + "温度," + Convert.ToString(f1));
                            }
                        }
                    }
                    catch
                    {

                    }
                })
                );
            }
            catch (Exception ex)
            {
                //响铃并显示异常给用户
                System.Media.SystemSounds.Beep.Play();
                MessageBox.Show(ex.Message);
            }
        }

appendix 

Baidu network disk , extraction code: tv6a

Guess you like

Origin blog.csdn.net/qq_21891843/article/details/124446316