Example Code for Arduino-Read Data Using I2C

This project demonstrates how to read the voltage value of channel 1 from the Gravity: 0-10V 15-bit High Precision Dual Channel ADC Module using I2C communication with an Arduino UNO controller. Users will learn how to wire the module via I2C, install the required library, and use sample code to obtain voltage data.

Hardware Preparation

  • DFRduino UNO Controller x1
  • DFR1184 Gravity:2-Channel 15Bit 0-10V ADC Module x1

Software Preparation

Wiring Diagram

I2C address table:

A1 A0 ADDR
0 0 0x48
0 1 0x49
1 0 0x4A
1 1 0x4B

Other Preparation Work

  1. Connect the module to the UNO controller according to the wiring diagram above. You can also use an expansion board for easier prototype construction.
  2. Turn the selector switch on the sensor to the I2C side (default I2C address is 0x48).
  3. Download and install the DFRobot_ADS1115 Library.
  4. Note: Switch off the power when switching the toggle switch.

Sample Code

#include <DFRobot_ADS1115_0_10V.h>
#define I2C_COMMUNICATION 
#define MODULE_I2C_ADDRESS 0x48
DFRobot_ADS1115_I2C ads1115(&Wire, MODULE_I2C_ADDRESS);

void setup() {
    Serial.begin(9600);
    while (!ads1115.begin()) {
        Serial.println("Error, check connection!");
        delay(1000);
    }
}

void loop() {
    double data;
    const unsigned char channel = 1;
    
    data = ads1115.getValue(channel);
    Serial.print("channel:");
    Serial.print(channel);
    Serial.print(" adValue:");
    Serial.print(data);
    Serial.println("mv");
    
    delay(1000);
}

Result

Open the serial monitor of the Arduino IDE, adjust the baud rate to 9600, and observe the serial print results to get the voltage value input from channel 1.

Switch off the power when switching the toggle switch.**

Was this article helpful?

TOP