Forum Controladores/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
Descartar
2 Respuestas
0
<div> <h5 class="o_wforum_bio_popover_name mb-0"> <address class="mb-0" itemscope="itemscope" itemtype="http://schema.org/Organization"> <div> <span itemprop="name">Albert Prieto</span> <span><img src=https://www.industrialshields.com/es_ES/forum/forum-controladores-plc-17/question/"/web/image/res.country/68/image/España?unique=a14a800%22 class="img img-fluid country_flag" alt="España"/></span> </div> <div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress"> </div> <div> </div> </address> </h5> <span class="o_wforum_bio_popover_info"> <address class="mb-0" itemscope="itemscope" itemtype="http://schema.org/Organization"> <div class="css_non_editable_mode_hidden"> --<span class="text-muted">Albert Prieto</span>-- </div> <div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress"> </div> <div> <div class="css_editable_mode_hidden"> <div class="mb-2"> <br/> </div> <b class="mt-4"><i class="fa fa-diamond text-secondary"></i> 1000000029</b> <div style="display: inline-block"> <b>|</b> <span class="fa fa-trophy badge-gold ml-2" role="img" aria-label="Gold badge" title="Gold badge"></span> 0 <span class="fa fa-trophy badge-silver ml-2" role="img" aria-label="Silver badge" title="Silver badge"></span> 0 <span class="fa fa-trophy badge-bronze ml-2" role="img" aria-label="Bronze badge" title="Bronze badge"></span> 0 </div> <div class="mt-2"> <div class="o_forum_tooltip_line"> <span>asd</span><span>, </span><span>España</span> </div> </div> </div> </div> </address> </span> <div class="o_wforum_bio_popover_bio"> <address class="mb-0" itemscope="itemscope" itemtype="http://schema.org/Organization"> <div class="css_non_editable_mode_hidden"> --<span class="text-muted">Albert Prieto</span>-- </div> <div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress"> </div> <div> <span> </span> </div> </address> </div> </div> </div> "> 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 Comentario
Avatar
Descartar
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
Descartar