34 Arduino Sensor Projects
34 Arduino Sensor Projects
By Iain Hendry
Contents Overview
Arduino Basics
Sensor 1 – BMP180
Sensor 2 – DS18B20
Sensor 3 – DHT11
Sensor 4 – PIR Detector
Sensor 5 – HC-SR04 Ultrasonic Sensor
Sensor 6 – HDC1008
Sensor 7 – mcp9808
Sensor 8 – mlx90614
Sensor 9 – BME280
Sensor 10 – TSL2561
Sensor 11 –SHT21
Sensor 12 – ML8511
Sensor 13 – SHT31
Sensor 14 – MAG3110
Sensor 15 – TCS34725
Sensor 16 – MLX90393
Sensor 17 – DS1624
Sensor 18 – SI7021
Sensor 19 – HDC1080
Sensor 20 – BMP280
Sensor 21 – DHT12
Sensor 22 – AM2320
Sensor 23 – LM75
Sensor 24 – OPT3001
Sensor 25 – TMP175
Sensor 26 – MPL3115A2
Sensor 27 – CCS811
Sensor 28 – MAX30100
Sensor 29 – MLX90615
Sensor 30 – Si1145
Sensor 31 – TMP102
Sensor 32 – HMC5983
Sensor 33 – MAX44009
Sensor 34 – MMA8451
Overview
In this book we look at various sensors that can be
connected to an Arduino, we will have a description which is
usually pulled from the manufacturer’s website and some
specifications or features. Some people like reading this, it’s
a basic introduction and overview of the sensor.
We will have the parts that we used for the example, mainly
these will consist of an Arduino, a module and some
connecting wire. We prefer not to use breadboards and most
of the sensors can be tricky to work with unless you can a
module, we also use an Arduino sensor shield – this can
make it slightly easier to connect to a module as it uses
female to female wiring rather than male to female,
sometimes the male wires can come out of the Arduino
headers.
We will have schematics or a layout or even a connection
table for each sensor showing how to connect it to an
Arduino, generally most sensors are very easy to connect,
for example an I2C sensor tends to be the supply voltage
pins and the SDA and SCL pins, so only 4 connections
required.
All the code is in the eBook and will also be available from a
github repo, I always feel that code can be a pain to read in
an eBook or an app. Sometimes it’s better to be able to view
it online and save it to your development PC.
We generally look for libraries that do a lot of the work for
you but in some cases we will show examples that do not – if
you have the time then it is always recommended that you
look at the code in a library to see how it works and what the
developer is doing. One day you may need to fix a bug, add
your own feature or even write your own library for a sensor
as one does not already exist.
We are assuming that the people who are using this eBook
know how to get and install the Arduino IDE, install a library
and have a bit of basic usage of the IDE but we have
included a basic chapter if you need it at the start.
Code and schematics that are available have been uploaded
to
https://github.com/getelectronics
/arduino-sensor-ebook
Arduino Basics
Arduino download
Visit https://www.arduino.cc/en/Main/Software to download
the Arduino IDE
Get the latest version from the download page. You can
choose between the Installer (.exe) and the Zip packages.
We suggest you use the first one that installs directly
everything you need to use the Arduino Software (IDE),
including the drivers. With the Zip package you need to
install the drivers manually. The Zip file is also useful if you
want to create a portable installation.
When the download finishes, proceed with the installation
and please allow the driver installation process when you get
a warning from the operating system.
Choose the components to install Choose the installation
directory (we suggest to keep the default one) The process
will extract and install all the required files to execute
properly the Arduino Software (IDE)
Install a library
Using the Library Manager To install a new library into
your Arduino IDE you can use the Library Manager (available
from IDE version 1.6.2). Open the IDE and click to the
"Sketch" menu and then Include Library > Manage Libraries.
Then the Library Manager will open and you will find a list of
libraries that are already installed or ready for installation. In
this example we will install the Bridge library. Scroll the list to
find it, click on it, then select the version of the library you
want to install. Sometimes only one version of the library is
available. If the version selection menu does not appear,
don't worry: it is normal.
Finally click on install and wait for the IDE to install the new
library. Downloading may take time depending on your
connection speed. Once it has finished, an Installed tag
should appear next to the Bridge library. You can close the
library manager.
You can now find the new library available in the Sketch >
Include Library menu. If you want to add your own library to
Library Manager, follow these instructions.
Importing a .zip Library Libraries are often distributed as
a ZIP file or folder. The name of the folder is the name of the
library. Inside the folder will be a .cpp file, a .h file and often
a keywords.txt file, examples folder, and other files required
by the library. Starting with version 1.0.5, you can install 3rd
party libraries in the IDE. Do not unzip the downloaded
library, leave it as is.
In the Arduino IDE, navigate to Sketch > Include Library >
Add .ZIP Library. At the top of the drop down list, select the
option to "Add .ZIP Library''.
Parts List
Name Quantity
Arduino Uno 1
BMP180 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup()
{
Serial.begin(9600);
if (!bmp.begin())
{
Serial.println("BMP180 sensor not found");
while (1) {}
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print("Altitude = ");
Serial.print(bmp.readAltitude(101500));
Serial.println(" meters");
Serial.println();
delay(1000);
}
Output
Datasheet : https://ae-
bst.resource.bosch.com/media/_tech/media/datasheets/BST-
BMP180-DS000.pdf
Sensor 2 – DS18B20
Description
The DS18B20 digital thermometer from Maxim provides 9-bit
to 12-bit Celsius temperature measurements and has an
alarm function with nonvolatile user-programmable upper
and lower trigger points. The DS18B20 communicates over a
1-Wire bus that by definition requires only one data line (and
ground) for communication with a central microprocessor. In
addition, the DS18B20 can derive power directly from the
data line ("parasite power"), eliminating the need for an
external power supply.
Each DS18B20 has a unique 64-bit serial code, which allows
multiple DS18B20s to function on the same 1-Wire bus. Thus,
it is simple to use one microprocessor to control many
DS18B20s distributed over a large area. Applications that
can benefit from this feature include HVAC environmental
controls, temperature monitoring systems inside buildings,
equipment, or machinery, and process monitoring and
control systems.
Name Quantity
Arduino Uno 1
DS18b20 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
http://download.milesburton.com/Arduino/MaximTemp
erature/DallasTemperature_372Beta.zip
http://www.pjrc.com/teensy/arduino_libraries/OneWire.
zip #include <OneWire.h>
#include <DallasTemperature.h>
OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);
void setup()
{
Serial.begin(9600);
delay(1000);
//start reading
sensors.begin();
}
void loop()
{
//read temperature and output via serial
sensors.requestTemperatures();
Serial.print(sensors.getTempCByIndex(0));
Serial.println(” degrees C”);
}
Output
Open the serial monitor this is what you should see
References
Datasheet -
https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
Sensor 3 – DHT11
Description
DHT11 digital temperature and humidity sensor is a
composite Sensor contains a calibrated digital signal output
of the temperature and humidity. Application of a dedicated
digital modules collection technology and the temperature
and humidity sensing technology, to ensure that the product
has high reliability and excellent long-term stability. The
sensor includes a resistive sense of wet components and an
NTC temperature measurement devices, and connected with
a high-performance 8-bit microcontroller.
Relative humidity
Resolution: 16Bit
Repeatability: ±1% RH
Accuracy: At 25 ℃ ±5% RH
Temperature
Resolution: 16Bit
Repeatability: ±0.2
Electrical Characteristics
Power supply: DC 3.5 ~ 5.5V
Supply Current: measurement 0.3mA standby 60μ A
Sampling period: more than 2 seconds
Name Quantity
Arduino Uno 1
DHT11 module 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
dht11 DHT;
//Pin 4 of Arduino to Data of DHT11
#define DHT11_PIN 4
void setup()
{
Serial.begin(9600);
int check;
Serial.print(“DHT11 STATUS – \t”);
check = DHT.read(DHT11_PIN);
//check status
switch (check)
{
case DHTLIB_OK:
Serial.print(“OK\n”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print(“Checksum error\n”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print(“Timeout error\n”);
break;
default:
Serial.print(“Unknown error\n”);
break;
}
}
void loop()
{
delay(1000);
}
Output
open the Serial Monitor window
References
Sensor 4 – PIR Detector
Description
The PIR sensor stands for Passive Infrared sensor. It is a low
cost sensor which can detect the presence of Human beings
or animals. This sensor has three output pins Vcc, Output
and Ground as shown in the pin diagram above.
The module can be powered from voltage 4.5V to 20V but
because we are using an Arduino Uno 5V is used. Once the
module is powered allow the module to calibrate itself for
few minutes, 2 minutes is a well settled time. Then observe
the output on the output pin. Before we analyse the output
we need to know that there are two operating modes in this
sensor such as Repeatable(H) and Non- Repeatable(L) and
mode. The Repeatable mode is the default mode.
The output of the sensor can be set by shorting any two pins
on the left of the module as shown below. You can also notice
two orange colour potentiometers that can be used to set
the sensitivity and time.
Parts List
Name Quantity
Arduino Uno 1
HCSR01 PIR module 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = digitalRead(pirPin);
//low = no motion, high = motion
if (val == LOW)
{
Serial.println(“No motion”);
}
else
{
Serial.println(“Motion detected – ALARM”);
}
delay(1000);
}
Output
References
Sensor 5 – HC-SR04 Ultrasonic Sensor
Description
Ultrasonic ranging module HC - SR04 provides 2cm - 400cm
non-contact measurement function, the ranging accuracy
can reach to 3mm. The modules includes ultrasonic
transmitters, receiver and control circuit. The basic principle
of work: (1) Using IO trigger for at least 10us high level
signal, (2) The Module automatically sends eight 40 kHz and
detect whether there is a pulse signal back.
(3) IF the signal back, through high level , time of high
output IO duration is the time from sending ultrasonic to
returning. Test distance = (high level time×velocity of sound
(340M/S) / 2
Working Voltage DC 5 V
Working Current 15mA
Working Frequency 40Hz
Max Range 4m
Min Range 2cm
Measuring Angle 15 degrees
module
Parts List
Name Quantity
Arduino Uno 1
HC-SR04 detector 1
Connecting wire 1
Schematics/Layout/Connection
void setup()
{
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
Serial.println(distance);
//Delay 50ms before next reading.
delay(50);
}
Output
If you open the serial monitor window you should see the
distance to an object displayed
References
Sensor 6 – HDC1008
Description
The HDC1008 is a digital humidity sensor with integrated
temperature sensor that provides excellent measurement
accuracy at very low power. The device measures humidity
based on a novel capacitive sensor. The humidity and
temperature sensors are factory calibrated. The innovative
WLCSP (Wafer Level Chip Scale Package) simplifies board
design with the use of an ultra-compact package. The
sensing element of the HDC1008 is placed on the bottom
part of the device, which makes the HDC1008 more robust
against dirt, dust, and other environmental contaminants.
The HDC1008 is functional within the full –40°C to +125°C
temperature range.
Parts List
Name Quantity
Arduino UNO 1
HDC1008 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
The good folks at Adafruit have done the hard work and
produced a library for this device -
https://github.com/adafruit/Adafruit_HDC1000_Library .
#include <Wire.h>
#include "Adafruit_HDC1000.h"
if (!hdc.begin())
{
Serial.println("Couldn't find sensor!");
while (1);
}
}
void loop()
{
Serial.print("Temp: "); Serial.print(hdc.readTemperature());
Serial.print("\t\tHum: "); Serial.println(hdc.readHumidity());
delay(500);
}
Output
Open the serial monitor and you should see the readings
from the module
References
Datasheet - http://www.ti.com/lit/gpn/hdc1008
Sensor 7 – mcp9808
Description
The MCP9808 digital temperature sensor converts
temperatures between -20°C and +100°C to a digital word
with ±0.5°C (max.) accuracy. The MCP9808 comes with user-
programmable registers that provide flexibility for
temperature sensing applications. The registers allow user-
selectable settings such as Shutdown or low-power modes
and the specification of temperature Event and Critical
output boundaries. When the temperature changes beyond
the specified boundary limits, the MCP9808 outputs an Event
signal. The user has the option of setting the event output
signal polarity as an active-low or active-high comparator
output for thermostat operation, or as temperature event
interrupt output for microprocessor-based systems. The
event output can also be configured as a Critical
temperature output. This sensor has an industry standard 2-
wire, SMBus and Standard I2C™Compatible compatible
(100kHz/400kHz bus clock) serial interface, allowing up to
eight sensors to be controlled in a single serial bus. These
features make the MCP9808 ideal for sophisticated multi-
zone temperature- monitoring applications.
Name Quantity
Arduino Uno 1
MCP9808 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
if (!tempsensor.begin())
{
Serial.println("Couldn't find MCP9808!");
while (1);
}
}
void loop() {
// Read and print out the temperature, then convert to *F
float c = tempsensor.readTempC();
float f = c * 9.0 / 5.0 + 32;
Serial.print("Temp: ");
Serial.print(c);
Serial.print(" C\t");
Serial.print(f);
Serial.println(" F");
delay(250);
tempsensor.shutdown_wake(1);
delay(2000);
tempsensor.shutdown_wake(0);
}
Output
Open the serial monitor and you should see something like
this Temp: 21.69 C 71.04 F
Temp: 21.62 C 70.93 F
Temp: 24.50 C 76.10 F
Temp: 25.06 C 77.11 F
Temp: 25.37 C 77.68 F
Temp: 25.56 C 78.01 F
Temp: 24.25 C 75.65 F
Temp: 23.87 C 74.97 F
References
Sensor 8 – mlx90614
Description
The MLX90614 is an infrared thermometer for non-contact
temperature measurements. Both the IR sensitive thermopile
detector chip and the signal conditioning ASIC are integrated
in the same TO-39 can. Integrated into the MLX90614 are a
low noise amplifier, 17-bit ADC and powerful DSP unit thus
achieving high accuracy and resolution of the thermometer.
The thermometer comes factory calibrated with a digital
SMBus output giving full access to the measured
temperature in the complete temperature range(s) with a
resolution of 0.02°C.
The user can configure the digital output to be pulse width
modulation (PWM). As a standard, the 10-bit PWM is
configured to continuously transmit the measured
temperature in range of -20 to 120°C, with an output
resolution of 0.14°C.
Factory calibrated in wide temperature range: -40 to 125°C
for sensor temperature and -70 to 380°C for object
temperature High accuracy of 0.5°C over wide temperature
range (0..+50 C for both Ta and To) Measurement resolution
of 0.02°C
SMBus compatible digital interface for fast temperature
readings and building sensor networks Customizable PWM
output for continuous reading Available in 3V and 5V
versions
Power saving mode
Name Quantity
Arduino Uno 1
MLX90614 (GY-906) 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
void setup()
{
Serial.begin(9600);
mlx.begin();
}
void loop()
{
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("*C\tObject = ");
Serial.print(mlx.readObjectTempC());
Serial.println("*C");
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempF());
Serial.print("*F\tObject = ");
Serial.print(mlx.readObjectTempF());
Serial.println("*F");
Serial.println();
delay(500);
}
Output
You will see values every 500 milliseconds via the serial
monitor
References
Datasheet -
https://www.melexis.com/-/media/files/documents/datasheet
s/mlx90614-datasheet-melexis.pdf
Sensor 9 – BME280
Description
The BME280 is an integrated environmental sensor
developed specifically for mobile applications where size and
low power consumption are key design constraints. The unit
combines individual high linearity, high accuracy sensors for
pressure, humidity and temperature in an 8-pin metal-lid 2.5
x 2.5 x 0.93 mm³ LGA package, designed for low current
consumption (3.6 μA @1Hz), long term stability and high
EMC robustness.
The humidity sensor features an extremely fast response
time which supports performance requirements for emerging
applications such as context awareness, and high accuracy
over a wide temperature range. The pressure sensor is an
absolute barometric pressure sensor with features
exceptionally high accuracy and resolution at very low noise.
The integrated temperature sensor has been optimized for
very low noise and high resolution. It is primarily used for
temperature compensation of the pressure and humidity
sensors, and can also be used for estimating ambient
temperature.
The BME280 supports a full suite of operating modes which
provides the flexibility to optimize the device for power
consumption, resolution and filter performance.
Operation range (full accuracy)
Pressure: 300...1100 hPa
Temperature: -40…85°C
Supply voltage VDD 1.71 ... 3.6 V
Interface I²C and SPI
I used the following module
Parts List
Name Quantity
Arduino Uno 1
BME280 1
Connecting wire 1
Schematics/Layout/Connection
You can use this module in either SPI or I2C modes, in this
case we went for SPI mode, here is the wiring for our module
to our arduino Uno Connect Vin to 5V.
Connect GND to ground
Connect the SCK pin to Digital #13
Connect the SDO pin to Digital #12
Connect the SDI pin to Digital #11
Connect the CS pin Digital #10
Code Examples
void setup()
{
Serial.begin(57600);
//SPI
mySensor.settings.commInterface = SPI_MODE;
mySensor.settings.chipSelectPin = 10;
//Operation settings
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
mySensor.settings.tempOverSample = 1;
mySensor.settings.pressOverSample = 1;
mySensor.settings.humidOverSample = 1;
void loop()
{
//Each loop, take a reading.
Serial.print("Temperature: ");
Serial.print(mySensor.readTempC(), 2);
Serial.println(" degrees C");
Serial.print("Temperature: ");
Serial.print(mySensor.readTempF(), 2);
Serial.println(" degrees F");
Serial.print("Pressure: ");
Serial.print(mySensor.readFloatPressure(), 2);
Serial.println(" Pa");
Serial.print("Altitude: ");
Serial.print(mySensor.readFloatAltitudeMeters(), 2);
Serial.println("m");
Serial.print("Altitude: ");
Serial.print(mySensor.readFloatAltitudeFeet(), 2);
Serial.println("ft");
Serial.print("%RH: ");
Serial.print(mySensor.readFloatHumidity(), 2);
Serial.println(" %");
Serial.println();
delay(1000);
Output
All going well if you open your serial monitor window you
should see something like this
Temperature: 22.55 degrees C
Temperature: 72.61 degrees F
Pressure: 100637.00 Pa
Altitude: 59.39m
Altitude: 194.01ft
%RH: 0.00 %
References
Datasheet - https://ae-
bst.resource.bosch.com/media/_tech/media/datasheets/BST-
BME280-DS002.pdf
Sensor 10 – TSL2561
Description
The TSL2561 is a light-to-digital converter that transforms
light intensity to a digital signal output capable of an I2C
interface. Each device combines one broadband photodiode
(visible plus infrared) and one infrared-responding
photodiode on a single CMOS integrated circuit capable of
providing a near photopic response over an effective 20-bit
dynamic range (16-bit resolution).
Two integrating ADCs convert the photodiode currents to a
digital output that represents the irradiance measured on
each channel. This digital output can be input to a
microprocessor where illuminance (ambient light level) in lux
is derived using an empirical formula to approximate the
human eye response. The TSL2561 device supports a
traditional level style interrupt that remains asserted until
the firmware clears it.
Name Quantity
Arduino Uno 1
TSL2561 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
We use the Adafruit TS2561 library - this is a cut down
version of the default -
https://github.com/adafruit/Adafruit_TSL2561
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
void configureSensor(void)
{
tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x
and 16x */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low
resolution */
}
void setup(void)
{
Serial.begin(9600);
Serial.println("Light Sensor Test");
Serial.println("");
configureSensor();
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
Output
Parts List
Name Quantity
Arduino Uno 1
SHT21 1
Connecting wire 1
Schematics/Layout/Connection
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Serial.print("Humidity: ");
Serial.println(SHT2x.GetHumidity());
Serial.print("Temperature(C): ");
Serial.println(SHT2x.GetTemperature());
Serial.println();
delay(1000);
}
Output
When you open the serial monitor you should see the
temperature and humidity displayed
References
Sensor 12 – ML8511
Description
The ML8511 is a UV sensor, which is suitable for acquiring
UV intensity indoors or outdoors. The ML8511 is equipped
with an internal amplifier, which converts photo-current to
voltage depending on the UV intensity.
This unique feature offers an easy interface to external
circuits such as ADC. In the power down mode, typical
standby current is 0.1uA, thus enabling a longer battery life.
FEATURES
• Photodiode sensitive to UV-A and UV-B
• Embedded operational amplifier
• Analog voltage output
• Low supply current (300uA typ.) and low standby current
(0.1uA typ.) • Small and thin surface mount package (4.0mm
x 3.7mm x 0.73mm, 12-pin
This sensor detects 280-390nm light the best. This is
categorized as part of the UVB spectrum (burning) and most
of the UVA spectrum (tanning). It outputs an analog voltage
that is linearly related to the measured UV intensity
(mW/cm2). With the aid of an analog to digital signal
conversion then you can detect UV levels.
Parts List
Name Quantity
Arduino Uno 1
ML8511 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
void setup()
{
pinMode(UVsensorIn, INPUT);
Serial.begin(9600); //open serial port, set the baud rate to 9600 bps
}
void loop()
{
int uvLevel = averageAnalogRead(UVsensorIn);
return(runningValue);
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Output
You should see values in the serial monitor window – adjust
the light on the sensor to see the values change
References
Sensor 13 – SHT31
Description
The new digital SHT3x humidity sensor series takes sensor
technology to a new level. As the successor of the SHT2x
series it is determined to set the next industry standard in
humidity sensing. The SHT3x humidity sensor series consists
of a low-cost version with the SHT30 humidity sensor, a
standard version with the SHT31 humidity sensor, and a
high-end version with the SHT35 humidity sensor. The SHT3x
humidity sensor series combines multiple functions and
various interfaces (I2C, analog voltage output) with a
applications-friendly, very wide operating voltage range
(2.15 to 5.5 V). The SHT3x humidity sensor is available in
both large and small volumes.
The SHT3x builds on a completely new and optimized
CMOSens® chip, which allows for increased reliability and
improved accuracy specifications. The SHT3x offers a range
of new features, such as enhanced signal processing, two
distinctive and user-selectable I2C addresses, an alert mode
with programmable humidity and temperature limits, and
communication speeds of up to 1 MHz Output I²C, Voltage
Out Supply voltage range 2.15 to 5.5 V
Energy consumption 4.8µW (at 2.4 V, low repeatability, 1
measurement / s) RH operating range 0 - 100% RH
T operating range -40 to +125°C (-40 to +257°F) RH
response time 8 sec (tau63%)
I bought and used the following module
Parts List
Name Quantity
Arduino Uno 1
SHT31 (SHT3x) 1
Connecting Wire 1
Schematics/Layout/Connection
If you’re using an Arduino simply make the following
connections VIN pin to the 5V voltage pin,
GND to ground,
SCL to I2C Clock (Analog 5)
SDA to I2C Data (Analog 4).
Like this
Code Examples
void setup()
{
Serial.begin(9600);
if (! sht31.begin(0x44))
{
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
}
void loop()
{
float t = sht31.readTemperature();
float h = sht31.readHumidity();
if (! isnan(t))
{
Serial.print("Temp *C = "); Serial.println(t);
}
else
{
Serial.println("Failed to read temperature");
}
if (! isnan(h))
{
Serial.print("Hum. % = "); Serial.println(h);
}
else
{
Serial.println("Failed to read humidity");
}
Serial.println();
delay(1000);
}
Output
References
Sensor 14 – MAG3110
Description
Overview The MAG3110 is a small, low-power digital 3D
magnetic sensor with a wide dynamic range to allow
operation in PCBs with high extraneous magnetic fields. The
MAG3110: Measures the components of the local magnetic
field, the sum of the geomagnetic field and the magnetic
field created by components on the circuit board Can be
used in conjunction with a 3-axis accelerometer so that
orientation-independent accurate compass heading
information may be achieved Features a standard I²C serial
interface and can measure local magnetic fields up to 10
Gauss with output data rates up to 80 Hz Features 80 Hz
maximum sampling rate
I²C interface 400 kHz
-40°C to +85°C operation
0.95 to 3.6-volt supply
Full-scale range ±1000 µT
Low-power, single-shot measurement mode
Noise down to 0.25 µT rms
Sensitivity of 0.10 µµT
Parts List
Name Quantity
Arduino Uno 1
MAG3110 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#include <Wire.h>
#define MAG_ADDR 0x0E //7-bit address for the MAG3110, doesn't change
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
config(); // turn the MAG3110 on
}
void loop()
{
print_values();
delay(5);
}
void config(void)
{
Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E
Wire.write(0x11); // cntrl register2
Wire.write(0x80); // write 0x80, enable auto resets
Wire.endTransmission(); // stop transmitting
delay(15);
Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E
Wire.write(0x10); // cntrl register1
Wire.write(1); // write 0x01, active mode
Wire.endTransmission(); // stop transmitting
}
void print_values(void)
{
Serial.print("x=");
Serial.print(read_x());
Serial.print(",");
Serial.print("y=");
Serial.print(read_y());
Serial.print(",");
Serial.print("z=");
Serial.println(read_z());
}
return reg_val;
}
int read_x(void)
{
return mag_read_value(0x01, 0x02);
}
int read_y(void)
{
return mag_read_value(0x03, 0x04);
}
int read_z(void)
{
return mag_read_value(0x05, 0x06);
}
Output
Open up the serial monitor x=44,y=1138,z=1505
x=65175,y=580,z=2037
x=65117,y=745,z=1435
x=65145,y=1487,z=1814
x=64700,y=949,z=1912
x=64848,y=671,z=1921
x=65411,y=803,z=2218
x=64852,y=720,z=1644
References
Datasheet - https://www.nxp.com/docs/en/data-
sheet/MAG3110.pdf
Sensor 15 – TCS34725
Description
The TCS3472 device provides a digital return of red, green,
blue (RGB), and clear light sensing values. An IR blocking
filter, integrated on-chip and localized to the color sensing
photodiodes, minimizes the IR spectral component of the
incoming light and allows color measurements to be made
accurately. The high sensitivity, wide dynamic range, and IR
blocking filter make the TCS3472 an ideal color sensor
solution for use under varying lighting conditions and
through attenuating materials. This data is transferred via an
I2C to the host.
Features Integrated IR blocking filter
3.8M:1 dynamic range
Four independent analog-to-digital converters A reference
channel for color analysis (clear channel photodiode)
Benefits Minimizes IR and UV spectral component effects to
produce accurate color measurement Enables accurate color
and ambient light sensing under varying lighting conditions
Minimizes motion/transient errors
Clear channel provides a reference which allows for isolation
of color content
Product parameters Supply Voltage [V] 2.7 - 3.6
Interface VDD
Color Sensor Channels RGBC
IR Blocking Filter Yes Temperature Range [°C] -40 to 85
Name Quantity
Arduino Uno 1
TCS34725 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
We will use the adafruit library -
https://github.com/adafruit/Adafruit_TCS34725 This is one of
the default examples #include <Wire.h>
#include "Adafruit_TCS34725.h"
void setup(void) {
Serial.begin(9600);
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
References
Sensor 16 – MLX90393
Description
The MLX90393 is a magnetic field sensor designed for
micropower applications, with programmable duty cycles in
the range of 0.1% to 100%.
The MLX90393 magnetic field sensor can be reprogrammed
to different modes and with different settings at run-time.
The sensor offers a 16-bit output proportional to the
magnetic flux density sensed along the XYZ axes using the
Melexis proprietary Triaxis® technology and also offers a
temperature output signal. These digital values are available
via I2C and SPI, where the MLX90393 is a slave on the bus.
By selecting which axes are to be measured, the raw data
can be used as input for further post-processing, such as for
joystick applications, rotary knobs, and more complex 3D
position sensing applications. Unparallelled performance is
achieved with this sensor, which is primarily targeting
industrial and consumer applications.
Name Quantity
Arduino Uno 1
MLX90393 (JCMCU-90393) 1
Connecting wire 1
Schematics/Layout/Connection
Module Arduino
VDD 3v3
Gnd Gnd
SDA A4
SCL A5
Code Examples
void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select Write register command
Wire.write(0x60);
// Set AH = 0x00, BIST disabled
Wire.write(0x00);
// Set AL = 0x5C, Hall plate spinning rate = DEFAULT, GAIN_SEL = 5
Wire.write(0x5C);
// Select address register, (0x00 << 2)
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
void loop()
{
unsigned int data[7];
Output
Open the serial monitor and you should see something like
this Magnetic Field in X-Axis : 66
Magnetic Field in Y-Axis : 65458
Magnetic Field in Z-Axis : 8
Magnetic Field in X-Axis : 83
Magnetic Field in Y-Axis : 65477
Magnetic Field in Z-Axis : 65525
Magnetic Field in X-Axis : 76
Magnetic Field in Y-Axis : 65452
Magnetic Field in Z-Axis : 65506
Magnetic Field in X-Axis : 25
Magnetic Field in Y-Axis : 65374
Magnetic Field in Z-Axis : 65512
Magnetic Field in X-Axis : 80
References
Sensor 17 – DS1624
Description
Name Quantity
Arduino Uno 1
DS1624 (CJMCU-1624) 1
Connecting wire 1
Schematics/Layout/Connection
Module Arduino
VDD 5v
Gnd Gnd
SDA SDA - A4
SCL SCL - A5
Code Examples
void setup()
{
// Begin serial connection at 9600 baud
Serial.begin(9600);
}
void loop()
{
float temperature;
bool valid;
// Print it
Serial.println(temperature);
// Wait a while
delay(1000);
}
Output
Open the serial monitor and you should see the following
24.31
24.31
24.87
25.94
26.44
27.06
27.37
27.81
27.81
27.69
References
Datasheet -
https://datasheets.maximintegrated.com/en/ds/DS1624.pdf
Sensor 18 – SI7021
Description
The Si7021 I2C Humidity and Temperature Sensor is a
monolithic CMOS IC integrating humidity and temperature
sensor elements, an analog-to-digital converter, signal
processing, calibration data, and an I2C Interface. The
patented use of industry-standard, low-K polymeric
dielectrics for sensing humidity enables the construction of
low-power, monolithic CMOS Sensor ICs with low drift and
hysteresis, and excellent long-term stability.
The humidity and temperature sensors are factory-
calibrated, and the calibration data is stored in the on-chip
non-volatile memory. This ensures that the sensors are fully
interchangeable, with no recalibration or software changes
required.
Operating Voltage: 1.9 - 3.6V (recommend 3.3V) Standby
Current: 60nA
Temperature Range: -40 - 85 ℃ (recommend -10 - 60 ℃ )
Temperature Accuracy: ±0.4 ℃ (-10 - 85 ℃ ) Humidity
Range: 0-100%RH (recommend 20% - 80%RH) Humidity
Accuracy: ±3%RH (0-80%RH)
Temperature Conversion Time: 7ms
Humidity Conversion Time: 17ms (RH measurement will
automatically initiate a temperature measurement)
This is the module that I used
Parts List
Name Quantity
Arduino Uno 1
Si7021 1
Connecting wire 1
Schematics/Layout/Connection
#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
delay(100);
Wire.beginTransmission(ADDR);
Wire.endTransmission();
}
void loop()
{
/**Send command of initiating temperature measurement**/
Wire.beginTransmission(ADDR);
Wire.write(0xE3);
Wire.endTransmission();
Serial.print("Temp");
Serial.print("\t");
Serial.println("Humidity");
if(Wire.available()<=2);
{
X0 = Wire.read();
X1 = Wire.read();
X0 = X0<<8;
X_out = X0+X1;
}
Serial.println();
delay(1000);
Output
Open the serial monitor, you should see something like this
Temp Humidity
23.12C 52.83%
Temp Humidity
24.04C 53.13%
Temp Humidity
26.28C 53.83%
Temp Humidity
27.42C 54.57%
References
Sensor 19 – HDC1080
Description
The HDC1080 is a digital humidity sensor with integrated
temperature sensor that provides excellent measurement
accuracy at very low power. The HDC1080 operates over a
wide supply range, and is a low cost, low power alternative
to competitive solutions in a wide range of common
applications. The humidity and temperature sensors are
factory calibrated.
Features
Relative Humidity Accuracy ±2% (typical)
Temperature Accuracy ±0.2°C (typical)
14 Bit Measurement Resolution
100 nA Sleep Mode Current
Average Supply Current:
710 nA @ 1sps, 11 bit RH Measurement
1.3 µA @ 1sps, 11 bit RH and Temperature Measurement
Supply Voltage 2.7 V to 5.5 V
I2C Interface
Parts List
Name Quantity
Arduino Uno 1
HDC1080 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
ClosedCube_HDC1080 hdc1080;
void setup()
{
Serial.begin(9600);
Serial.println("ClosedCube HDC1080 Arduino Test");
// Default settings:
// - Heater off
// - 14 bit Temperature and Humidity Measurement Resolutions
hdc1080.begin(0x40);
Serial.print("Manufacturer ID=0x");
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas
Instruments
Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
printSerialNumber();
void loop()
{
Serial.print("T=");
Serial.print(hdc1080.readTemperature());
Serial.print("C, RH=");
Serial.print(hdc1080.readHumidity());
Serial.println("%");
delay(3000);
}
void printSerialNumber() {
Serial.print("Device Serial Number=");
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
char format[12];
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid,
sernum.serialLast);
Serial.println(format);
}
Output
Open the serial monitor window and you should expect to
see something like this T=21.75C, RH=28.00%
T=21.60C, RH=28.21%
T=25.36C, RH=32.17%
T=27.87C, RH=43.27%
T=27.42C, RH=40.23%
T=26.90C, RH=32.15%
References
Sensor 20 – BMP280
Description
BMP280 is an absolute barometric pressure sensor especially
designed for mobile applications. The sensor module is
housed in an extremely compact package. Its small
dimensions and its low power consumption allow for the
implementation in battery powered devices such as mobile
phones, GPS modules or watches.
As its predecessor BMP180, BMP280 is based on Bosch’s
proven Piezo-resistive pressure sensor technology featuring
high accuracy and linearity as well as long term stability and
high EMC robustness. Numerous device operation options
offer highest flexibility to optimize the device regarding
power consumption, resolution and filter performance. A
tested set of default settings for example use case is
provided to the developer in order to make design-in as easy
as possible.
Operation range (full accuracy) Pressure: 300...1100 hPa
Temperature: -40…85°C
Absolute accuracy (Temp. @ 0…+65°C) ~ ±1 hPa Average
current consumption (1 Hz data refresh rate) 2.74 μA, typical
(ultra-low power mode) Average current consumption in
sleep mode 0.1 μA Average measurement time 5.5 msec
Supply voltage VDD 1.71 ... 3.6 V
Name Quantity
Arduino Uno 1
BMP280 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
if (!bme.begin()) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" Pa");
Serial.println();
delay(2000);
}
Output
Open the serial monitor and you should see readings like this
Temperature = 27.65 *C
Pressure = 100592.44 Pa
Approx altitude = 61.17 m
Temperature = 28.72 *C
Pressure = 100589.25 Pa
Approx altitude = 61.44 m
Temperature = 29.31 *C
Pressure = 100590.25 Pa
Approx altitude = 61.35 m
References
Datasheet - https://ae-
bst.resource.bosch.com/media/_tech/media/datasheets/BST-
BMP280-DS001.pdf
Sensor 21 – DHT12
Description
The DHT12 is an I2C version of the DHT11 sensor that we
looked at earlier - the following is from the datasheet DHT12
Digital temperature and humidity sensor is a calibrated
digital output record of temperature and humidity.
Application-specific digital temperature and humidity sensor
module and semiconductor ensure high reliability and
excellent long-term stability. DHT12 with a single bus, and
standards I2C Two kinds of communication and single bus
communication mode is fully compatible with DHT11 。
Standard bus interface makes it simple and quick to system
integration. With super small size, low power consumption,
suitable for a wide variety of applications.I2C Communication
uses standard communication sequence, the user can
directly I2C Communication on the bus, no additional wiring,
simple to use. Two-way switch, users are free to choose, easy
to use, should be a broad range of areas. Products for the 4
Lead, convenient connection, provides special packages
according to user needs.
Fully interchangeable, low cost, long term stability, relative
humidity and temperature measurement, signal transmission
of long distance, digital output, precise calibration, power
consumption is very low, the standard single-wire digital
interface, the standard I2C Bus digital interface,
communication can be freely chosen.
This is the module I selected
Parts List
Name Quantity
Arduino Uno 1
DHT12 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#include <DHT12.h>
void setup()
{
Serial.begin(112560);
// Start sensor handshake
dht12.begin();
}
int timeSinceLastRead = 0;
void loop()
{
// Report every 2 seconds.
if(timeSinceLastRead > 2000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Read temperature as Celsius (the default)
float t12 = dht12.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f12 = dht12.readTemperature(true);
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h12 = dht12.readHumidity();
dht12Read = false;
}
if (dht12Read){
// Compute heat index in Fahrenheit (the default)
float hif12 = dht12.computeHeatIndex(f12, h12);
// Compute heat index in Celsius (isFahreheit = false)
float hic12 = dht12.computeHeatIndex(t12, h12, false);
// Compute dew point in Fahrenheit (the default)
float dpf12 = dht12.dewPoint(f12, h12);
// Compute dew point in Celsius (isFahreheit = false)
float dpc12 = dht12.dewPoint(t12, h12, false);
Output
Open the serial monitor DHT12=> Humidity: 33.70 %
Temperature: 20.20 *C 68.36 *F Heat index: 19.16 *C 66.48
*F Dew point: 3.60 *C 38.48 *F
DHT12=> Humidity: 39.70 % Temperature: 20.60 *C 69.08
*F Heat index: 19.75 *C 67.55 *F Dew point: 6.34 *C 43.41 *F
DHT12=> Humidity: 44.60 % Temperature: 21.20 *C 70.16
*F Heat index: 20.54 *C 68.97 *F Dew point: 8.64 *C 47.55 *F
DHT12=> Humidity: 47.80 % Temperature: 21.80 *C 71.24
*F Heat index: 21.28 *C 70.31 *F Dew point: 10.25 *C 50.45
*F
DHT12=> Humidity: 48.90 % Temperature: 22.40 *C 72.32
*F Heat index: 21.97 *C 71.55 *F Dew point: 11.16 *C 52.08
*F
References
Sensor 22 – AM2320
Description
Temperature and humidity combined sensor AM2320 digital
temperature and humidity sensor is a digital signal output
has been calibrated. Using special temperature and humidity
acquisition technology, ensure that the product has a very
high reliability and excellent long-term stability.
Sensor consists of a capacitive moisture element and an
integrated high-precision temperature measurement devices
and connected with a high-performance microprocessor.
The product has excellent quality, super-fast response,
strong anti-interference ability, very high property price rate.
Name Quantity
Arduino Uno 1
AM2320 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
AM2320 th;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
Serial.println("Chip = AM2320");
switch(th.Read()) {
case 2:
Serial.println(" CRC failed");
break;
case 1:
Serial.println(" Sensor offline");
break;
case 0:
Serial.print(" Humidity = ");
Serial.print(th.Humidity);
Serial.println("%");
Serial.print(" Temperature = ");
Serial.print(th.cTemp);
Serial.println("*C");
Serial.println();
break;
}
delay(2000);
}
Output
Open the serial monitor
Chip = AM2320
Humidity = 47.10%
Temperature = 24.80*C
Chip = AM2320
Humidity = 48.70%
Temperature = 25.10*C
References
Sensor 23 – LM75
Description
The LM75A is an industry-standard digital temperature
sensor with an integrated sigma-delta analog-to-digital
converter (ADC) and I2C interface. The LM75A provides 9-bit
digital temperature readings with an accuracy of ±2°C from
–25°C to 100°C and ±3°C over –55°C to 125°C.
The LM75A operates with a single supply from 2.7 V to 5.5 V.
Communication is accomplished over a 2-wire interface
which operates up to 400 kHz. The LM75A has three address
pins, allowing up to eight LM75A devices to operate on the
same 2-wire bus. The LM75A has a dedicated
overtemperature output (O.S.) with programmable limit and
hysteresis. This output has programmable fault tolerance,
which lets the user to define the number of consecutive error
conditions that must occur before O.S. is activated. The wide
temperature and supply range and I2C interface make the
LM75A ideal for a number of applications including base
stations, electronic test equipment, office electronics,
personal computers, and any other system in which thermal
management is critical to performance. The LM75A is
available in an SOIC-8 package and an VSSOP-8 package.
Features Shutdown Mode to Minimize Power Consumption
Up to Eight LM75As can be Connected to a Single Bus Power
up Defaults Permit Stand-Alone Operation as Thermostat
Supply Voltage : 2.7 V to 5.5 V
Supply Current
Operating: 280 µA (Typical)
Shutdown: 4 µA (Typical)
Temperature Accuracy
25°C to 100°C: ±2°C (Max)
55°C to 125°C: ±3°C (Max)
This was the module that I used
Parts List
Name Quantity
Arduino Uno 1
LM75 module (open-smart0 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#include <inttypes.h>
#include <Wire.h>
#include <lm75.h>
void setup()
{
Serial.begin(9600);
Serial.println("Start");
Serial.print("Actual temp ");
Serial.print(termo.getTemp());
Serial.println(" oC");
delay(2000);
}
void loop()
{
Serial.print(termo.getTemp());
Serial.println(" oC");
delay(5000);
}
Output
You should see temperature readings via the serial monitor
window
References
Datasheet - http://www.ti.com/lit/ds/symlink/lm75a.pdf
Sensor 24 – OPT3001
Description
The OPT3001 is a sensor that measures the intensity of
visible light. The spectral response of the sensor tightly
matches the photopic response of the human eye and
includes significant infrared rejection.
The OPT3001 is a single-chip lux meter, measuring the
intensity of light as visible by the human eye. The precision
spectral response and strong IR rejection of the device
enables the OPT3001 to accurately meter the intensity of
light as seen by the human eye regardless of light source.
The strong IR rejection also aids in maintaining high
accuracy when industrial design calls for mounting the
sensor under dark glass for aesthetics. The OPT3001 is
designed for systems that create light-based experiences for
humans, and an ideal preferred replacement for
photodiodes, photoresistors, or other ambient light sensors
with less human eye matching and IR rejection.
Measurements can be made from 0.01 lux up to 83k lux
without manually selecting full-scale ranges by using the
built-in, full-scale setting feature. This capability allows light
measurement over a 23-bit effective dynamic range.
The digital operation is flexible for system integration.
Measurements can be either continuous or single-shot. The
control and interrupt system features autonomous operation,
allowing the processor to sleep while the sensor searches for
appropriate wake-up events to report via the interrupt pin.
The digital output is reported over an I2C- and SMBus-
compatible, two-wire serial interface.
The low power consumption and low power-supply voltage
capability of the OPT3001 enhance the battery life of
battery-powered systems.
Features
Precision Optical Filtering to Match Human Eye: Rejects >
99% (typ) of IR
Automatic Full-Scale Setting Feature Simplifies Software and
Ensures Proper Configuration Measurements: 0.01 lux to 83 k
lux Low Operating Current: 1.8 µA(typ)
Operating Temperature Range: –40°C to +85°C
Wide Power-Supply Range: 1.6 V to 3.6 V
5.5-V Tolerant I/O
Parts List
Name Quantity
Arduino Uno 1
OPT3001 1
Connecting wire 1
Schematics/Layout/Connection
Arduino CJMCU-3001
5v Vcc
Gnd Gnd
SDA SDA
SCL SCL
Code Examples
This is example for ClosedCube OPT3001 Digital Ambient Light Sensor breakout
board
MIT License
*/
#include <Wire.h>
#include <ClosedCube_OPT3001.h>
ClosedCube_OPT3001 opt3001;
void setup()
{
Serial.begin(9600);
Serial.println("ClosedCube OPT3001 Arduino Test");
opt3001.begin(OPT3001_ADDRESS);
Serial.print("OPT3001 Manufacturer ID");
Serial.println(opt3001.readManufacturerID());
Serial.print("OPT3001 Device ID");
Serial.println(opt3001.readDeviceID());
configureSensor();
printResult("High-Limit", opt3001.readHighLimit());
printResult("Low-Limit", opt3001.readLowLimit());
Serial.println("----");
}
void loop()
{
OPT3001 result = opt3001.readResult();
printResult("OPT3001", result);
delay(500);
}
void configureSensor() {
OPT3001_Config newConfig;
newConfig.RangeNumber = B1100;
newConfig.ConvertionTime = B0;
newConfig.Latch = B1;
newConfig.ModeOfConversionOperation = B11;
Serial.println("------------------------------");
}
Parts List
Name Quantity
Arduino Uno 1
TMP175 1
Connecting wire 1
Schematics/Layout/Connection
#include <Wire.h>
void Cal_Temp();
/*******************************************************************************
Setup
*******************************************************************************/
void setup()
{
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
delay(1000);
}
/*******************************************************************************
Main Loop
*******************************************************************************/
void loop()
{
const int I2C_address = 0x37; // I2C write address
delay(100);
Wire.beginTransmission(I2C_address);
Wire.write(1); // Setup configuration register
Wire.write(0x60); // 12-bit
Wire.endTransmission();
Wire.beginTransmission(I2C_address);
Wire.write(0); // Setup Pointer Register to 0
Wire.endTransmission();
while (1)
{
delay(1000);
// Display temperature
Serial.print("The temperature is ");
if (P_N == 0)
Serial.print("-");
Serial.print(TempHi,DEC);
Serial.print(".");
Serial.print(Decimal,DEC);
Serial.println(" degree C");
}
}
void Cal_Temp()
{
if (TempHi&0x80) // If bit7 of the TempHi is HIGH then the temperature is negative
P_N = 0;
else // Else the temperature is positive
P_N = 1;
Output
You should see something like this via the serial monitor The
temperature is 22.8125 degree C
The temperature is 22.8125 degree C
The temperature is 23.5625 degree C
The temperature is 23.6875 degree C
The temperature is 24.3750 degree C
The temperature is 24.6250 degree C
The temperature is 25.0 degree C
The temperature is 25.2500 degree C
The temperature is 25.4375 degree C
References
Datasheet - http://www.ti.com/lit/ds/sbos288l/sbos288l.pdf
Sensor 26 – MPL3115A2
Description
The MPL3115A2 is a compact, piezoresistive, absolute
pressure sensor with an I2C digital interface. MPL3115A2 has
a wide operating range of 20 kPa to 110 kPa, a range that
covers all surface elevations on earth. The MEMS is
temperature compensated utilizing an on-chip temperature
sensor.
The pressure and temperature data is fed into a high
resolution ADC to provide fully compensated and digitized
outputs for pressure in Pascals and temperature in °C. The
compensated pressure output can then be converted to
altitude, utilizing the formula stated in Section 9.1.3
"Pressure/altitude" provided in meters.The internal
processing in MPL3115A2 removes compensation and unit
conversion load from the system MCU, simplifying system
design.
MPL3115A2's advanced ASIC has multiple user
programmable modes such as power saving, interrupt and
autonomous data acquisition modes, including programmed
acquisition cycle timing, and poll-only modes. Typical active
supply current is 40 μA per measurement-second for a stable
10 cm output resolution Operating range: 20 kPa to 110 kPa
absolute pressure Calibrated range: 50 kPa to 110 kPa
absolute pressure Calibrated temperature output: −40 °C to
85 °C
Direct reading
– Pressure: 20-bit measurement (Pascals) 20 to 110 kPa –
Altitude: 20-bit measurement (meters) –698 to 11,775 m –
Temperature: 12-bit measurement (°C) –40 °C to 85 °C
1.95 V to 3.6 V supply voltage, internally regulated 1.6 V to
3.6 V digital interface supply voltage Operating temperature
from −40 °C to +85 °C
Name Quantity
Arduino Uno 1
MPL3115A2 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
void setup() {
Serial.begin(9600);
Serial.println("Adafruit_MPL3115A2 test!");
}
void loop() {
if (! baro.begin()) {
Serial.println("Couldnt find sensor");
return;
}
delay(250);
}
Output
Open the serial monitor - this is what I saw
Adafruit_MPL3115A2 test!
29.70 Inches (Hg)
84.12 meters
23.87*C
29.70 Inches (Hg)
84.25 meters
23.94*C
References
Datasheet - https://www.nxp.com/docs/en/data-
sheet/MPL3115A2.pdf
Sensor 27 – CCS811
Description
CCS811 is a low-power digital gas sensor solution, which
integrates a gas sensor solution for detecting low levels of
VOCs typically found indoors, with a microcontroller unit
(MCU) and an Analog-to-Digital converter to monitor the
local environment and provide an indication of the indoor air
quality via an equivalent CO2 or TVOC output over a
standard I2C digital interface.
Features
Integrated MCU
On-board processing
Standard digital interface
Optimised low power modes
IAQ threshold alarms
Programmable baseline
Product parameters
Supply Voltage [V] 1.8 to 3.6
Power Consumption [mW] 1.2 to 46
Ambient Temperature Range [°C] -40 to 85
Ambient Humidity Range [% r.h.] 10 to 95
Parts List
Name Quantity
Arduino Uno 1
CCS811 (CJMCU-811) 1
Connecting Wire 1
Schematics/Layout/Connection
You need to connect the WAKE pin to ground or you will get
no readings
Code Examples
#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;
void setup()
{
Serial.begin(9600);
Serial.println("CCS811 test");
if(!ccs.begin())
{
Serial.println("Failed to start sensor! Please check your wiring.");
while(1);
}
void loop()
{
if(ccs.available())
{
float temp = ccs.calculateTemperature();
if(!ccs.readData())
{
Serial.print("CO2: ");
Serial.print(ccs.geteCO2());
Serial.print("ppm, TVOC: ");
Serial.print(ccs.getTVOC());
Serial.print("ppb Temp:");
Serial.println(temp);
}
else
{
Serial.println("ERROR!");
while(1);
}
}
delay(500);
}
Output
Open the serial monitor - this is what I saw. The higher CO2
level was when I breathed on the sensor
CO2: 400ppm, TVOC: 0ppb Temp:28.28
CO2: 400ppm, TVOC: 0ppb Temp:47.75
CO2: 400ppm, TVOC: 0ppb Temp:25.00
CO2: 400ppm, TVOC: 0ppb Temp:26.49
CO2: 1228ppm, TVOC: 126ppb Temp:25.68
CO2: 575ppm, TVOC: 26ppb Temp:9.59
CO2: 400ppm, TVOC: 0ppb Temp:26.49
CO2: 400ppm, TVOC: 0ppb Temp:105.81
References
Sensor 28 – MAX30100
Description
The MAX30100 is an integrated pulse oximetry and heart-
rate monitor sensor solution. It combines two LEDs, a
photodetector, optimized optics, and low-noise analog signal
processing to detect pulse oximetry and heart-rate signals.
Key Features
Complete Pulse Oximeter and Heart-Rate Sensor Solution
Simplifies Design Integrated LEDs, Photo Sensor, and High-
Performance Analog Front-End Tiny 5.6mm x 2.8mm x
1.2mm 14-Pin Optically Enhanced System-in-Package Ultra-
Low-Power Operation Increases Battery Life for Wearable
Devices Programmable Sample Rate and LED Current for
Power Savings Ultra-Low Shutdown Current (0.7µA, typ)
Advanced Functionality Improves Measurement Performance
High SNR Provides Robust Motion Artifact Resilience
Integrated Ambient Light Cancellation
High Sample Rate Capability
Fast Data Output Capability
Name Quantity
Arduino Uno 1
MAX 30100 (GY-MAX30100) 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
uint32_t tsLastReport = 0;
void setup()
{
Serial.begin(115200);
void loop()
{
// Make sure to call update as fast as possible
pox.update();
tsLastReport = millis();
}
}
Output
Open the serial monitor
Heart rate:95.04bpm / SpO2:93%
Beat!
Beat!
Heart rate:79.23bpm / SpO2:94%
Beat!
Heart rate:78.94bpm / SpO2:94%
Beat!
Heart rate:76.35bpm / SpO2:94%
Beat!
Beat!
Heart rate:76.26bpm / SpO2:94%
Beat!
References
Datasheet -
https://datasheets.maximintegrated.com/en/ds/MAX30100.p
df
Sensor 29 – MLX90615
Description
The MLX90615 is a miniature infrared thermometer for non-
contact temperature measurements. Both the IR sensitive
thermopile detector chip and the signal conditioning ASIC are
integrated in the same miniature TO-46 can.
With its small size, this infrared thermometer is especially
suited for medical applications like ear or forehead
thermometers or other applications where "small things
make a big difference".
The infrared thermometer comes factory calibrated with a
digital SMBus output giving full access to the measured
temperature in the complete temperature range(s) with a
resolution of 0.02 °C. The sensor achieves an accuracy of
±0.2°C within the relevant medical temperature range. The
user can choose to configure the digital output to be PWM.
Factory calibrated in wide temperature range: -20 to 85°C for
sensor temperature and -40 to 115°C for object temperature
High accuracy of 0.5°C over wide temperature range (0..+50
C for both Ta and To) Medical accuracy of 0.2°C in a limited
temperature range Measurement resolution of 0.02°C
SMBus compatible digital interface for fast temperature
readings and building sensor networks Customizable PWM
output for continuous reading 3V supply voltage with power
saving mode
Name Quantity
Arduino Uno 1
MLX90615 1
Connecting wire 1
Schematics/Layout/Connection
void setup()
{
Serial.begin(9600);
Serial.println("Melexis MLX90615 infra-red temperature sensor test");
mlx.begin();
Serial.print("Sensor ID number = ");
Serial.println(mlx.get_id(), HEX);
}
void loop()
{
Serial.print("Ambient = ");
Serial.print(mlx.get_ambient_temp()); //ambient temperature
Serial.print(" *C\tObject = ");
Serial.print(mlx.get_object_temp()); //object temperature
Serial.println(" *C");
delay(500);
}
Output
Open the serial monitor and you should see something like
this.
Ambient = 30.85 *C Object = 25.67 *C
Ambient = 30.85 *C Object = 25.71 *C
Ambient = 30.79 *C Object = 25.81 *C
Ambient = 30.75 *C Object = 25.67 *C
Ambient = 30.71 *C Object = 25.43 *C
Ambient = 30.63 *C Object = 25.57 *C
Ambient = 30.57 *C Object = 25.95 *C
Ambient = 30.53 *C Object = 25.95 *C
Ambient = 30.49 *C Object = 26.15 *C
References
Sensor 30 – Si1145
Description
The Si1145/46/47 is a low-power, reflectance-based, infrared
proximity, ultraviolet (UV) index, and ambient light sensor
with I2C digital interface and programmableevent interrupt
output. This touchless sensor IC includes an analog-to-digital
converter, integrated high-sensitivity visible and infrared
photodiodes, digital signal processor, and one, two, or three
integrated infrared LED drivers with fifteen selectable drive
levels.
The Si1145/46/47 offers excellent performance under a wide
dynamic range and a variety of light sources including direct
sunlight. The Si1145/46/47 can also work under dark glass
covers. The photodiode response and associated digital
conversion circuitry provide excellent immunity to artificial
light flicker noise and natural light flutter noise.
With two or more LEDs, the Si1146/47 is capable of
supporting multiple-axis proximity motion detection. The
Si1145/46/47 devices are provided in a 10-lead 2x2 mm QFN
package and are capable of operation from 1.71 to 3.6 V
over the –40 to +85 °C temperature range.
Proximity detection adjustable from under 1 cm to over 50
cm Three independent LED drivers
15 current settings from 5.6 mA to 360 mA for each LED
driver 50 cm proximity range with single pulse (<3 klx) 15
cm proximity range with single pulse (>3 klx) Operates at up
to 128 klx (direct sunlight)
1.71 to 3.6 V supply voltage
Internal and external wake support
Built-in voltage supply monitor and power-on reset controller
Up to 3.4 Mbps data rate
Temperature Range –40 to +85 °C
Here is the module that I used
Parts List
Name Quantity
Arduino Uno 1
Si1145 module (GY1145) 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
Adafruit_SI1145 uv = Adafruit_SI1145();
void setup() {
Serial.begin(9600);
if (! uv.begin()) {
Serial.println("Didn't find Si1145");
while (1);
}
Serial.println("OK!");
}
void loop() {
Serial.println("===================");
Serial.print("Vis: "); Serial.println(uv.readVisible());
Serial.print("IR: "); Serial.println(uv.readIR());
delay(1000);
}
Output
Open the serial monitor window and you will see something
like this
Vis: 261
IR: 293
UV: 0.02
===================
Vis: 261
IR: 295
UV: 0.02
===================
Vis: 261
IR: 263
UV: 0.02
===================
References
Datasheet - https://www.silabs.com/documents/public/data-
sheets/Si1145-46-47.pdf
Sensor 31 – TMP102
Description
The TMP102 device is a digital temperature sensor ideal for
NTC/PTC thermistor replacement where high accuracy is
required. The device offers an accuracy of ±0.5°C without
requiring calibration or external component signal
conditioning. Device temperature sensors are highly linear
and do not require complex calculations or lookup tables to
derive the temperature. The on-chip 12-bit ADC offers
resolutions down to 0.0625°C.
The 1.6-mm × 1.6-mm SOT563 package is 68% smaller
footprint than an SOT-23 package. The TMP102 device
features SMBus™, two-wire and I2C interface compatibility,
and allows up to four devices on one bus. The device also
features an SMBus alert function. The device is specified to
operate over supply voltages from 1.4 to 3.6 V with the
maximum quiescent current of 10 µA over the full operating
range.
The TMP102 device is ideal for extended temperature
measurement in a variety of communication, computer,
consumer, environmental, industrial, and instrumentation
applications. The device is specified for operation over a
temperature range of –40°C to 125°C.
The TMP102 production units are 100% tested against
sensors that are NIST-traceable and are verified with
equipment that are NIST-traceable through ISO/IEC 17025
accredited calibrations.
Features
Accuracy Without Calibration:
2.0°C (max) from –25°C to 85°C
3.0°C (max) from –40°C to 125°C
Low Quiescent Current:
10-µA Active (max) 1-µA Shutdown (max)
Supply Range: 1.4 to 3.6 V
Resolution: 12 Bits
Digital Output: SMBus, Two-Wire, and I2C Interface
Compatibility
This is the module that I used
Parts List
Name Quantity
Arduino Uno 1
TMP102 module 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
#define TMP102_I2C_ADDRESS 72 /* This is the I2C address for our chip. This
value is correct if you tie the ADD0 pin to ground. See the datasheet for some
other values. */
void setup()
{
Wire.begin(); // start the I2C library
Serial.begin(115200); //Start serial communication at 115200 baud
}
void loop()
{
getTemp102();
delay(5000); //wait 5 seconds before printing our next set of readings.
}
void getTemp102()
{
byte firstbyte, secondbyte; //these are the bytes we read from the TMP102
temperature registers
int val; /* an int is capable of storing two bytes, this is where we "chuck" the two
bytes together. */
float convertedtemp; /* We then need to multiply our two bytes by a scaling
factor, mentioned in the datasheet. */
float correctedtemp;
firstbyte = (Wire.read());
/*read the TMP102 datasheet - here we read one byte from
each of the temperature registers on the TMP102*/
secondbyte = (Wire.read());
/*The first byte contains the most significant bits, and
the second the less significant */
val = firstbyte;
if ((firstbyte & 0x80) > 0)
{
val |= 0x0F00;
}
val <<= 4;
/* MSB */
val |= (secondbyte >> 4);
/* LSB is ORed into the second 4 bits of our byte.
Bitwise maths is a bit funky, but there's a good tutorial on the playground*/
convertedtemp = val*0.0625;
correctedtemp = convertedtemp - 5;
/* See the above note on overreading */
Serial.print("firstbyte is ");
Serial.print("\t");
Serial.println(firstbyte, BIN);
Serial.print("secondbyte is ");
Serial.print("\t");
Serial.println(secondbyte, BIN);
Serial.print("Concatenated byte is ");
Serial.print("\t");
Serial.println(val, BIN);
Serial.print("Converted temp is ");
Serial.print("\t");
Serial.println(val*0.0625);
Serial.print("Corrected temp is ");
Serial.print("\t");
Serial.println(correctedtemp);
Serial.println();
}
Output
Open the serial monitor window and you should see
something like this
firstbyte is 10110
secondbyte is 11000000
Concatenated byte is 101101100
Converted temp is 22.75
Corrected temp is 17.75
firstbyte is 11100
secondbyte is 10110000
Concatenated byte is 111001011
Converted temp is 28.69
Corrected temp is 23.69
References
Datasheet - http://www.ti.com/lit/ds/symlink/tmp102.pdf
Sensor 32 – HMC5983
Description
The Honeywell HMC5983 is a temperature compensated
three-axis integrated circuit magnetometer. This surface-
mount, multi-chip module is designed for low-field magnetic
sensing for applications such as automotive and personal
navigation, vehicle detection, and pointing.
The HMC5983 includes our state-of-the-art, high-resolution
HMC118X series magnetoresistive sensors plus an ASIC
containing amplification, automatic degaussing strap drivers,
offset cancellation, and a 12-bit ADC that enables 1° to 2°
compass heading accuracy. The I²C or SPI serial bus allows
for easy interface. The HMC5983 is a 3.0x3.0x0.9mm surface
mount 16-pin leadless chip carrier (LCC).
The HMC5983 utilizes Honeywell’s Anisotropic
Magnetoresistive (AMR) technology that provides
advantages over other magnetic sensor technologies.
Honeywell’s anisotropic, directional sensors excel in linearity,
low hysteresis, null output and scale factor stability over
temperature, and with very low cross-axis sensitivity.
Features
Temperature Compensated Data Output and Temperature
Output Automatic Offset Compensation
12-Bit ADC Coupled with Low Noise AMR Sensors Achieves 2
milli-gauss Field Resolution Fast 220 Hz Maximum Output
Rate
Wide Magnetic Field Range (+/-8 Oe)
Low Voltage Operations (2.16 to 3.6V) and Low Power
Consumption (100 μA)
Here is the module that I used
Parts List
Name Quantity
Arduino Uno 1
HMC5983 module (GY-282) 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples
void setup()
{
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(addr);
Wire.write(0x02);
Wire.write(0x00); //Continuously Measure
Wire.endTransmission();
}
void loop()
{
int x,y,z; //triple axis data
Wire.beginTransmission(addr);
Wire.write(0x03);
Wire.endTransmission();
//Read the data
Wire.requestFrom(addr, 6);
if(6<=Wire.available())
{
x = Wire.read()<<8; //MSB x
x |= Wire.read(); //LSB x
z = Wire.read()<<8; //MSB z
z |= Wire.read(); //LSB z
y = Wire.read()<<8; //MSB y
y |= Wire.read(); //LSB y
}
// Show Values via serial
Serial.print("X Value: ");
Serial.println(x);
Serial.print("Y Value: ");
Serial.println(y);
Serial.print("Z Value: ");
Serial.println(z);
Serial.println();
delay(500);
}
Output
Open the serial monitor X Value: -379
Y Value: 301
Z Value: 126
X Value: 116
Y Value: 548
Z Value: -255
X Value: -458
Y Value: 119
Z Value: -273
X Value: -314
Y Value: -39
Z Value: 383
X Value: -91
Y Value: 471
Z Value: 129
References
Sensor 33 – MAX44009
Description
The MAX44009 ambient light sensor features an I²C digital
output that is ideal for a number of portable applications
such as smartphones, notebooks, and industrial sensors. At
less than 1µA operating current, it is the lowest power
ambient light sensor in the industry and features an ultra-
wide 22-bit dynamic range from 0.045 lux to 188,000 lux.
Low-light operation allows easy operation in dark-glass
applications.
The on-chip photodiode's spectral response is optimized to
mimic the human eye’s perception of ambient light and
incorporates IR and UV blocking capability. The adaptive gain
block automatically selects the correct lux range to optimize
the counts/lux.
The IC is designed to operate from a 1.7V to 3.6V supply
voltage range and consumes only 0.65µA in full operation. It
is available in a small, 2mm x 2mm x 0.6mm UTDFN-Opto
package.
Features
Wide 0.045 Lux to 188,000 Lux Range
VCC = 1.7V to 3.6V
ICC = 0.65µA Operating Current
-40°C to +85°C Temperature Range
Name Quantity
Arduino Uno 1
MAX44009 module 1
Connecting wire pack 1
Schematics/Layout/Connection
Code Examples
#include<Wire.h>
void setup()
{
Wire.begin();
// Initialise serial communication
Serial.begin(9600);
Wire.beginTransmission(Addr);
Wire.write(0x02);
Wire.write(0x40);
Wire.endTransmission();
delay(300);
}
void loop()
{
unsigned int data[2];
Wire.beginTransmission(Addr);
Wire.write(0x03);
Wire.endTransmission();
Output
Open the serial monitor and change the light intensity on the
sensor, here is an example Ambient Light luminance :4.59
lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :6.12 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :36.72 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
Ambient Light luminance :73.44 lux
References
Datasheet -
https://datasheets.maximintegrated.com/en/ds/MAX44009.p
df
Sensor 34 – MMA8451
Description
The MMA8451Q is a smart, low-power, three-axis, capacitive,
micromachined accelerometer with 14 bits of resolution. This
accelerometer is packed with embedded functions with
flexible user programmable options, configurable to two
interrupt pins. Embedded interrupt functions allow for overall
power savings relieving the host processor from continuously
polling data.
There is access to both low-pass filtered data as well as high-
pass filtered data, which minimizes the data analysis
required for jolt detection and faster transitions. The device
can be configured to generate inertial wakeup interrupt
signals from any combination of the configurable embedded
functions allowing the MMA8451Q to monitor events and
remain in a low-power mode during periods of inactivity.
Features
• 1.95 V to 3.6 V supply voltage
• 1.6 V to 3.6 V interface voltage
• ±2 g/±4 g/±8 g dynamically selectable full scale • Output
data rates (ODR) from 1.56 Hz to 800 Hz • 99 μg/√Hz noise
• 14-bit and 8-bit digital output
• I2C digital output interface
• Two programmable interrupt pins for seven interrupt
sources • Three embedded channels of motion detection —
Freefall or motion detection: one channel
— Pulse detection: one channel
— Jolt detection: one channel
• Orientation (portrait/landscape) detection with
programmable hysteresis • Automatic ODR change for auto-
wake and return to sleep • 32-sample FIFO
• High-pass filter data available per sample and through the
FIFO
• Self-test
• Current consumption: 6 μA to 165 μA
Parts List
Name Quantity
Arduino Uno 1
MMA8451 1
Connecting wire pack 1
Schematics/Layout/Connection
void setup(void) {
Serial.begin(9600);
if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");
mma.setRange(MMA8451_RANGE_2_G);
void loop() {
// Read the 'raw' data in 14-bit counts
mma.read();
Serial.print("X:\t"); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();
switch (o) {
case MMA8451_PL_PUF:
Serial.println("Portrait Up Front");
break;
case MMA8451_PL_PUB:
Serial.println("Portrait Up Back");
break;
case MMA8451_PL_PDF:
Serial.println("Portrait Down Front");
break;
case MMA8451_PL_PDB:
Serial.println("Portrait Down Back");
break;
case MMA8451_PL_LRF:
Serial.println("Landscape Right Front");
break;
case MMA8451_PL_LRB:
Serial.println("Landscape Right Back");
break;
case MMA8451_PL_LLF:
Serial.println("Landscape Left Front");
break;
case MMA8451_PL_LLB:
Serial.println("Landscape Left Back");
break;
}
Serial.println();
delay(500);
Output
Open the serial monitor and move the module around
References
Datasheet - https://www.nxp.com/docs/en/data-
sheet/MMA8451Q.pdf