Home ArduinoArduino Code Arduino three in one sensor module example

Arduino three in one sensor module example

I like connecting sensors to my Arduino boards, recently I noticed the following module which combined the following 3 sensors in one easy to use module, all of the sensors are I2C so minimal connections from the module to your arduino are required

The HTU21D is a low-cost, easy to use, highly accurate, digital humidity and temperature sensor.
The BMP180 is the new digital barometric pressure sensor of Bosch Sensortec.
BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface.

Here is a picture of the module

CJMCU-HTU21D + BMP180 + BH1750FVI module

CJMCU-HTU21D + BMP180 + BH1750FVI module

 

Now lets take a look at some code examples, you will need a few libraries for the sensors

https://github.com/arduinolearning/Arduino-Libraries/blob/master/BH1750-master.zip

https://github.com/misenso/SHT2x-Arduino-Library

https://github.com/adafruit/Adafruit-BMP085-Library

 

Code

This is an example for the BH1750FVI Ambient Light Sensor

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup(){
Serial.begin(9600);
lightMeter.begin();
Serial.println(“Running…”);
}
void loop() {
uint16_t lux = lightMeter.readLightLevel();
Serial.print(“Light: “);
Serial.print(lux);
Serial.println(” lx”);
delay(1000);
}
[/codesyntax]

 

This is an example for the BMP180 barometric pressure sensor

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;

void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println(“Could not find a valid BMP085 sensor, check wiring!”);
while (1) {}
}
}

void loop() {
Serial.print(“Temperature = “);
Serial.print(bmp.readTemperature());
Serial.println(” *C”);

Serial.print(“Pressure = “);
Serial.print(bmp.readPressure());
Serial.println(” Pa”);

Serial.print(“Altitude = “);
Serial.print(bmp.readAltitude());
Serial.println(” meters”);

Serial.print(“Pressure at sealevel (calculated) = “);
Serial.print(bmp.readSealevelPressure());
Serial.println(” Pa”);

Serial.print(“Real altitude = “);
Serial.print(bmp.readAltitude(101500));
Serial.println(” meters”);

Serial.println();
delay(500);
}
[/codesyntax]

 

Finally here is an example for the HTU21D digital humidity and temperature sensor

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <SHT2x.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}

void loop()
{
Serial.print(“Humidity(%RH): “);
Serial.print(SHT2x.GetHumidity());
Serial.print(” Temperature(C): “);
Serial.println(SHT2x.GetTemperature());

delay(1000);
}
[/codesyntax]

 

 

Links

HTU21D+BMP180+BH1750FVI temperature and humidity pressure light sensor three in one

You may also like