我买了这个传感器:
http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
并且输出是“MaxDetect 1-wire bus”,这是什么意思以及如何使用它?我试图将它连接到 arduino 并对其进行编程,但它无法正常工作,我不断收到 1 位的数据。我想我的代码是错误的。我需要为 arduino 使用 Wire-1 库吗?
int SensorVccPin = 8;
int datapin = 6;
int bitcheck1;
int bitcheck2;
int temp[16];
int humidity[16];
int sensorcheck[8];
void setup()
{
pinMode(SensorVccPin, OUTPUT);
pinMode(datapin, INPUT);
Serial.begin(9600);
}
void loop()
{
// This is the STEP #1
digitalWrite(SensorVccPin, HIGH);
delay(5000);
digitalWrite(SensorVccPin, LOW);
delay(15);
digitalWrite(SensorVccPin, HIGH);
delayMicroseconds(30);
digitalWrite(SensorVccPin, LOW);
while(digitalRead(datapin) == 0){
delayMicroseconds(2); }
while(digitalRead(datapin) == HIGH)
{
delayMicroseconds(2); }
// STEP #2
for (int i = 0; i<16; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{temp[i]=1;
delayMicroseconds(28);
}
else
{temp[i]=0;
}
}
for (int i = 0; i<16; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{humidity[i]=1;
delayMicroseconds(28);
}
else
{humidity[i]=0;
}
}
for (int i = 0; i<8; i++)
{
while(digitalRead(datapin) == LOW)
{
delayMicroseconds(2); }
delayMicroseconds(10);
bitcheck1 = digitalRead(datapin); // maybe store as an array
delayMicroseconds(17); // 50 sec pause // 27us = 0 bit, 70us is 1 bit data
delayMicroseconds(15);
bitcheck2 = digitalRead(datapin);
if (bitcheck1==bitcheck2)
{sensorcheck[i]=1;
delayMicroseconds(28);
}
else
{sensorcheck[i]=0;
}
delayMicroseconds(80);
for(int i=0; i<16; i++)
{
Serial.print(temp[i]);
}
Serial.print(" temp ");
for(int i=0; i<16; i++)
{
Serial.print(humidity[i]);
}
Serial.print(" hum ");
for(int i=0; i<8; i++)
{
Serial.print(sensorcheck[i]);
}
Serial.print(" check ");
}
}