求教如何将传感器读取的数据存入String中
答案:2 悬赏:40 手机版
解决时间 2021-02-01 13:38
- 提问者网友:蓝琪梦莎
- 2021-02-01 03:35
求教如何将传感器读取的数据存入String中
最佳答案
- 五星知识达人网友:底特律间谍
- 2021-02-01 04:46
#define DHT22_PIN 3
uint8_t deg[8] = {0x6,0x9,0x9,0x6};
#define MG_PIN (0)
#define BOOL_PIN (2)
#define DC_GAIN (8.5)
#define READ_SAMPLE_INTERVAL (50)
#define READ_SAMPLE_TIMES (5)
#define ZERO_POINT_VOLTAGE (0.220)
#define REACTION_VOLTGAE (0.020)
#include
#include
#include
#include
LiquidCrystal_I2C lcd(0x27,20,4);
DHT22 myDHT22(DHT22_PIN);
float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))};
String data=" ";
String Co2="";
String Temp="";
String Hem="";
void setup()
{
Serial.begin(9600);
pinMode(BOOL_PIN, INPUT);
digitalWrite(BOOL_PIN, HIGH);
lcd.init();
lcd.backlight();
lcd.createChar(0, deg);
}
void loop()
{ int percentage;
float volts;
volts = MGRead(MG_PIN);
percentage = MGGetPercentage(volts,CO2Curve);
if (percentage == -1) {
String Co2 = "<400" ;
} else {
String Co2 =String(percentage,DEC);
}
DHT22_ERROR_t errorCode;
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{ String Temp = String (myDHT22.getTemperatureC(),DEC);
String Hem = String (myDHT22.getHumidity(),DEC);
}
Serial.println(Co2);
Serial.println(Temp);
Serial.println(Hem);
String Co2="";
String Temp="";
String Hem="";
delay(1000);
}
float MGRead(int mg_pin)
{
int i;
float v=0;
for (i=0;i
v += analogRead(mg_pin);
delay(READ_SAMPLE_INTERVAL);
}
v = (v/READ_SAMPLE_TIMES) *5/1024 ;
return v;
}
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]);
}
}
uint8_t deg[8] = {0x6,0x9,0x9,0x6};
#define MG_PIN (0)
#define BOOL_PIN (2)
#define DC_GAIN (8.5)
#define READ_SAMPLE_INTERVAL (50)
#define READ_SAMPLE_TIMES (5)
#define ZERO_POINT_VOLTAGE (0.220)
#define REACTION_VOLTGAE (0.020)
#include
#include
#include
#include
LiquidCrystal_I2C lcd(0x27,20,4);
DHT22 myDHT22(DHT22_PIN);
float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))};
String data=" ";
String Co2="";
String Temp="";
String Hem="";
void setup()
{
Serial.begin(9600);
pinMode(BOOL_PIN, INPUT);
digitalWrite(BOOL_PIN, HIGH);
lcd.init();
lcd.backlight();
lcd.createChar(0, deg);
}
void loop()
{ int percentage;
float volts;
volts = MGRead(MG_PIN);
percentage = MGGetPercentage(volts,CO2Curve);
if (percentage == -1) {
String Co2 = "<400" ;
} else {
String Co2 =String(percentage,DEC);
}
DHT22_ERROR_t errorCode;
errorCode = myDHT22.readData();
if(errorCode == DHT_ERROR_NONE)
{ String Temp = String (myDHT22.getTemperatureC(),DEC);
String Hem = String (myDHT22.getHumidity(),DEC);
}
Serial.println(Co2);
Serial.println(Temp);
Serial.println(Hem);
String Co2="";
String Temp="";
String Hem="";
delay(1000);
}
float MGRead(int mg_pin)
{
int i;
float v=0;
for (i=0;i
delay(READ_SAMPLE_INTERVAL);
}
v = (v/READ_SAMPLE_TIMES) *5/1024 ;
return v;
}
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]);
}
}
全部回答
- 1楼网友:人類模型
- 2021-02-01 05:46
期待看到有用的回答!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