0% found this document useful (0 votes)
8 views

34 Arduino Sensor Projects

The document is a comprehensive guide detailing 34 different sensors that can be used with Arduino, including their descriptions, specifications, and example code. Each sensor is accompanied by a parts list, schematics for connections, and references for further information. The guide also includes basic Arduino setup instructions and library installation processes for users unfamiliar with the platform.

Uploaded by

Eddie Kwok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

34 Arduino Sensor Projects

The document is a comprehensive guide detailing 34 different sensors that can be used with Arduino, including their descriptions, specifications, and example code. Each sensor is accompanied by a parts list, schematics for connections, and references for further information. The guide also includes basic Arduino setup instructions and library installation processes for users unfamiliar with the platform.

Uploaded by

Eddie Kwok
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 180

34 Arduino Sensor Examples

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''.

You will be prompted to select the library you would like to


add. Navigate to the .zip file's location and open it.
Return to the Sketch > Include Library menu. menu. You
should now see the library at the bottom of the drop-down
menu. It is ready to be used in your sketch. The zip file will
have been expanded in the libraries folder in your Arduino
sketches directory.
NB: the Library will be available to use in sketches, but with
older IDE versions examples for the library will not be
exposed in the File > Examples until after the IDE has
restarted.
Manual installation When you want to add a library
manually, you need to download it as a ZIP file, expand it
and put in the proper directory. The ZIP file contains all you
need, including usage examples if the author has provided
them. The library manager is designed to install this ZIP file
automatically as explained in the former chapter, but there
are cases where you may want to perform the installation
process manually and put the library in the libraries folder of
your sketchbook by yourself.
You can find or change the location of your sketchbook folder
at File > Preferences > Sketchbook location.
Sensor 1 – BMP180
Description
The BMP180 is a digital barometric pressure sensor made by
Bosch Sensortec, with a very high performance, which
enables applications in advanced mobile devices, such as
smartphones, tablet PCs and sports devices. It follows the
BMP085 and brings many improvements, like the smaller
size and the expansion of digital interfaces.
The ultra-low power consumption down to 3 μA makes the
BMP180 the leader in power saving for your mobile devices.
BMP180 is also distinguished by its very stable behavior
(performance) with regard to the independency of the supply
voltage.
Specs Pressure range : 300 ... 1100 hPa
Supply voltage : 1.8 to 3.6 V
Operation temp : -40 ... +85 °C

This is the module that I used for this example

Parts List

Name Quantity
Arduino Uno 1
BMP180 1
Connecting wire 1
Schematics/Layout/Connection
Code Examples

I used this library - https://github.com/adafruit/Adafruit-


BMP085-Library

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

// Connect VCC of the BMP180 sensor to 3.3V


// Connect GND to Ground
// Connect SCL to i2c clock thats A5
// Connect SDA to i2c data thats A4

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

this was the reading from the serial monitor


Temperature = 22.90 *C
Altitude = 103.32 meters

To see how accurate this was I went to


http://elevationmap.net and typed in my address, the stated
elevation was 99m. Given that there was probably an
additional couple of metres where the device was located in
my house that's not too bad accuracy wise
References

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.

Features Unique 1-Wire® Interface Requires Only One Port


Pin for Communication Measures Temperatures from -55°C to
+125°C
±0.5°C Accuracy from -10°C to +85°C
Programmable Resolution from 9 Bits to 12 Bits No External
Components Required
Parasitic Power Mode Requires Only 2 Pins for Operation (DQ
and GND) Each Device Has a Unique 64-Bit Serial Code
Stored in On-Board ROM

This is the module that I used


Parts List

Name Quantity
Arduino Uno 1
DS18b20 1
Connecting wire 1

Schematics/Layout/Connection

Code Examples

You need to download 2 libraries and install them


using the library manager.

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>

//the pin you connect the ds18b20 to


#define DS18B20 2

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

Each read of the temperature and humidity values are the


results of the last measurement For real-time data you need
to perform a sequential read twice, but it is not
recommended to repeatedly read the sensors, each read
sensor interval should be greater than 5 seconds to obtain
accurate data.
This is the module that I used
Parts List

Name Quantity
Arduino Uno 1
DHT11 module 1
Connecting wire 1

Schematics/Layout/Connection
Code Examples

You will need the DHT11 library from the


https://github.com/getmicros/Arduino-
Libraries/blob/master/dht11.zip.

Download, extract and import this to your Arduino libraries


