KY-053 Analog Digital Converter
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.
- Arduino
- Raspberry Pi
- Raspberry Pi Pico
- Micro:Bit
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 | 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 |
GND | 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 16-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
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 | 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 Raspberry Pi
Pin assignment Raspberry Pi
Raspberry Pi | Sensor |
---|---|
3.3 V | + V |
GND | 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 16-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.
First you need to enable I2C on your Raspberry Pi. To open the configuration, enter the following command:
sudo raspi-config
Select 3 Interface Options → I4 I2C and activate the I2C interface. You have now successfully activated I2C. The analog-to-digital converter can now be reached under the I2C address 0x48, which is set by default for this sensor. The I2C address will be different if you have already configured it before configuring your Raspberry Pi.
Now install pip3 with the following command:
sudo apt-get install python3-pip
The next step is to set up the virtual environment. To do this, enter the following commands:
mkdir dein_projekt
cd dein_projekt
python -m venv --system-site-packages env
source env/bin/activate
Use the following commands to download and install the adafruit-circuitpython-ads1x15 library.
pip3 install adafruit-circuitpython-ads1x15
After you have downloaded the library, you only need to enter the following command...
nano ADS1115.py
... to create a new file on your Raspberry Pi and then copy the following code into the file you have just created.
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)
Sample program download
To start with the command
sudo python3 KY053.py
Advanced ADS1115 functions
The ADS1115 function used in the code examples presented above is called "Single Ended Conversion" and indicates that a measurement is performed on the single channel selected with respect to ground.
In addition to this type of measurement, the ADS1115 ADC also features, for example, a differential measurement function, so that a differential voltage between two inputs is measured (e.g. voltage between A0 and A1). In addition to one-sided measurement, a comparator function can be activated, which provides a measurement result only when a voltage threshold is exceeded.
These and other functions, such as changing the sampling rate, are programmed in the Adafruit libraries for configuration - see the Adafruit library documentation for details.
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 | 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 Micro:Bit
Pin assignment Micro:Bit
Micro:Bit | Sensor |
---|---|
3,3 V | +V |
GND | GND |
Pin 19 | SCL |
Pin 20 | SDA |
- | ADDR |
- | ALRT |
- | A0 |
- | A1 |
- | A2 |
- | A3 |
The Micro:Bit already has an integrated 10-bit ADC. If more channels or higher accuracy are required, the Micro:Bit can be extended by 4 ADC channels with 16-bit accuracy using the KY-053 Analog Digital Converter Module.
For control we recommend the use of the pxt-ads1115 library, which was published by us under the MIT license.
You can add the library by going to the Makecode page, clicking on Extensions, and then typing ADS1115 in the search bar. After you do that, all you have to do is click on the extension to add it automatically to your current project.
Sample program download
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 to 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 | 0x48 to 0x4B |
Typical operating current | 150μA |
Change 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
Code example Raspberry Pi Pico
Pin assignment Raspberry Pi Pico
Raspberry Pi Pico | Sensor |
---|---|
3,3 V | +V |
GND | GND |
GPIO1 | SCL |
GPIO0 | SDA |
- | ADDR |
- | ALRT |
- | A0 |
- | A1 |
- | A2 |
- | A3 |
The Raspberry Pi Pico already has an integrated 12-bit ADC. If more channels or a higher accuracy are needed, the Raspberry Pi Pico can be extended by 4 ADC channels with 16-bit accuracy using the KY-053 Analog Digital Converter Module.
For control we recommend the use of the ADS1115-Micropython library, which was published by us under the MIT license .
This code example reads channel 0 and returns the read data as analog value and as calculated voltage.
# Load libraries
import machine
import ADS1115
import sys
from time import sleep
# Variables initialization
chan = 0
if __name__ == '__main__':
try:
# Initialization of the ADC
ADS1115.init(0x48, 3, 4, False)
print("start")
while True:
# Output of the data from channel 0 of the ADC
print(ADS1115.read(chan))
# Output of the read out and converted data of channel 0 of the ADC
print(str(ADS1115.raw_to_v(ADS1115.read(chan))) + " V")
sleep(1)
except KeyboardInterrupt:
sys.exit()