KY-053

With the appropriate commands on the I2C bus, analog voltage values can be measured with up to 16-bit accuracy on up to 4 inputs. The measurement result is coded and output 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 2V to 5.5V
Analog Input Voltage 0V to Operating Voltage
I2C logic voltage 0V to 5.5V
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.

Pin assignment

The pin assignment is printed on the module board

Code example Arduino

Pin assignment Arduino

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

The Arduino boards have a 10-bit ADC with 6 channels. However, if you need more channels or higher accuracy, you can expand the Arduino by 4 ADC channels with 12-bit accuracy using the KY-053 Analog Digital Converter Module, which is connected to the Arduino via I2C.

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 "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);
   
  // This value is required for the conversion into a voltage - this depends on the set amplification.
  // The appropriate value for the gain should be taken from the table above
  gain_conversion_factor = 0.1875;
   
  // Conversion of the recorded values into a voltage
  voltage0 = (adc0 * gain_conversion_factor);
  voltage1 = (adc1 * gain_conversion_factor);
  voltage2 = (adc2 * gain_conversion_factor);
  voltage3 = (adc3 * gain_conversion_factor);
   
  // Output of the values to the serial interface
  Serial.print ("Analog input 0:"); Serial.print (voltage0); Serial.println ("mV");
  Serial.print ("Analog input 1:"); Serial.print (voltage1); Serial.println ("mV");
  Serial.print ("Analog input 2:"); Serial.print (voltage2); Serial.println ("mV");
  Serial.print ("Analog input 3:"); Serial.print (voltage3); Serial.println ("mV");
  Serial.println ("------------------------");
   
  delay (1000);
}

Sample program download

KY053-Arduino.zip

Code example Raspberry Pi

Pin assignment Raspberry Pi

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

In contrast to the Arduino, the Raspberry Pi has no analog inputs or there is no ADC (analog digital converter) integrated in the Raspberry Pi chip. This limits the Raspberry Pi if you want to use sensors where digital values are not output [voltage value exceeded -> digital ON | Voltage value fallen below -> digital OFF | Example: button pressed [ON] button released [OFF]], but it should be a continuously variable value (example: potentiometer -> other position = different voltage value)

In order to avoid this problem, our X40 sensor kit has the KY-053, a module with 16-bit ADC, which you can use on the Raspberry to expand it with 4 analog inputs. This is connected to the Raspberry Pi via I2C, takes over the analog measurement and digitally forwards the value to the Raspberry Pi.

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

The program reads out the current voltage that is present on the 4 channels of the ADS1115 ADC and displays it on the console. The pause between measurements can be set using the "delayTime" variable.

So that the Raspberry Pi can communicate with the sensor on the I2C bus, the I2C function on the Raspberry Pi must be activated in advance. To do this, the following lines must be added to the end of the "/boot/config.txt" file:

dtparam = i2c_arm = on

The file can be edited with the following command:

sudo nano /boot/config.txt

After saving, restart the system so that I²C is activated correctly:

sudo reboot

With the key sequence [Ctrl + X -> Y -> Enter] the file can be saved and closed after adding the line at the bottom.

Additional libraries are also required to use I2C within Python. To install this, the following command must be entered in the console:

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

The following Python code example can then be used:

To do this, create a new file and then copy the example into the file:

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, which is used in the code examples shown above, is called "Single Ended Conversion" and means that a measurement is made on the individually selected channel to ground. In addition to this type of measurement, the ADS1115 ADC also has, for example, the function of differential measurement, so that a differential voltage is measured between two inputs (example: voltage between A0 and A1). In addition to the single-ended measurement, the comparator function can also be activated, which only delivers a measurement result when a voltage threshold is exceeded.

These functions and functions, such as changing the sample rate, are programmed into the Adafruit Libraries for configuration - see the Adafruit Libraries documentation for more information.