KY-053

By appropriate commands on the I2C bus, analog voltage values can be measured on up to 4 inputs with up to 16-bit accuracy. The measurement result is output coded on the I2C bus.

Technical data

Interface I2C
ADC channels 4
Resolution per Channel 16 Bit
Programmable sampling rate 8 to 860 SPS
Operating Voltage 2 V to 5.5 V
Analog Input Voltage 0 V to Operating Voltage
I2C logic voltage 0 V to 5.5 V
I2C Address (Configurable by Jumper) 0x48 to 0x4B
Typical Operating Current 150 μA

A corresponding library is required for this module - see code examples below.

Changing the I2C address

This analog to digital converter (or in short ADC) has not only one I2C address. This is an ADC which can have 4 different I2C addresses. These can be chosen freely but in the further course the standard address 0x48 is used.

In the following table you can see all possible addresses and how they can be reached. Here is mainly to note that the ADDR pin of the ADC is responsible for the change of the address.

From To Address
ADDR Pin GND Pin 0x48
ADDR Pin VDD Pin 0x49
ADDR Pin SDA Pin 0x4A
ADDR Pin SCL Pin 0x4B

Pin assignment

The pin assignment is printed on the module board

Code example Arduino

Pin assignment Arduino

Arduino Sensor
5V + V
Ground GND
Pin A5 SCL
Pin A4 SDA
- ADDR
- ALRT
- A0
- A1
- A2
- A3

The Arduino boards already have an integrated 10 bit ADC with 6 channels. If more channels, or a higher accuracy, are needed, the Arduino can be extended by 4 ADC channels with 12-bit accuracy using the KY-053 Analog Digital Converter Module.

There are several ways to control this module - the ADS1X15 libraries have proven to be particularly accessible; they are available from Adafruit at https: / /github.com/adafruit/Adafruit_ADS1X15 under the BSD license .

The example below uses this library - we recommend downloading it from Github, unpacking it and placing it in the Arduino library folder, which is located by default under (C: \ Users \ [username] \ Documents \ Arduino \ libraries), so that it is available for this code example and the following projects. Alternatively, this is also included in the download package below.

#include <Adafruit_ADS1X15.h>
#include <math.h>
 
// ADS1115 module is initialized - all subsequent operations with the ADC
// can be executed with the help of the "ads" object.
Adafruit_ADS1115 ads;
 
void setup (void)
{
  Serial.begin (9600);
   
  Serial.println ("Values of the analog inputs of the ADS1115 (A0..A3) are read out and output");
  Serial.println ("ADC Range: +/- 6.144V (1 bit = 0.1875mV)");
   
  // This module has signal amplifiers at its analog inputs, whose
  // Gain can be configured via software in the areas below
  // can.
  // This is required when a certain voltage range
  // is expected as the measurement result and thus a higher resolution of the signal
  // receives.
  // Gain = [2/3] is selected as the standard gain and can be commented out
  // be switched to a different gain.
  // ADS1115
  // -------
  // ads.setGain (GAIN_TWOTHIRDS); // 2 / 3x gain +/- 6.144V 1 bit = 0.1875mV
  // ads.setGain (GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 0.125mV
  // ads.setGain (GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 0.0625mV
  // ads.setGain (GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.03125mV
  // ads.setGain (GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.015625mV
  // ads.setGain (GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.0078125mV
   
  ads.begin ();
}
 
void loop (void)
{
  uint16_t adc0, adc1, adc2, adc3;
  float voltage0, voltage1, voltage2, voltage3;
  float gain_conversion_factor;
   
  // The "ads.readADC_SingleEnded (0)" command is the actual operation that starts the measurement in the ADC.
  // the "0" as a variable for this function defines the channel used that is to be measured
  // If, for example, the third channel is to be measured, this must be replaced with the "3"
  adc0 = ads.readADC_SingleEnded (0);
  adc1 = ads.readADC_SingleEnded (1);
  adc2 = ads.readADC_SingleEnded (2);
  adc3 = ads.readADC_SingleEnded (3);
   
  // Conversion of the recorded values into a voltage
  voltage0 = ads.computeVolts(adc0);
  voltage1 = ads.computeVolts(adc1);
  voltage2 = ads.computeVolts(adc2);
  voltage3 = ads.computeVolts(adc3);
   
  // Output of the values to the serial interface
  Serial.print ("Analog input 0:"); Serial.print (voltage0); Serial.println (" V");
  Serial.print ("Analog input 1:"); Serial.print (voltage1); Serial.println (" V");
  Serial.print ("Analog input 2:"); Serial.print (voltage2); Serial.println (" V");
  Serial.print ("Analog input 3:"); Serial.print (voltage3); Serial.println (" V");
  Serial.println ("------------------------");
   
  delay (1000);
}

Sample program download

KY053-Arduino.zip

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
3.3 V + V
Ground GND
GPIO 2 [pin 3] SCL
GPIO 3 [pin 5] SDA
- ADDR
- ALRT
- A0
- A1
- A2
- A3

Unlike the Arduino, the Raspberry Pi has neither analog inputs nor an integrated analog-digital converter. This limits the Raspberry Pi when using analog sensors. To still use analog sensors on the Raspberry Pi, the Raspberry Pi can be extended by 4 ADC channels with 12-bit accuracy with our KY-053 Analog Digital Converter Module.

The program uses the corresponding ADS1x15 and I2C Python libraries from Adafruit to control the ADS1115 ADC. These were found under the following link https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 under the MIT license released. The required libraries are ** not ** included in the download package below.

You can install this library with the following command:

sudo pip3 install adafruit-circuitpython-ads1x15

To enable communication between the ADC and the Raspberry Pi, the I2C interface of the Raspberry Pi must also be activated. To do this, open the config.txt file via the following command:

sudo nano /boot/config.txt

Add the following line to the end of the file:

dtparam = i2c_arm = on

Save the file with the key combination [CTRL+O], confirm with [Enter] and exit the editor with the key combination [CTRL+X].

Additionally the installation of the I2C libraries is necessary. Install them via the following command...

sudo apt-get install python3-smbus i2c-tools -y

...and then perform a reboot afterwards:

sudo reboot

After this, the following Python code example can be used:

sudo nano ADS1115.py
#! / usr / bin / python
# coding = utf-8
 
################################################# ################################################# #########
### Copyright by Joy-IT
### Published under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
### Commercial use only after permission is requested and granted
###
### KY-053 Analog Digital Converter - Raspberry Pi Python Code Example
###
################################################# ################################################# #########
import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Create the I2C bus
i2c = busio.I2C (board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1115 (i2c)

# Create single-ended input on channels
chan0 = AnalogIn (ads, ADS.P0)
chan1 = AnalogIn (ads, ADS.P1)
chan2 = AnalogIn (ads, ADS.P2)
chan3 = AnalogIn (ads, ADS.P3)



while True:
    print ("channel 0:", "{:> 5} \ t {:> 5.3f}". format (chan0.value, chan0.voltage))
    print ("channel 1:", "{:> 5} \ t {:> 5.3f}". format (chan1.value, chan1.voltage))
    print ("channel 2:", "{:> 5} \ t {:> 5.3f}". format (chan2.value, chan2.voltage))
    print ("channel 3:", "{:> 5} \ t {:> 5.3f}". format (chan3.value, chan3.voltage))
    print ("----------------------------------------------- ---- ")
    time.sleep (1)

The library also includes a code example. You can see this on the website: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/tree/main/examples

The Python script must be run with Python 3.

Sample program download

KY053-RPi.zip

To start with the command

sudo python3 KY053.py

Extended functions of the ADS1115 ADC

The function of the ADS1115 used in the code examples above is called Single Ended Conversion and means that a measurement is made on the single selected channel against ground.

In addition to this type of measurement, the ADS1115 ADC also has the differential measurement function, so that a differential voltage between two inputs is measured (example: voltage between A0 and A1). In addition to the single-ended measurement, the comparator function can also be activated, which only provides a measurement result when a voltage threshold is exceeded.

These functions are programmed into the Adafruit Libraries for configuration - see the Adafruit Libraries documentation for details.