folder location. This is a simple example which outputs the
humidity and temperature, place your fingers on the DHT11
and you will see the readings fluctuate #include <dht11.h>

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()
{

//humidity and temperature output


Serial.print(“Humidity is “);
Serial.print(DHT.humidity,1);
Serial.print(“\n”);
Serial.println(“Temperature is “);
Serial.println(DHT.temperature,1);

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.

Input voltage : 4.V to 12V (+5V recommended) Output


voltage is High/Low (3.3V TTL)
Two operating modes : Repeatable(H) and Non-
Repeatable(H) Coverage : 120° and 7 meters
Power consumption : 65mA
Operating temperature : -20° to +80° Celsius
This is the module that I used

Parts List

Name Quantity
Arduino Uno 1
HCSR01 PIR module 1
Connecting wire 1

Schematics/Layout/Connection
Code Examples

This basic example will display a different output


depending on whether motion is detected. This does
not wait as per the spec above before readings are
taken
int pirPin = 8;
int val;

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

Wire connecting direct as following: 5V Supply


Trigger Pulse Input
Echo Pulse Output
0V Ground

Working Voltage DC 5 V
Working Current 15mA
Working Frequency 40Hz
Max Range 4m
Min Range 2cm
Measuring Angle 15 degrees

You only need to supply a short 10uS pulse to the trigger


input to start the ranging, and then the module will send out
an 8-cycle burst of ultrasound at 40 kHz and raise its echo.
The Echo is a distance object that is pulse width and the
range in proportion. You can calculate the range through the
time interval between sending trigger signal and receiving
echo signal. Formula: uS / 58 = centimeters or uS / 148
=inch; or: the range = high level time * velocity (340M/S) / 2;
we suggest using over 60ms measurement cycle, to prevent
trigger signal to the echo signal This is a picture of this

module
Parts List

Name Quantity
Arduino Uno 1
HC-SR04 detector 1
Connecting wire 1

Schematics/Layout/Connection

Module Connection Arduino Connection


Vcc 5v
GND Gnd
Echo D7
Trig D8
Code Examples

#define echoPin 7 // Echo Pin


#define trigPin 8 // Trigger Pin

long duration, distance; // Duration used to calculate distance

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.

Features Relative Humidity (RH) Operating Range 0% to


100%
14 Bit Measurement Resolution
Relative Humidity Accuracy ±4%
Temperature Accuracy ±0.2 °C

Average Supply Current:


820 nA @ 1sps, 11 bit RH Measurement
1.2 µA @ 1sps, 11 bit RH and Temperature Measurement
Supply Voltage 3 V to 5 V
I2C Interface

This sensor has been superseded by the HDC1010 and is not


recommended for new designs but there are modules that
can still be purchased, here is the one I used

Parts List

Name Quantity
Arduino UNO 1
HDC1008 1
Connecting wire 1

Schematics/Layout/Connection

Connect Vin to 5VDC


Connect GND to ground
Connect SCL to A5 on UNO
Connect SDA to A4 on UNO

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"

Adafruit_HDC1000 hdc = Adafruit_HDC1000();


void setup()
{
Serial.begin(9600);
Serial.println("HDC100x test");

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.

Additional Features Accuracy:


±0.25°C (typical) from -40°C to +125°C
±0.5°C (maximum) from -20°C to +100°C
User Selectable Measurement Resolution: 0.5°C, 0.25°C,
0.125°C, 0.0625°C
Operating Voltage Range: 2.7V to 5.5V
Operating Current: 200 µA (typical)
Shutdown Current: 0.1 µA (typical)
2-wire Interface: I2C/SMBus Compatible
This is the module that I purchased
Parts List

Name Quantity
Arduino Uno 1
MCP9808 1
Connecting wire 1

Schematics/Layout/Connection
Code Examples

You will need the adafruit MCP9808 library which is available


at
https://github.com/adafruit/Adafruit_MCP9808_Library/archiv
e/master.zip
#include <Wire.h>
#include "Adafruit_MCP9808.h"

// Create the MCP9808 temperature sensor object


Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
void setup() {
Serial.begin(9600);

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

This is the module that I used


Parts List

Name Quantity
Arduino Uno 1
MLX90614 (GY-906) 1
Connecting wire 1
Schematics/Layout/Connection

Code Examples

The sketch below is fairly straightforward, most of the work


is done in the Adafruit MLX96014 library -
https://github.com/adafruit/Adafruit-MLX90614-Library
#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

Serial.println("Adafruit MLX90614 test");

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

The code uses the sparkfun library, I tried 2 others and


couldn't get them to compile. There are several examples
available. I removed some code from a basic example
Library -
https://github.com/sparkfun/SparkFun_BME280_Arduino_Libr
ary
#include <stdint.h>
#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"

//Global sensor object


BME280 mySensor;

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;

Serial.print("Starting BME280... result of .begin(): 0x");


delay(10); //BME280 requires 2ms to start up.
Serial.println(mySensor.begin(), HEX);

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.

Supply Voltage [V] 2.7 - 3.6


Interface I2C - VDD
Programmable Gain, integration time, interrupt Max. Lux
40000
Temperature Range [°C] -30 to 70

AMS recommend TSL2572x device family.


I used the following module
Parts List

Name Quantity
Arduino Uno 1
TSL2561 1
Connecting wire 1

Schematics/Layout/Connection

Device Pin Arduino


GND GND
Vcc / 3.3 (or Vin on Adafruit modules) 3.3 or 5v
SCL D1
SDA D2
ADDR N/C
Int N/C

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>

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT,


12345);

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("");

/* Initialise the sensor */


if(!tsl.begin())
{
Serial.print("no TSL2561 detected!");
while(1);
}

configureSensor();
}

void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);

