preface

Eleven one arrived, and it was a little cold. Not only unconsciously winter is coming, haze is coming. It’s important to feel the air for your own health and to know if the current air quality is good enough to exercise outside. PM2.5 as an important indicator of air pollution factors, it can be said that a PM2.5 monitor is a good choice.

So, let’s take a look at taobao and see what price the PM2.5 detector is. You can see 700s, 1000s, 500s, whatever price.

I feel that the price is still a little expensive, can buy an air purifier, so let’s search for PM2.5 sensors.

Focusing only on the PM2.5 sensor, you can see that there are two types of sensor, one is 158, one is 85. I’ve actually used both of these, and they give me similar numbers, but the first one goes down to the last decimal place, and the second one goes down to the whole number.

In fact, it is necessary to be accurate to one decimal point, so it is good to use a second sensor, which means that a PM2.5 sensor costs less than 100 yuan. And PM2.5 sensors are through serial port transmission data, so as long as the collocation of dozens of dollars or a few dollars of accessories can DIY a PM2.5 detector, the cost is more than twice as low!

Here I have three main production schemes in mind.

The plan

Plan 1: computer display

Use USB to TTL serial line to transfer the data to the computer, through the upper computer display.

Material cost:

  • USB to TTL: 5 yuan

  • Freight: 8 yuan

  • Total price: about 113 yuan

Plan two: mobile phone display

The sensor data is forwarded to the phone using Bluetooth and displayed by the phone software.

Material cost:

  • USB to TTL: 5 yuan (for testing the sensor)

  • Bluetooth 4.0 module: 20 yuan

  • Freight: 8 yuan

  • Total price: about 133 yuan

Scheme 3: Display on the screen

Write MCU code, read serial port data, data display on the display screen.

Material cost:

  • USB to TTL: 5 yuan (for testing the sensor)

  • Microcontroller: 16 yuan

  • OLED display: 23 yuan

  • Freight: 8 yuan

  • Total price: about 152 yuan

Hardware preparation

The second option is mainly introduced here. The first scheme requires a computer to use, not convenient, and in the second scheme will also use a computer for testing; And the third program needs to develop single-chip program, a little trouble.

Sensor selection

  • Climbing G5, G7 or G10, between 80 and 105. See individual be fond of here, series is taller, the volume is smaller, the price also can be expensive 10 yuan or so.

  • Climbing G5S, including climbing G5 functions, but also can measure formaldehyde, the price is about 200. If you want to test a formaldehyde, you can buy G5S, but the volume is much larger than G7, G10.

Other accessories

  • USB to TTL, available with CH340, PL2303, CP2102, etc.

  • Bluetooth module: Select CC2541 Bluetooth 4.0 module, common for Android and iOS.

  • Mother to mother Dupont line

  • Power expansion + power cable

Test sensor

The connection of hardware

Here, first test whether the sensor works normally, which requires USB to TTL, the sensor and three DuPont wires. (This is tested on a Windows computer)

VCC and GND are connected to VCC and GND are connected to GND for power supply. The third wire connects the TXD of the sensor to the RXD of USB to TTL. The sensor, as a data producer, needs to send byte data out through the sending end (TXD), and the USB to TTL receives the transmitted data through the receiving end (RXD), and transmits it to the computer through USB.

Once connected, you can plug it into your COMPUTER’s USB port.

Install the driver

After plugging the USB into the computer, open the device manager in the control panel, you can see that there is no serial port device in the port.

We need to download the corresponding drive online (taobao sellers can also find).

Once you have the driver, install it on your computer, reboot it, and open device Manager again. You can see our USB-to-TTL device displayed here.

Test sensor

Next, first download a serial debugging assistant to view the data sent by the sensor, attached with the link: https://raw.githubusercontent.com/nladuo/ElectronicDIY/master/04-PM2.5%E6%A3%80%E6%B5%8B%E4%BB%AA2.0/sscom32.exe.

After opening the serial debugging assistant, select the port you just saw in Device Manager (COM23 in my case), select HEX to display, and finally open the serial port.

If you can successfully see a string of data displayed starting with 424D001C, the sensor is good.

Calculate the current PM2.5 level

First, look at the description of the data.

It can be seen that the first four positions are unchanged, namely 424D001C, and the seventh and eighth positions represent the high and low values of PM2.5 in international standards, while the 13th and 14th positions represent the high and low values of PM2.5 in Chinese standards. The final result is high x256+ low.

(You can see that the current air quality is still good, suitable for outdoor exercise.)

Connect Bluetooth to power supply

After testing, we started to connect bluetooth and power.

Here, both the Bluetooth and sensor modules need power supplies, so a power extension module is required, and four DuPont wires are needed to connect the power supplies respectively. Data transfer is similar to the above. Just connect the TXD end of the sensor to the RXD end of the Bluetooth 4.0 module. All you need is a DuPont wire.

Finally, I take the tape and stick it in place.

Test applet

Download applets

When I was in college, I liked to write an Android APP, and then an iOS APP, and then connect the microcontroller to transfer data for fun. However, as I grew older, my fun-loving heart shrank and I wrote as little as possible.

Feel the emergence of small program is to solve this problem, usually write to play their own things is an APP or too big. Android is ok, it’s open; Apple has to be certified before it’s released, and they have to pay for it every year.

Without further ado, here is the applet code for the applet, which can be installed by clicking on it (I will update the blog if there are any changes).

Code words here will not say, the first time to write a small program. The source code is placed in: https://github.com/nladuo/ElectronicDIY/tree/master/04-PM2.5%E6%A3%80%E6%B5%8B%E4%BB%AA2.0/pm25-%E5%B0%8F%E7%A8%8B%E5%BA %8F

The use of applets

Now we open the small program, here in order to make the interface is not very empty, get the user’s avatar. Then there is the user’s configuration, if you use the Climbing G5S to check the formaldehyde option.

Then, when we plugged in our device, we could see that the bluetooth light was flashing, indicating that the Bluetooth was not paired.

Next, click the Connect Bluetooth device button to enter the scanning device interface, where bluetooth device is selected. (I have changed the name here, and chose BLE_ RGB_LED).

After clicking the device name, wait for a moment, you can see the values of PM2.5 and PM10 normally displayed.

You can see that the PM2.5 value here is one or two hundred, not because the air is not very good, mainly because when WRITING this article, the author’s mother is cooking, made a pile of lampblack, so it becomes like this.

This article is shared here, for continuous attention.