arduino和MG111二氧化碳传感器采集co2
来源:互联网 发布:mac java version 编辑:程序博客网 时间:2024/03/29 23:22
原文地址:http://wiki.dfrobot.com.cn/index.php/(SKU:SEN0159)CO2_二氧化碳传感器模块_V1#.E6.A0.B7.E4.BE.8B.E4.BB.A3.E7.A0.81.E4.BA.8C
(SKU:SEN0159)CO2 二氧化碳传感器模块 V1
目录
[隐藏]- 1 简介
- 2 产品参数
- 3 使用教程
- 3.1 连线图
- 3.2 样例代码一
- 3.3 样例代码二
- 3.4 结果
- 4 疑难解答
简介
温室效应、废气排放、冰川融化、岛国淹没,这一切的罪魁祸首就是CO2的过度排放。是时候家中常备一款CO2监测装置,来知道我们的环境危机是多么的紧迫。它还可以告诉你室内空气的质量,及时开窗降低CO2浓度。DFRobot为您带来这款CO2传感器。CO2浓度越高,输出的电压值就越小。通过我们的说明书和样例代码,用户可以轻松的读取CO2数值。用户还可以用板子上的电位器直接设置阈值,当CO2浓度高达一定程度时,探头旁边的3P针头会输出一个信号(数字量)。
该模块采用工业级的MG-811 CO2探头,对CO2极为敏感,同时还能排除酒精和CO的干扰。该探头对环境温湿度的依赖小,性能稳定,快速恢复响应。模块自带信号放大电路,进一步提高灵敏度。另外,板子上的加热电路直接把5V转换成稳定6V,为探头加热供电,提高模块适应性。
产品参数
- 传感器探头工作电压:6v
- 内置升压电路,支持3.7~5v DC电源输入,电源电流大于500mA
- 兼容蜂鸣器,通过调节板载金属电位器,可快速实现CO2超标蜂鸣器警报功能
- 高品质接头,耐反复插拔
- 沉金工艺,金色质感
- 板子上带有模拟传感图标“A”和明显的电位器标识
- 尺寸:32*42mm
- 模块数据曲线表
使用教程
连线图
注意:使用二氧化传感器时,Arduino必须外接供电(7.5V-9V),否则会造成数据不准确。另外,样例2中需要更改代码,具体看#define 部分Application Related Macros细节说明:电位器用来设置阀值,当设置的阀值小于测得的数值时,数字输出口便输出一个高电平。你可以在数字输出口接蜂鸣器模块或者LED模块用作报警显示。
样例代码一
void setup(){ Serial.begin(9600); } void loop(){ Serial.print("Sample value:"); Serial.println(analogRead(0)); delay(100);}
样例代码二
/*******************Demo for MG-811 Gas Sensor Module V1.1*****************************Author: Tiequan Shao: tiequan.shao@sandboxelectronics.com Peng Wei: peng.wei@sandboxelectronics.com Lisence: Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)Note: This piece of source code is supposed to be used as a demostration ONLY. More sophisticated calibration is required for industrial field application. Sandbox Electronics 2012-05-31************************************************************************************//************************Hardware Related Macros************************************/#define MG_PIN (0) //define which analog input channel you are going to use#define BOOL_PIN (2)#define DC_GAIN (8.5) //define the DC gain of amplifier/***********************Software Related Macros************************************/#define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation#define READ_SAMPLE_TIMES (5) //define the time interval(in milisecond) between each samples in //normal operation/**********************Application Related Macros**********************************///These two values differ from sensor to sensor. user should derermine this value.#define ZERO_POINT_VOLTAGE (0.324) //define the output of the sensor in volts when the concentration of CO2 is 400PPM#define REACTION_VOLTGAE (0.020) //define the voltage drop of the sensor when move the sensor from air into 1000ppm CO2/*****************************Globals***********************************************/float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))}; //two points are taken from the curve. //with these two points, a line is formed which is //"approximately equivalent" to the original curve. //data format:{ x, y, slope}; point1: (lg400, 0.324), point2: (lg4000, 0.280) //slope = ( reaction voltage ) / (log400 –log1000) void setup(){ Serial.begin(9600); //UART setup, baudrate = 9600bps pinMode(BOOL_PIN, INPUT); //set pin to input digitalWrite(BOOL_PIN, HIGH); //turn on pullup resistors Serial.print("MG-811 Demostration\n"); }void loop(){ int percentage; float volts; volts = MGRead(MG_PIN); Serial.print( "SEN0159:" ); Serial.print(volts); Serial.print( "V " ); percentage = MGGetPercentage(volts,CO2Curve); Serial.print("CO2:"); if (percentage == -1) { Serial.print( "<400" ); } else { Serial.print(percentage); } Serial.print( "ppm" ); Serial.print( " Time point:" ); Serial.print(millis()); Serial.print("\n"); if (digitalRead(BOOL_PIN) ){ Serial.print( "=====BOOL is HIGH======" ); } else { Serial.print( "=====BOOL is LOW======" ); } Serial.print("\n"); delay(200);}/***************************** MGRead *********************************************Input: mg_pin - analog channelOutput: output of SEN0159Remarks: This function reads the output of SEN0159************************************************************************************/ float MGRead(int mg_pin){ int i; float v=0; for (i=0;i<READ_SAMPLE_TIMES;i++) { v += analogRead(mg_pin); delay(READ_SAMPLE_INTERVAL); } v = (v/READ_SAMPLE_TIMES) *5/1024 ; return v; }/***************************** MQGetPercentage **********************************Input: volts - SEN-000007 output measured in volts pcurve - pointer to the curve of the target gasOutput: ppm of the target gasRemarks: By using the slope and a point of the line. The x(logarithmic value of ppm) of the line could be derived if y(MG-811 output) is provided. As it is a logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic value.************************************************************************************/ int MGGetPercentage(float volts, float *pcurve){ if ((volts/DC_GAIN )>=ZERO_POINT_VOLTAGE) { return -1; } else { return pow(10, ((volts/DC_GAIN)-pcurve[1])/pcurve[2]+pcurve[0]); }}
结果
打开串口监视器,大约五分钟后,你会得到你周围二氧化碳浓度的数据。
0 0
- arduino和MG111二氧化碳传感器采集co2
- 我要为二氧化碳(CO2)申冤
- Arduino 中多传感器数据采集的写法
- CM106-05红外二氧化碳传感器的应用
- Arduino 和 雨滴传感器 滴水实验
- Arduino Uno 和 DHT11/DHT22 温湿度传感器
- 弧焊 不同气体对焊缝的影响 100二氧化碳 15%氩气CO2混合
- Arduino 和 AM3201(DHT21)温湿度传感器 应用
- Arduino 和 MQ-135 空气污染气体传感器 实验
- arduino与传感器
- Arduino - DHT11温湿度传感器
- arduino DHT11 温湿度传感器
- Arduino使用“按键传感器”
- Arduino使用光线传感器
- Arduino使用水位传感器
- Arduino使用土壤湿度传感器
- Arduino的传感器使用教程1:PM2.5、温度和大气压传感器
- 003用LabVIEW和Arduino开发一个温度采集系统
- 树梅派应用6:树莓派下编译RTL8723BU无线蓝牙网卡
- 糗事百科
- C语言中关键字const
- Thread中的interrupt(),interrupted(),isInterrupted()方法的详解
- Reflux helloworld
- arduino和MG111二氧化碳传感器采集co2
- 通过预设在nvram里的数据实现lcm兼容的方案
- 学生管理系统
- 基于欧几里德距离的K最近邻(KNN)算法的实现(JAVA版)
- 问题 A: C语言习题 计算该日在本年中是第几天
- 贝叶斯网络(笔记)
- 新浪微博接口清单
- 树梅派应用7:用树莓派DIY一台专门拍Gif动图的相机
- java实现定时关机