/* Display the results (light is measured in lux) */


if (event.light)
{
Serial.print(event.light);
Serial.println(" lux");
}
else
{
Serial.println("Sensor overload");
}
delay(500);
}

Output

Open the serial monitor window, mover the sensor to light


sources, cover the sensor. you can see in the example below
me moving to a bright light source and the value increasing
349.00 lux
757.00 lux
892.00 lux
992.00 lux
1192.00 lux
1890.00 lux
3324.00 lux
4051.00 lux
References
Sensor 11 –SHT21
Description
The digital SHT2x humidity sensor series is used in high
volumes in a wide variety of applications and has today
become the de facto industry standard. The SHT2x series
consists of a low-cost version with the SHT20 humidity
sensor, a standard version with the SHT21 humidity sensor,
and a high-end version with the SHT25 humidity sensor. The
open cavity mold package - which encapsulates the
complete chip except for the humidity sensor area - protects
the capacitive humidity sensor against external impact and
facilitates excellent long-term stability. The SHT2x sensors
are available both in large and small volumes.
Embedded in a reflow solderable dual-flat no-leads (DFN)
package of 3 × 3 × 1.1 mm3, the SHT2x provides calibrated,
linearized sensor signals in digital, I2C format. The SHT2x
humidity sensor series contains a capacitive-type humidity
sensor, a band-gap temperature sensor, and specialized
analog and digital integrated circuits – all on a single
CMOSens® chip. This yields superior sensor performance in
terms of accuracy and stability as well as minimal power
consumption.
Every sensor is individually calibrated and tested. Lot
identification is printed on the sensor and an electronic
identification code is stored on the chip – which can be read
out on command. Furthermore, the resolution of the SHT2x
humidity sensor can be changed on command (8/12 bit up to
12/14 bit for RH/T) and a checksum helps to improve
communication reliability. With this set of features and its
proven reliability and long-term stability, the SHT2x humidity
sensor series offers an outstanding price-performance ratio.
To test a humidity sensor from the SHT2x series, two
evaluation kits, EK-H4 and EK-H5, are available.
Features Output I²C digital, PWM, SDM
Supply voltage range 2.1 to 3.6 V
Energy consumption 3.2µW (at 8-bit, 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 used the following module

Parts List

Name Quantity
Arduino Uno 1
SHT21 1
Connecting wire 1

Schematics/Layout/Connection

Here is a simple schematic, again be careful as Vcc is 3.3v


with this device
Code Examples

I used the following library -


https://github.com/elechouse/SHT21_Arduino
#include <Wire.h>
#include <SHT2x.h>

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

int UVsensorIn = A0; //Output from the sensor

void setup()
{
pinMode(UVsensorIn, INPUT);
Serial.begin(9600); //open serial port, set the baud rate to 9600 bps
}

void loop()
{
int uvLevel = averageAnalogRead(UVsensorIn);

float outputVoltage = 3.3 * uvLevel/1024;


float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);

Serial.print(" UV Intensity: ");


Serial.print(uvIntensity);
Serial.print(" mW/cm^2");
Serial.println();
delay(200);
}

//Takes an average of readings on a given pin


//Returns the average
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;

for(int x = 0 ; x < numberOfReadings ; x++)


runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;

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

This example uses the adafruit sht31 library -


https://github.com/adafruit/Adafruit_SHT31
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_SHT31.h"

Adafruit_SHT31 sht31 = Adafruit_SHT31();

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

I used t he following module for this example

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());
}

int mag_read_register(int reg)


{
int reg_val;

Wire.beginTransmission(MAG_ADDR); // transmit to device 0x0E


Wire.write(reg); // x MSB reg
Wire.endTransmission(); // stop transmitting
delayMicroseconds(2); //needs at least 1.3us free time between start and stop

Wire.requestFrom(MAG_ADDR, 1); // request 1 byte


while(Wire.available()) // slave may write less than requested
{
reg_val = Wire.read(); // read the byte
}

return reg_val;
}

