Arduino Projects

Arduino i2c Scanner and Multiple i2c Sensors Interfacing & Programming

Description:

 

Arduino i2c Scanner and Multiple i2c Sensors Interfacing & Programming– in this tutorial, I will teach you the simplest method on how to scan the address of an i2c supported Sensor and how to connect multiple i2c supported sensors with Arduino without using the Sensors addresses. There are situations when we need to use multiple sensors with the Arduino Uno, but due to the limited number of the I/O pins we are not able to connect many sensors, but thanks to the i2c supported Sensors, now we can connect multiple i2c sensors using only two wires. In this tutorial, I will practically demonstrate; how to use the BPM180 and HMC588L with the Arduino.

 I searched Google and YouTube, I found so many tutorials but they were talking about the sensors addresses and they were rewriting the entire code, reading and writing the hex codes, performing all calculations and so on. Almost all the i2c supported sensors have libraries and programmers has made it very simple for us, we only read the values by calling certain built-in functions. So today you will learn how to use i2c supported sensors without using the addresses.


In this tutorial, I will cover

  • i2c bus Explanation
  • BMP180 Sensor Introduction, its Pinout, interfacing programming and testing
  • HMC5883l Sensor Introduction, Pinout, interfacing, programming and testing
  • Combining both the Sensors and access the data of each sensor separately.

Without any further delay let’s get started!!!

Amazon Links:

Arduino Nano USB-C Type (Recommended)

12v Adaptor:

BMP180 sensor:

HMC5883L Sensor:

Other Tools and Components:

ESP32 WiFi + Bluetooth Module (Recommended)

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

 

Before I am going to explain the multiple Sensors interfacing, I would like to explain some basics. I will write programs for the BMP180 and HMC588L Sensors; once I explain the basics then I will write a combined program.



I2C Bus:

Arduino i2c Scanner and Multiple i2c Sensors

I2C communication Bus has become very popular and now commonly used by thousands of electronics devices because of its easy implementation. By the easy implementation I mean that such devices need only 2 wires. This way we can connect so many devices with for example Arduino using only two wires. Using I2C communication bus we can connect many devices at the same time using only two wires as each device has its own unique address. In Arduino Uno the i2c bus is available on pins A4 and A5.

Arduino i2c Scanner Program:

While the i2c supported Sensor is connected with the Arduino, the following program can be used to find the i2c address of any i2c supported sensor.

All the libraries used in this tutorial can be downloaded by clicking on the link given below.


Download Libraries


About the HMC5883L i2c supported Sensor:

Arduino i2c Scanner and Multiple i2c Sensors

The module includes a state-of-the-art, High-Resolution HMC118x series magneto-resistive sensor, Plus an ASIC containing amplification, Automatic degaussing strap Drivers, Offset cancellation, and a 12-bit ADC that enables 1 to 2 degree compass heading accuracy. The I2C serial bus allows for easy interface.

Features:

  • The Honeywell HMC5883L is a surface mount, multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as low cost compassing and magnetometry.
  • The 12-Bit ADC coupled with low noise AMR sensors
  • Low voltage operations and low power consumption, supports built in self test.
  • Built in strap drive circuits, wide magnetic field range,I2C digital interface
  • Working voltage 3.3v to 5v.

HMC5883L Connection to Arduino:

Arduino i2c Scanner and Multiple i2c Sensors

  • Arduino GND -> HMC5883L GND
  • Arduino 3.3V -> HMC5883L VCC
  • Arduino A4 (SDA) -> HMC5883L SDA
  • Arduino A5 (SCL) -> HMC5883L SCL


HMC5883L Arduino Code:

The libraries used in this program can be downloaded by clicking on the following link.

Download libraries

About the BMP180 i2c supported Sensor:

The BMP180 Barometric Pressure Sensor is one of the most commonly used Sensors throughout the world. This Sensor is often used in student’s projects. With the help of the BMP180 Barometric Pressure Sensor which is an i2c supported Sensor, we can find the Temperature, Pressure and Altitude. I have already used this Sensor in an IoT based project using Nodemcu ESP8266 Wifi module and Blynk application. You can find link in the related projects section. The BMP180 i2c supported Sensor interfacing with the Arduino is very simple. We need only two wires to connect this sensor with the Arduino Uno. Let’s have a look at the following Connection diagram.



BMP180 Sensor connection to Arduino:

Arduino i2c Scanner and Multiple i2c Sensors

BMP180 Arduino Uno Code:

So now that I have explained the connection of both the Sensors with the Arduino Uno and I also share the codes. Now it’s time to combine both the projects. As both the Sensors HMC5883L and BMP180 supports the i2c communication. So, both the sensors can be connected with Arduino’s pins A4 and A5. Connect the SDA pins of both the sensors with the A4 of the Arduino Uno and also connect the SCL pins of both the Sensors with the A5 pin of the Arduino Uno.


Multiple i2c devices Arduino code:

Before you start the programming first of all, make sure you download the libraries, these libraries can be downloaded by clicking on the following link.

Download Libraries

This program is the combination of the programs given above. We don’t need to use the addresses of the modules; this task has already been done by the programmers, now we only need to use these libraries.


Watch Video for the Practical Demonstration:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button