Forum Controllers/PLC

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

Connect DHT11 or 22 to 20 I/Os Analog HF

Avatar
Javier

I want to connect the DHT11 or 22 to 20 I/Os Analog HF to the module. Is it possible?

Avatar
Discard
2 Answers
0
Avatar
Albert Prieto
Best Answer

Hi,

sure you can use DHT11 sensor using "dht11.h" library on the Ardbox Analog as you would use it to an Individual Arduino board.

see below an example of code:

#include <dht11.h>
#define DHT11PIN 2

dht11 DHT11;

void setup()
{
  Serial.begin(9600);
 
}

void loop()
{
  Serial.println();

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);

  delay(2000);
}

As you can see it is connected at pin 2

So it is necessary to switch the right switch off: 

SDA-D2/I0.0 OFF

There will be an Input lost because of that adjustment.

On the other hand, Each Ardbox Analog has 6 Analog Inputs so If you need 22 to 20 Analog Inputs you could also connect 4 Analog outputs through RS485 (using modbus RTU protocol or another one you want) or you could also use 2x MDuino 58+ which has 16 Analog Inputs each.


1 Comment
Avatar
Discard
Avatar
Javier
-

Hi Albert, thanks for your reply.

Could I use an unblocking library such as the "dht_nonblocking.h" like I do in a normal arduino uno#include

#include <dht_nonblocking.h>

//--------HUMIDITY AND TEMPERATURE SENSOR--------------

#define DHT_Sensor_Pin I0_5

/* Uncomment according to your sensortype. */

#define DHT_SENSOR_TYPE DHT_TYPE_11

//#define DHT_SENSOR_TYPE DHT_TYPE_21

//#define DHT_SENSOR_TYPE DHT_TYPE_22

DHT_nonblocking dht_sensor( DHT_Sensor_Pin, DHT_SENSOR_TYPE );

//Variables

/*

* Poll for a measurement, keeping the state machine alive. Returns

* true if a measurement is available.

*/

static bool measure_environment( float *temperature, float *humidity )

{

static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */

if( millis( ) - measurement_timestamp > 4000ul )

{

if( dht_sensor.measure( temperature, humidity ) == true )

{

measurement_timestamp = millis( );

return( true );

}

}

return( false );

}

void Read_Temp_Humid_DHT_sensor()

{

float temperature;

float humidity;

/* Measure temperature and humidity. If the functions returns

true, then a measurement is available. */

if( measure_environment( &temperature, &humidity ) == true )

{

Room_Temp = int(temperature*100);

Room_Humd = int(humidity*100);

Serial.print("temperatura: ");

Serial.println(Room_Temp);

Serial.print("humedad: ");

Serial.println(Room_Humd);

}

}

void loop() {

Read_Temp_Humid_DHT_sensor();

}

0
Avatar
Javier
Best Answer

Hi Albert, thanks for your reply.

Could I use an unblocking library such as the "dht_nonblocking.h" like I do in a normal arduino uno?

#include <dht_nonblocking.h>

//--------HUMIDITY AND TEMPERATURE SENSOR--------------
#define DHT_Sensor_Pin I0_5

/* Uncomment according to your sensortype. */
#define DHT_SENSOR_TYPE DHT_TYPE_11
//#define DHT_SENSOR_TYPE DHT_TYPE_21
//#define DHT_SENSOR_TYPE DHT_TYPE_22

DHT_nonblocking dht_sensor( DHT_Sensor_Pin, DHT_SENSOR_TYPE );

//Variables
/*
 * Poll for a measurement, keeping the state machine alive.  Returns
 * true if a measurement is available.
 */
static bool measure_environment( float *temperature, float *humidity )
{
  static unsigned long measurement_timestamp = millis( );

  /* Measure once every four seconds. */
  if( millis( ) - measurement_timestamp > 4000ul )
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      measurement_timestamp = millis( );
      return( true );
    }
  }

  return( false );
}



  void Read_Temp_Humid_DHT_sensor()
  {
    float temperature;
    float humidity;
      /* Measure temperature and humidity.  If the functions returns
     true, then a measurement is available. */
      if( measure_environment( &temperature, &humidity ) == true )
      {
            Room_Temp = int(temperature*100);
            Room_Humd = int(humidity*100);
            Serial.print("temperatura: ");
            Serial.println(Room_Temp);
            Serial.print("humedad: ");
            Serial.println(Room_Humd);
      }
  }

void loop() {
Read_Temp_Humid_DHT_sensor();
}


Avatar
Discard