int mag_read_value(int msb_reg, int lsb_reg)


{
int val_low, val_high; //define the MSB and LSB
val_high = mag_read_register(msb_reg);
delayMicroseconds(2); //needs at least 1.3us free time between start and stop
val_low = mag_read_register(lsb_reg);
int out = (val_low|(val_high << 8)); //concatenate the MSB and LSB
return out;
}

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

Here is the module that I picked out


Parts List

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"

/* Example code for the Adafruit TCS34725 breakout library */

/* Connect SCL to analog 5


Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */

/* Initialise with default values (int time = 2.4ms, gain = 1x) */


// Adafruit_TCS34725 tcs = Adafruit_TCS34725();

/* Initialise with specific int time and gain values */


Adafruit_TCS34725 tcs =
Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);

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

if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}

// Now we're ready to get readings!


}

void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;

tcs.getRawData(&r, &g, &b, &c);


colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);

Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");


Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}
Output
Open the serial monitor, this is what you should see, point
the module/sensor at a different coloured object
Color Temp: 4554 K - Lux: 379 - R: 1122 G: 831 B: 776 C:
1429
Color Temp: 3173 K - Lux: 181 - R: 475 G: 339 B: 272 C: 707
Color Temp: 3425 K - Lux: 224 - R: 604 G: 435 B: 364 C: 868
Color Temp: 2833 K - Lux: 1497 - R: 2983 G: 2240 B: 1461 C:
5723
Color Temp: 5847 K - Lux: 109 - R: 4109 G: 1327 B: 890 C:
5814
Color Temp: 2767 K - Lux: 460 - R: 4468 G: 1703 B: 1062 C:
6734
Color Temp: 4381 K - Lux: 463 - R: 1379 G: 1012 B: 938 C:
1789
Color Temp: 4276 K - Lux: 588 - R: 1464 G: 1136 B: 997 C:
2153
Color Temp: 3952 K - Lux: 646 - R: 1424 G: 1135 B: 933 C:
2350
Color Temp: 3528 K - Lux: 835 - R: 1713 G: 1362 B: 1036 C:
3101

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.

This time we used the following module


Parts List

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

/ Distributed with a free-will license.


// Use it any way you want, profit or free, provided it
fits in the licenses of its associated works.
// This code is designed to work with the
MLX90393_I2CS I2C Mini Module available from
ControlEverything.com.
// https://www.controleverything.com/products
#include<Wire.h>

// MLX90393 I2C Address is 0x0C(12)


#define Addr 0x0C

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();

// Request 1 byte of data


Wire.requestFrom(Addr, 1);

// Read status byte


if(Wire.available() == 1)
{
unsigned int c = Wire.read();
}

// Start I2C Transmission


Wire.beginTransmission(Addr);
// Select Write register command
Wire.write(0x60);
// Set AH = 0x02
Wire.write(0x02);
// Set AL = 0xB4, RES for magnetic measurement = 0
Wire.write(0xB4);
// Select address register, (0x02 << 2)
Wire.write(0x08);
// Stop I2C Transmission
Wire.endTransmission();

// Request 1 byte of data


Wire.requestFrom(Addr, 1);

// Read status byte


if(Wire.available() == 1)
{
unsigned int c = Wire.read();
}
delay(300);
}

void loop()
{
unsigned int data[7];

// Start I2C Transmission


Wire.beginTransmission(Addr);
// Start single meaurement mode, ZYX enabled
Wire.write(0x3E);
// Stop I2C Transmission
Wire.endTransmission();

// Request 1 byte of data


Wire.requestFrom(Addr, 1);

// Read status byte


if(Wire.available() == 1)
{
unsigned int c = Wire.read();
}
delay(100);

// Start I2C Transmission


Wire.beginTransmission(Addr);
// Send read measurement command, ZYX enabled
Wire.write(0x4E);
// Stop I2C Transmission
Wire.endTransmission();

// Request 7 bytes of data


Wire.requestFrom(Addr, 7);

// Read 7 bytes of data


// status, xMag msb, xMag lsb, yMag msb, yMag lsb, zMag msb, zMag lsb
if(Wire.available() == 7);
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
data[6] = Wire.read();
}

// Convert the data


int xMag = data[1] * 256 + data[2];
int yMag = data[3] * 256 + data[4];
int zMag = data[5] * 256 + data[6];

// Output data to serial monitor


Serial.print("Magnetic Field in X-Axis : ");
Serial.println(xMag);
Serial.print("Magnetic Field in Y-Axis : ");
Serial.println(yMag);
Serial.print("Magnetic Field in Z-Axis : ");
Serial.println(zMag);
delay(500);
}

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

The DS1624 consists of two separate functional units: a 256-


byte nonvolatile E2 memory and a direct-to-digital
temperature sensor.
The nonvolatile memory is made up of 256 bytes of E2
memory. This memory can be used to store any type of
information the user wishes. These memory locations are
accessed through the 2-wire serial bus.
The direct-to-digital temperature sensor allows the DS1624
to measure the ambient temperature and report the
temperature in a 12-bit word with 0.0625°C resolution. The
temperature sensor and its related registers are accessed
through the 2-wire serial interface. Figure 1 in the full data
sheet shows a block diagram of the DS1624.
Key Features Reduces Component Count with Integrated
Temperature Sensor and Nonvolatile E2 Memory Measures
Temperatures from -55°C to +125°C in 0.0625°C Increments
±0.5°C Accuracy from 0°C to 70°C
256 Bytes of E2 Memory for Storing Information Such as
Frequency Compensation Coefficients No External
Components
Easy-to-Use 2-Wire Serial Interface
Temperature is Read as a 12-Bit Value (2-Byte Transfer)
Available in 8-Pin SO and DIP Packages

This is the module that I used


Parts List

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

//I downloaded and imported the following library -


https://github.com/bluemurder/DS1624

//This is the example so some of the hard graft has already


been done for you #include <DS1624.h>

// Sensor presents all address pins connected to ground


DS1624 ds1624(0x00);

void setup()
{
// Begin serial connection at 9600 baud
Serial.begin(9600);
}

void loop()
{
float temperature;
bool valid;

// Get current temperature


ds1624.GetTemperature(temperature, 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

Be careful because the sensor that I used required 3.3v, it


did not include a 3.3v regulator on the board
Code Examples

#include <Wire.h>

const int ADDR =0x40;


int X0,X1,Y0,Y1,Y2,Y3;
double X,Y,X_out,Y_out1,Y_out2;

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");

/**Read data of temperature**/


Wire.requestFrom(ADDR,2);

if(Wire.available()<=2);
{
X0 = Wire.read();
X1 = Wire.read();
X0 = X0<<8;
X_out = X0+X1;
}

/**Calculate and display temperature**/


X=(175.72*X_out)/65536;
X=X-46.85;
Serial.print(X);
Serial.print("C");
Serial.print("\t");

/**Send command of initiating relative humidity measurement**/


Wire.beginTransmission(ADDR);
Wire.write(0xE5);
Wire.endTransmission();

/**Read data of relative humidity**/


Wire.requestFrom(ADDR,2);
if(Wire.available()<=2);
{
Y0 = Wire.read();
Y2=Y0/100;
Y0=Y0%100;
Y1 = Wire.read();
Y_out1 = Y2*25600;
Y_out2 = Y0*256+Y1;
}

/**Calculate and display relative humidity**/


Y_out1 = (125*Y_out1)/65536;
Y_out2 = (125*Y_out2)/65536;
Y = Y_out1+Y_out2;
Y=Y-6;
Serial.print(Y);
Serial.println("%");
delay(300);

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

This is the module that I selected

Parts List
Name Quantity
Arduino Uno 1
HDC1080 1
Connecting wire 1
Schematics/Layout/Connection

Arduino connection Module connection


3v3 3v3
GND GND
SDA - A4 SDA
SCL - A5 SCL

Code Examples

You will need to download the following library and install it


from
https://github.com/closedcube/ClosedCube_HDC1080_Arduin
o , this is the default example #include <Wire.h>
#include "ClosedCube_HDC1080.h"

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

I used the following module


Parts List

Name Quantity
Arduino Uno 1
BMP280 1
Connecting wire 1
Schematics/Layout/Connection

Code Examples

This time we use a couple of libraries written by adafruit ,


these are the
https://github.com/adafruit/Adafruit_BMP280_Library and
https://github.com/adafruit/Adafruit_Sensor

This is the default example


/***************************************************************************
This is a library for the BMP280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BMEP280 Breakout
----> http://www.adafruit.com/products/2651

These sensors use I2C or SPI to communicate, 2 or 4 pins are required


to interface.

Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!

Written by Limor Fried & Kevin Townsend for Adafruit Industries.


BSD license, all text above must be included in any redistribution
***************************************************************************/

#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

Adafruit_BMP280 bme; // I2C


//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);

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.print("Approx altitude = ");


Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local
forcase
Serial.println(" m");

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

This is from https://github.com/xreef/DHT12_sensor_library


#include "Arduino.h"

#include <DHT12.h>

// Set dht12 i2c comunication on default Wire pin


DHT12 dht12;

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();

bool dht12Read = true;


// Check if any reads failed and exit early (to try again).
if (isnan(h12) || isnan(t12) || isnan(f12)) {
Serial.println("Failed to read from DHT12 sensor!");

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);

Serial.print("DHT12=> Humidity: ");


Serial.print(h12);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t12);
Serial.print(" *C ");
Serial.print(f12);
Serial.print(" *F\t");
Serial.print(" Heat index: ");
Serial.print(hic12);
Serial.print(" *C ");
Serial.print(hif12);
Serial.print(" *F");
Serial.print(" Dew point: ");
Serial.print(dpc12);
Serial.print(" *C ");
Serial.print(dpf12);
Serial.println(" *F");
}
timeSinceLastRead = 0;
}
delay(100);
timeSinceLastRead += 100;

