0

我买了这个传感器:

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   "); 


    }



  }
4

2 回答 2

1

您应该始终保持 VCC 引脚(引脚 1)为高电平。事实上,理想情况下,它应该连接到电源。您应该将数据引脚(引脚 2)拉高和拉低以与传感器通信,并且您应该读取数据引脚。您将不得不在输入和输出模式之间切换数据引脚。确保数据引脚上有一个上拉电阻,因为传感器只能将其拉低。

于 2012-08-08T03:08:08.263 回答
0

MaxDetect 1-wire 总线是MaxDetect Technology Co., Ltd. 专门设计的,它不同于Maxim/Dallas 1-wire 总线,因此不兼容Dallas 1-wire 总线。

你可以看看这个:

http://tienda.tdrobotica.co/download/RHT03_programa.pdf

此致。

于 2013-04-25T16:54:27.960 回答