SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD

Dht11 and soil moisture sensor at once

Someone wanted to know how he can compile sketch of a DHT11 and a soil moisture sensor so that he can monitor humidity, temperature and moisture at the same time.

Well this is the sketch which does all those things at once plus you can control something with humidity, temperature or moisture of the soil.
Ad


The sketch

#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 2
int led1 = 3;
int led2 = 4;
int led3 = 5;

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();

pinMode (led1,OUTPUT);
pinMode (led2,OUTPUT);
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
        Serial.println("OK ");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        Serial.println("Checksum error");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        Serial.println("Time out error");
        break;
    default:
        Serial.println("Unknown error");
        break;
  }
int sensorValue = analogRead(A3);

  Serial.print("Humidity = ");
  Serial.print((float)DHT11.humidity);
  Serial.println(" (%)");

  Serial.print("Temperature = ");
  Serial.print((float)DHT11.temperature);
  Serial.print(" (C) ");
    Serial.println(" ");
   
  Serial.print("Soil Moisture Sensor = ");
  Serial.print(sensorValue);

 if (DHT11.humidity >60){
   digitalWrite (led1, HIGH);
 } else {
      digitalWrite (led1, LOW);
 }

  if (DHT11.temperature >30){
   digitalWrite (led2, HIGH);
 } else {
      digitalWrite (led2, LOW);
 }

if (sensorValue >=500){
    digitalWrite(led3, HIGH);
  }
  else {
    digitalWrite(led3, LOW);
  }
   delay(3000);
}


Pins:
A3 which is analogue pin 3 in the arduino, if you want you can change the pin but make sure you change the pin in the code ( int sensorValue = analogRead(A3); ) as well.

Pin 2 is for DHT11
Pin 3 is for first led which is controlled by humidity.
Pin 4 is for second led which is controlled by temperature.
Pin 5 is for third led which is controlled by soil moisture sensor.

Note:
One thing I've noticed with the soil moisture sensor is that when I connected the vcc with 3v it was getting readings up to 715 but when I connected the vcc to 5v it started getting readings 1000+ so don't really know what going on but it's up to you which ever wire you want to connect with.

Tags:
Dht11 and soil moisture code

You may also like...


DHT22 with sound alert Arduino



Controlling stuff with dht11 Arduino

Ad



No comments:

Post a Comment



Newly posted:
Reason why rich getting richer and poor getting poorer