Output
Open the serial monitor DHT12=&gt; 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=&gt; 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=&gt; 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=&gt; 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=&gt; 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.

AM2320 communication using a single bus, two


communication modes standard I2C. Standard single-bus
interface, the system integration becomes easy and quick.
Ultra-small size, low power consumption, signal transmission
distance up to 20 meters, making all kinds of applications
and even the most demanding applications the best choice.
I2C communication using standard communication
sequence, the user can directly link to the I2 C
communication bus without additional wiring, simple to use.
Two communication modes are used as humidity,
temperature, and other digital information directly CRC
checksum temperature-compensated output, users do not
need to calculate the secondary digital output, and no need
for temperature compensation of the humidity, temperature
and humidity can be accurately information. Two
communication modes are free to switch, the user can freely
choose, easy to use, wide range of applications. 4 lead
product, easy connection, special packages according to user

needs and provide I used this module


Parts List

Name Quantity
Arduino Uno 1
AM2320 1
Connecting wire 1

Schematics/Layout/Connection
Code Examples

You will need to install the folllowing library from


https://github.com/EngDial/AM2320 This is the default
example #include <Wire.h>
#include <AM2320.h>

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

I used this library - https://github.com/jlz3008/lm75


#define VERSION "1.1"

#include <inttypes.h>
#include <Wire.h>

#include <lm75.h>

TempI2C_LM75 termo = TempI2C_LM75(0x48,TempI2C_LM75::nine_bits);

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 example uses the following library


https://github.com/closedcube/ClosedCube_OPT3001_Arduin
o
/*

This is example for ClosedCube OPT3001 Digital Ambient Light Sensor breakout
board

Initial Date: 02-Dec-2015

Hardware connections for Arduino Uno:


VDD to 3.3V DC
SDA to A4
SCL to A5
GND to common ground

Written by AA for ClosedCube

MIT License

*/

#include <Wire.h>
#include <ClosedCube_OPT3001.h>

ClosedCube_OPT3001 opt3001;

#define OPT3001_ADDRESS 0x44

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;

OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);


if (errorConfig != NO_ERROR)
printError("OPT3001 configuration", errorConfig);
else {
OPT3001_Config sensorConfig = opt3001.readConfig();
Serial.println("OPT3001 Current Config:");
Serial.println("------------------------------");

Serial.print("Conversion ready (R):");


Serial.println(sensorConfig.ConversionReady,HEX);

Serial.print("Conversion time (R/W):");


Serial.println(sensorConfig.ConvertionTime, HEX);
Serial.print("Fault count field (R/W):");
Serial.println(sensorConfig.FaultCount, HEX);

Serial.print("Flag high field (R-only):");


Serial.println(sensorConfig.FlagHigh, HEX);

Serial.print("Flag low field (R-only):");


Serial.println(sensorConfig.FlagLow, HEX);

Serial.print("Latch field (R/W):");


Serial.println(sensorConfig.Latch, HEX);

Serial.print("Mask exponent field (R/W):");


Serial.println(sensorConfig.MaskExponent, HEX);

Serial.print("Mode of conversion operation (R/W):");


Serial.println(sensorConfig.ModeOfConversionOperation, HEX);

Serial.print("Polarity field (R/W):");


Serial.println(sensorConfig.Polarity, HEX);

Serial.print("Overflow flag (R-only):");


Serial.println(sensorConfig.OverflowFlag, HEX);

Serial.print("Range number (R/W):");


Serial.println(sensorConfig.RangeNumber, HEX);

Serial.println("------------------------------");
}

void printResult(String text, OPT3001 result) {


if (result.error == NO_ERROR) {
Serial.print(text);
Serial.print(": ");
Serial.print(result.lux);
Serial.println(" lux");
}
else {
printError(text,result.error);
}
}

