Temperature humidity sensors comparison (Code configuration) Part 2

Spread the love

First we must connect all this sensors. I use an Arduino UNO to read the values.

BMP280

You can find here AliExpress

For this sensor exist an Adafruit library that you can search and install from Arduino IDE Library Manager

But to use Adafruit Library you must install Adafruit Unified sensor one.

Wiring

bmp280

Than import library and instantiate bme object (I use It with i2c protocol).

// BPM280
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bme; // I2C

On setup start It

  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }

If you receive the error on begin first check the wiring, but probably you must change the address, so install an i2c scanner sketch like this:

#include &lp;Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

And set the address on the old library here:

/*=========================================================================
    I2C ADDRESS/BITS
    -----------------------------------------------------------------------*/
    #define BMP280_ADDRESS                (0x76)
/*========9================================================================*/

as advise by zoomx the new library now support the i2c parameter on begin

bme.begin(0x76)

Now finally we can read the data from bme.

    float t = bme.readTemperature();
    bme280_T = t;
    float p = bme.readPressure();

    float alt = bme.readAltitude(1013.25); // this should be adjusted to your local forcase

    Serial.print("bmp280 --> ");
    Serial.print("Humidity: ");
    Serial.print("     ");
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print("     ");
    Serial.print(" *F\t");
    Serial.print("Pressure: ");
    Serial.print(p);
    Serial.print(" Pa ");
    Serial.print(alt);
    Serial.println(" m");

DHT11 and DHT22

You can find here AliExpress

You can find here AliExpress

This sensor have another Adafruit library.

Wiring.

Install It than include to use the sensors.

// DHT11 and DHT22
#include "DHT.h"

#define DHT22PIN 10     // what digital pin we're connected to
#define DHT11PIN 9      // what digital pin we're connected to

DHT dht22(DHT22PIN, DHT22);
DHT dht11(DHT11PIN, DHT11);

On setup start they

	  dht11.begin();
	  dht22.begin();

Now we can read the data

    float h = dht22.readHumidity();
    dht22_H = h;
    t = dht22.readTemperature();
    dht22_T = t;
    float f = dht22.readTemperature(true);

    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    float hif = dht22.computeHeatIndex(f, h);
    float hic = dht22.computeHeatIndex(t, h, false);

    Serial.print("DHT22  --> ");
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");

    h = dht11.readHumidity();
    dht11_H = h;
    t = dht11.readTemperature();
    dht11_T = t;
    f = dht11.readTemperature(true);

    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    hif = dht11.computeHeatIndex(f, h);
    hic = dht11.computeHeatIndex(t, h, false);

    Serial.print("DHT11  --> ");
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");

DHT12

You can find here DHT12 AliExpress

For this sensor I use my library, you can find It here, and an article here.

Wiring

Install It than include to use the sensors. (I use It with i2c protocol).

// DHT12
#include <DHT12.h>
#define DHT12PIN 8      // what digital pin we're connected to

DHT12 dht12(DHT12PIN, true);

On setup start they

	  dht12.begin();

Now we can read the data

    h = dht12.readHumidity();
    dht12_H = h;
    t = dht12.readTemperature();
    dht12_T = t;
    f = dht12.readTemperature(true);

    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    hif = dht12.computeHeatIndex(f, h);
    hic = dht12.computeHeatIndex(t, h, false);

    Serial.print("DHT12  --> ");
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");

Dallas Temperature ds18b20

You can find here AliExpress

Programmable Resolution 1-Wire Digital Thermometer

Download the library from Library Manager:

Wiring

Than import library and instantiate OneWire and DallalsTemperature object.

// Data wire is plugged into port 11 on the Arduino
#define ONE_WIRE_BUS 11

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address

Than begin with correct address:

  dallas.begin();

  dallas.getAddress(tempDeviceAddress, 0);

Now we can read the data

    // Dallas
    dallas.requestTemperatures(); // Send the command to get temperatures
    t = dallas.getTempC(tempDeviceAddress);
    dallas_T = t;
    f = DallasTemperature::toFahrenheit(t); // Converts tempC to Fahrenheit

    Serial.print("Dallas --> ");
    Serial.print("Humidity: ");
    Serial.print("     ");
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print("    ");
    Serial.print(" *C ");
    Serial.print("    ");
    Serial.println(" *F");

Thermistor

You can find here NTC MF58 3950 B 5% 1% 5K 10K 20K 50K 100K

For thermistor I use my personal library but exists a default library.

Thermistor connection schema
Vcc on thermistor
Vcc on thermistor 
Vcc on resistor
Vcc on resistor

Install It than include to use the sensors.

// Thermistor
#include "Thermistor.h"

// Set pin to A3, using complex formula, adjust resistance to 9900ohom measured with tester, set 10kohom to nominal // of thermistor, 24° nominal thermistor, 3950 thermistor and take 10 analogRead
Thermistor therm(A3, false, 9900, 10000, 24, 3950, 10);

I connect It with VCC on Thermistor.

	  therm.setVccToThermisor(false);

Now you can read the data.

    // Termistor
    t = therm.readTemperature();
	termistor_T = t;
    f = therm.readTemperature(true);

    Serial.print("Termistor> ");
    Serial.print("Humidity: ");
    Serial.print("     ");
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print("    ");
    Serial.print(" *C ");
    Serial.print("    ");
    Serial.println(" *F");

Thanks

In the next part we are going to analize comparison data from this sensors.

  1. Temperature humidity sensors comparison (Specifications)
  2. Temperature humidity sensors comparison (Code configuration)
  3. Temperature humidity sensors comparison (Data)

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *