Hi,大家好,这里是丹成学长,今天向大家介绍一个学长做的单片机项目
基于单片机的空气质量分析仪
大家可用于 课程设计 或 毕业设计
单片机-嵌入式毕设选题大全及项目分享:
https://blog.csdn.net/m0_71572576/article/details/125409052
本项目使用了的6个气体传感器,可测量12种气体的气体浓度。
在开始工作之前,应该给传感器供电,让它发热至少24小时。这一步非常重要,因为MQ传感器受到了污染,发热可以帮助它们自我清理。必须用5V给传感器供电然后把它们放在干净的地方。
MQ传感器输出模拟电压,该电压随某些选定气体的浓度而变化。所以可以通过Arduino ADC读取模拟值,得到空气中的气体浓度。
使用6个MQ传感器(MQ3、MQ4、MQ7、MQ8、MQ9和MQ135)。
传感器的用途:
这里主控学长选择的是arduino,你们可以选其他自己熟悉的主控,比如stm32,51等…
将传感器连接到Arduino nano,因为它有8个ADC,6个ADC用于传感器,2个用于I2C与LCD通信。
Arduino与传感器连接:
参考这篇文章:
https://jayconsystems.com/blog/understanding-a-gas-sensor
#include <SPI.h> //Library for SPI interface
#include <Wire.h> //Library for I2C interface
#include <Adafruit_GFX.h> //Core graphic library for displays
#include <Adafruit_SSD1306.h> //Library for OLED display
#define OLED_RESET 11 //Reset pin
Adafruit_SSD1306 display(OLED_RESET); //Set Reset pin for OLED display
int led = 10; //LED pin
int buzzer = 9; //Buzzer pin
int gas_sensor = A0; //Sensor pin
float m = -0.318; //Slope
float b = 1.133; //Y-Intercept
float R0 = 11.820; //Sensor Resistance in fresh air from previous code
void setup() {
Serial.begin(9600); //Baud rate
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Initialize screen
display.setTextColor(WHITE); //Set text color
display.setTextSize(3); //Set text size
pinMode(led, OUTPUT); //Set LED as output
digitalWrite(led, LOW); //Turn LED off
pinMode(buzzer, OUTPUT); //Set buzzer as output
digitalWrite(buzzer, LOW); // Turn buzzer off
pinMode(gas_sensor, INPUT); //Set gas sensor as input
}
void loop() {
display.clearDisplay(); //Clear display
display.setCursor(0,5); //Place cursor in (x,y) location
float sensor_volt; //Define variable for sensor voltage
float RS_gas; //Define variable for sensor resistance
float ratio; //Define variable for ratio
float sensorValue = analogRead(gas_sensor); //Read analog values of sensor
sensor_volt = sensorValue*(5.0/1023.0); //Convert analog values to voltage
RS_gas = ((5.0*10.0)/sensor_volt)-10.0; //Get value of RS in a gas
ratio = RS_gas/R0; // Get ratio RS_gas/RS_air
double ppm_log = (log10(ratio)-b)/m; //Get ppm value in linear scale according to the the ratio value
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
double percentage = ppm/10000; //Convert to percentage
display.print(percentage); //Load screen buffer with percentage value
display.print("%"); //Load screen buffer with "%"
display.display(); //Flush characters to screen
if(ppm>2000){ //Check if ppm value is greater than 2000
digitalWrite(led, HIGH); //Turn LED on
digitalWrite(buzzer, HIGH); //Turn buzzer on } else{ //Case ppm is not greater than 2000 digitalWrite(led, LOW); //Turn LED off digitalWrite(buzzer, LOW); //Turn buzzer off } }
单片机-嵌入式毕设选题大全及项目分享:
https://blog.csdn.net/m0_71572576/article/details/125409052