void printError(String text, OPT3001_ErrorCode error) {


Serial.print(text);
Serial.print(": [ERROR] Code #");
Serial.println(error);
}
Output
Open the serial monitor and you should see something like
this ------------------------------
High-Limit: 83865.54 lux
Low-Limit: 0.00 lux
----
OPT3001: 248.16 lux
OPT3001: 19.08 lux
OPT3001: 12.85 lux
OPT3001: 18.91 lux
OPT3001: 230.24 lux
OPT3001: 218.64 lux
OPT3001: 15.07 lux
OPT3001: 53.40 lux
OPT3001: 173.28 lux
OPT3001: 145.44 lux
References
Datasheet - http://www.ti.com/lit/ds/symlink/opt3001.pdf
Sensor 25 – TMP175
Description
The TMP175 device is a digital temperature sensors ideal for
NTC and PTC thermistor replacement. The devices offer a
typical accuracy of ±1°C without requiring calibration or
external component signal conditioning. IC temperature
sensors are highly linear and do not require complex
calculations or look-up tables to derive the temperature. The
on-chip 12-bit ADC offers resolutions down to 0.0625°C. The
devices are available in the industry standard LM75 SOIC-8
and MSOP-8 footprint.
The TMP175 features SMBus, Two-Wire, and I2C interface
compatibility. The TMP175 device allows up to 27 devices on
one bus. The TMP175 feature an SMBus Alert function.
The TMP175 device is ideal for extended temperature
measurement in a variety of communication, computer,
consumer, environmental, industrial, and instrumentation
applications.
The TMP175 device is specified for operation over a
temperature range of –40°C to 125°C.
The TMP75 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 TMP175: 27 Addresses


Digital Output: SMBus™, Two-Wire™, and I2C
Interface Compatibility
Resolution: 9 to 12 Bits, User-Selectable
Accuracy:
±1°C (Typical) from –40°C to 125°C
±2°C (Maximum) from –40°C to 125°C
Low Quiescent Current: 50-µA, 0.1-µA Standby Wide Supply
Range: 2.7 V to 5.5 V
Small 8-Pin MSOP and 8-Pin SOIC Packages

This is the module I used

Parts List

Name Quantity
Arduino Uno 1
TMP175 1
Connecting wire 1

Schematics/Layout/Connection

Module Connection Arduino Connection


VCC 5v
GND Gnd
SDA SDA
SCL SCL
Code Examples

#include <Wire.h>

byte TempHi; // Variable hold data high byte


byte TempLo; // Variable hold data low byte
boolean P_N; // Bit flag for Positive and Negative
unsigned int Decimal; // Variable hold decimal value

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);

// Read temperature value


Wire.requestFrom(I2C_address, 2);
while(Wire.available()) // Checkf for data from slave
{
TempHi = Wire.read(); // Read temperature high byte
TempLo = Wire.read(); // Read temperature low byte
}
Cal_Temp ();

// 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;

TempHi = TempHi & 0x7F; // Remove sign


TempLo = TempLo & 0xF0; // Filter out last nibble
TempLo = TempLo >>4; // Shift right 4 times
Decimal = TempLo;
Decimal = Decimal * 625; // Each bit = 0.0625 degree C

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

This is the module I used


Parts List

Name Quantity
Arduino Uno 1
MPL3115A2 1
Connecting wire 1

Schematics/Layout/Connection
Code Examples

Again we use a library and again its an adafruit one -


https://github.com/adafruit/Adafruit_MPL3115A2_Library

#include <Wire.h>
#include <Adafruit_MPL3115A2.h>

// Power by connecting Vin to 3-5V, GND to GND


// Uses I2C - connect SCL to the SCL pin, SDA to SDA pin
// See the Wire tutorial for pinouts for each Arduino
// http://arduino.cc/en/reference/wire
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();

void setup() {
Serial.begin(9600);
Serial.println("Adafruit_MPL3115A2 test!");
}

void loop() {
if (! baro.begin()) {
Serial.println("Couldnt find sensor");
return;
}

float pascals = baro.getPressure();


// Our weather page presents pressure in Inches (Hg)
// Use http://www.onlineconversion.com/pressure.htm for other units
Serial.print(pascals/3377); Serial.println(" Inches (Hg)");

float altm = baro.getAltitude();


Serial.print(altm); Serial.println(" meters");
float tempC = baro.getTemperature();
Serial.print(tempC); Serial.println("*C");

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

This is the module that I used for this example

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

Again we use a library this is the adafruit one - you


can use the library manager and add this. And this is
the out of the box example

#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);
}

//calibrate temperature sensor


while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
}

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.

The MAX30100 operates from 1.8V and 3.3V power supplies


and can be powered down through software with negligible
standby current, permitting the power supply to remain
connected at all times.

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

I used the following module


Parts List

Name Quantity
Arduino Uno 1
MAX 30100 (GY-MAX30100) 1
Connecting wire 1

