Monday 12 August 2013

Arduino: DHT11 humidity sensor, HC-SR04 ultrasonic distance sensor


In this project two new sensors (DHT11 and HC-SR04) are used with arduino. In the Arduino programming loop following code is used:


//DHT11
float DHT11_humidity = 0.0;
float DHT11_temperature = 0.0;

int chk = DHT11.read(DHT11PIN);


if(chk == 0)//if chk is zero it works properly
{
     DHT11_humidity = (float)DHT11.humidity;
     DHT11_temperature = (float)DHT11.temperature;
}


lcd.setCursor(0, 0);
lcd.print("H%:");
lcd.print(DHT11_humidity);
lcd.print(" TC:");
lcd.print(DHT11_temperature);


//HC-SR04
long duration, distance; 


digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW); 


duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1; 

if (distance >= 400 || distance <= 2)
{
   lcd.print(" Dcm: NA");
   lcd.print(" ");

else
{
   lcd.print(" Dcm: ");
  lcd.print(distance);
  lcd.print(" ");
}


DHT11 Humidity & Temperature Sensor

The DHT11 is a basic, digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). DHT11 specifications are:
  • Power supply: 3.0 to 5.5V DC
  • Output signal: digital signal via single-bus
  • Operating range: humidity 20 to 90%RH, temperature 0 to 50℃
  • Interchangeability: fully interchangeable
  • Range of meauring humidity: 20 to 90%RH(050temperature compensation
  • Range of meauring temperature: 0 to +50℃
  • Accuracy of measuring humidity: ±5.0%RH
  • Accuracy of measuring temperature: ±2.0℃
  • Response time: <5s 


HC-SR04 Ultrasonic Distance Sensor
Ultrasonic ranging module HC-SR04 provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work:

(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back.
(3) IF the signal back, through high level , time of high output IO duration is the time from sending ultrasonic to returning.

16x2 LCD displays DHT11 measured humidity as % and temperature in degrees centigrade. Light value is mapped to between 0 and 255. Distance in cm measured by HC-SR04.

The arduino pins are as follows:
//Arduino pins used for LCD
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

//Arduino pin for DHT11
#define DHT11PIN 13

//Arduino pins for HC-SR04
#define trigPin 9
#define echoPin 2

//Arduino pin for photocell
int photocellPin = A0;

//Arduino pins used for LED RGB
const int red = 3;
const int green = 8;
const int blue = 10;

I also suggest you to read Professional Android Sensor Programming.

No comments:

Post a Comment