Schematics/Layout/Connection

Arduino Module Pin


5v Vin
Gnd Gnd
SDA SDA
SCL SCL

Code Examples

You will need the library from


https://github.com/oxullo/Arduino-MAX30100 and import it
into the Arduino IDE This is the minimal example which
worked with my module [codesyntax lang="cpp"]
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 1000

// PulseOximeter is the higher level interface to the sensor


// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
PulseOximeter pox;

uint32_t tsLastReport = 0;

// Callback (registered below) fired when a pulse is detected


void onBeatDetected()
{
Serial.println("Beat!");
}

void setup()
{
Serial.begin(115200);

Serial.print("Initializing pulse oximeter..");

// Initialize the PulseOximeter instance


// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

// Register a callback for the beat detection


pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop()
{
// Make sure to call update as fast as possible
pox.update();

// Asynchronously dump heart rate and oxidation levels to the serial


// For both, a value of 0 means "invalid"
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");

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

This is the module that I used


Parts List

Name Quantity
Arduino Uno 1
MLX90615 1
Connecting wire 1
Schematics/Layout/Connection

This device requires a 3.3v connection


Code Examples

This particular example comes from the following library


which I installed - https://github.com/skiselev/MLX90615
#include <Wire.h>
#include <mlx90615.h>

MLX90615 mlx = MLX90615();

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

This example requires the Adafruit Si1145 library, you can


add this via the library manager or download from
https://github.com/adafruit/Adafruit_SI1145_Library
#include <Wire.h>
#include "Adafruit_SI1145.h"

Adafruit_SI1145 uv = Adafruit_SI1145();

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

Serial.println("Adafruit SI1145 test");

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());

// Uncomment if you have an IR LED attached to LED pin!


//Serial.print("Prox: "); Serial.println(uv.readProx());

float UVindex = uv.readUV();


// the index is multiplied by 100 so to get the
// integer index, divide by 100!
UVindex /= 100.0;
Serial.print("UV: "); Serial.println(UVindex);

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

This is from the Arduino site with a few tweaks #include


"Wire.h"

#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;

/* Reset the register pointer (by default it is ready to read temperatures)


You can alter it to a writeable register and alter some of the configuration -
the sensor is capable of alerting you if the temperature is above or below a
specified threshold. */

Wire.beginTransmission(TMP102_I2C_ADDRESS); //Say hi to the sensor.


Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(TMP102_I2C_ADDRESS, 2);
Wire.endTransmission();

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

#include <Wire.h> //I2C Arduino Library


#define addr 0x1E //I2C Address for The HMC5883

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

Here is a picture of the module that I selected


Parts List

Name Quantity
Arduino Uno 1
MAX44009 module 1
Connecting wire pack 1

Schematics/Layout/Connection

Make sure your module has a 3.3v regulator on it


Module Pin Arduino Pin
VIN 5v
GND GND
SDA
SCL

Code Examples
#include<Wire.h>

#define Addr 0x4A //address of device

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();

// Request 2 bytes of data


Wire.requestFrom(Addr, 2);

// Read 2 bytes of data luminance msb, luminance lsb


if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}

// Convert the data to lux


int exponent = (data[0] & 0xF0) >> 4;
int mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F);
float luminance = pow(2, exponent) * mantissa * 0.045;
//output th edata via the serial port
Serial.print("Ambient Light luminance :");
Serial.print(luminance);
Serial.println(" lux");
delay(500);
}

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

Here is a picture of the module that I purchased

Parts List

Name Quantity
Arduino Uno 1
MMA8451 1
Connecting wire pack 1

Schematics/Layout/Connection

An easy device to connect as its an I2C device and the


module works with 5v
Arduino Connection Module Connection
5v VCC_IN
Gnd Gnd
SDA SDA
SCL SCL
Code Examples

This needs the Adafruit library -


https://github.com/adafruit/Adafruit_MMA8451_Library/archiv
e/master.zip

I had to edit the Adafruit header file called


Adafruit_MMA8451.h as my device was address 0x1c (28)

#define MMA8451_DEFAULT_ADDRESS (0x1C)


#include <Wire.h>
#include "Adafruit_MMA8451.h"
#include <Adafruit_Sensor.h>

Adafruit_MMA8451 mma = Adafruit_MMA8451();

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

Serial.println("Adafruit MMA8451 test!");

if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");

mma.setRange(MMA8451_RANGE_2_G);

Serial.print("Range = "); Serial.print(2 << mma.getRange());


Serial.println("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();

/* Get a new sensor event */


sensors_event_t event;
mma.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */


Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");

/* Get the orientation of the sensor */


uint8_t o = mma.getOrientation();

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

You might also like