Tag Archives: ADC

Build Your Own I2C Sensor

Since Raspberry Pi doesn’t have a built-in ADC (Analog to Digital converter) to read the voltage off from most of sensors, the best solution is to add I2C ADC chips and modules to your project.

Paweł Spychalski faced this problem while building his own weather station that is based on Raspberry Pi. It collects various data and displays them on dedicated web page and Android app. Every few months he tries to add a new sensor to it. Last time it was a daylight sensor. He added this sensor to his system by using ATtiny85 and it was connected via I2C bus.

ATtiny85 is a member of Atmel tinyAVR series which has 8-bit core and fewer features, fewer I/O pins, and less memory than other AVR series.

The Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips. Like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device. Like Asynchronous Serial Interfaces (such as RS-232 or UARTs), it only requires two signal wires to exchange information.

I2C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.

Sample Inter-Integrated Circuit (I²C) schematic with one master (a microcontroller) and three slave nodes

Most of developers use I2C to connect to sensors with the help of the Arduino “Wire” library or “i2c-tools” on the Pi, but it is rare to see someone that is actually building the I2C slave device. Paweł’s project uses TinyWireS library, a slave-mode SPI and I2C library for AVR ATtiny Arduino projects.

This diagram shows how to build analog to digital converter using ATtiny85 and connect it to any device (Raspberry Pi, Arduino) using I2C bus. Here photoresistor has been used, but any analog meter will be fine: temperature, potentiometer, moisture…

ATtiny85 directly connected to Raspberry Pi via I2C, photoresistor with 10kOhm pull down connected to ATtiny85 and signal LED.

ATtiny85 directly connected to Raspberry Pi via I2C, photoresistor with 10kOhm pull down connected to ATtiny85 and signal LED.

For reading data you can use this code. ATtiny sends current measurement as two 8 bit value. First older bits, then younger 8 bits.

Wire.requestFrom(0x13, 2);    // request 2 bytes from slave device #0x13

int i =0;
unsigned int readout = 0;

while (Wire.available()) { // slave may send less than requested
 byte c = Wire.read(); // receive a byte as character

 if (i == 0) {
  readout = c;
 } else {
  readout = readout << 8;
  readout = readout + c;



To do this project you need to use Arduino IDE 1.6.6., TinyWireS library,ATtiny45/85 board, plus an 1MHz internal oscillator.

Watchdog timer interrupts ATtiny every few minutes, measures voltage, filters it and stores in memory. Every time read operation is requested, last filtered ADC value (10 bits as 2 bytes). I2C support is provided by TinyWireS library that configures ATtiny USI (Universal Serial Interface) as I2C slave.

* This function is executed when there is a request to read sensor
* To get data, 2 reads of 8 bits are required
* First requests send 8 older bits of 16bit unsigned int
* Second request send 8 lower bytes
* Measurement is executed when request for first batch of data is requested
void requestEvent() {

 if (reg_position >= reg_size) {
  reg_position = 0;

* Setup I2C
TinyWireS.onRequest(requestEvent); //Set I2C read event handler


Bright by day, dark by night
Bright by day, dark by night

This cool weather station and its need of daylight sensor is only an example. The amazing thing is that you can now build new I2C sensors and introduce new modules to your projects easily following Paweł’s steps.

For more details about this project you can check Github and the weather station website.

Adding ADC to Microcontrollers without ADC


@ swharden.com show us how to interface an analog signal to a microcontroller that doesn’t have an ADC.

I recently had the need to carefully measure a voltage with a microcontroller which lacks an analog-to-digital converter (ADC), and I hacked together a quick and dirty method to do just this using a comparator, two transistors, and a few passives. The purpose of this project is to make a crystal oven controller at absolute minimal cost with minimal complexity. Absolute voltage accuracy is not of high concern (i.e., holding temperature to 50.00 C) but precision is the primary goal (i.e., hold it within 0.01 C of an arbitrary target I set somewhere around 50 C).

Adding ADC to Microcontrollers without ADC – [Link]

How To Connect Multiple Buttons with MCU Using One Line

One of the biggest problems you could face in your current/next project, is when you’re out of free inputs to use.
Sometimes you can save a lot of inputs using some tricks, and there’re really a lot of them.
In this blog post we’re going to know how you can use many push buttons using only one analog input pin. John Boxall from tronixstuff.com demonstrates how we can do that.

Almost all MCUs come with an ADC unit, which is responsible to convert the voltage from an analog value to a digital one (digitizing), for example Arduino UNO, which uses Atmega328 MCU, has an 8-bit ADC.

ADCs convert the voltage to a number (level), so a 8-bit resolution ADC converts Vin to 256 levels.
By using this fact, we can build a voltage divider using a resistor for each button, using one ADC line and recognize each button.

John used Arduino UNO to implement this hack. He used one of the ADC lines, enabled its internal pull-up resistor and connected the buttons and resistors to it, as shown in the following diagram.

Images courtesy of tronixstuff

So now every button has a unique ADC value as the following:

  • 1023 for nothing pressed (default state).
  • 454 for button one.
  • 382 for button two.
  • 291 for button three.
  • 168 for button four.
  • 0 for button five.

To see the full details of this hack, and to get the source files, you can refer to tronixstuff website.

How to use a fully differential amplifier as a level shifter

7446.Figure 1.PNG-1230x0

Loren Siebert @ ti.com discuss about how to interface signals that have a reference voltage that isn’t 0V while preserving the DC information.

Many signal paths are direct current (DC)-coupled, and this can lead to challenges when different portions of the signal path require different operating conditions. Many portions of a signal path are ground-referenced, where a signal varies at about an average or mid value of 0V. If all signals had the same reference voltage, DC coupling would be very easy. Unfortunately, that is not the case. Devices operating from a single supply like mixers or analog-to-digital converters (ADCs) will typically have a reference voltage (common mode) that is not 0V. Interfacing these devices while preserving DC information can be challenging.

How to use a fully differential amplifier as a level shifter – [Link]

Analogue Sensors – Calculate the Nonlinearity Introduced by a Load or Pull Down Resistor


Tecwyn Twmffat @ instructables.com discuss about the notlinearity introduced by adding a pull down resistor and why you may get unpredictable readings from your ADC.

For many years I found that I would get strange, unpredictable, readings from my sensor related projects at the maximum and minimum locations when using analogue digital convertors (ADCs). I always blamed this on poorly designed micro processors and never for once thought that it might be my own circuit designs at fault ….. until now.

Analogue Sensors – Calculate the Nonlinearity Introduced by a Load or Pull Down Resistor – [Link]

Simple circuit provides precision ADC interface


Moshe Gerstanhaber @ edn.com provides an simple ADC interface using instrumentation amplifier IC.

Real-world measurement requires the extraction of weak signals from noisy sources. High common-mode voltages are often present even in differential measurements. The usual approach to this problem is to use an op amp or an instrumentation amplifier and then perform some type of lowpass-filtering to reduce the background noise level.

Simple circuit provides precision ADC interface – [Link]

Automatic monitor brightness controller


Dilshan Jayakody build a auto monitor brightness controller that adjusts your monitor brightness according to lighting conditions. He writes:

The sensor unit of this system is build around PIC18F2550 8-bit microcontroller. To measure the light level we use LDR with MCU’s inbuilt ADC. The control software of this unit is design to work with Microsoft Windows operating systems and it use Windows API’s DDC/CI related functions to control the monitors/display devices.

Automatic monitor brightness controller – [Link]

Analog Devices AD587KN 10V reference chip


SteelCity Electronics published an article about Analog Devices AD587KN 10V reference:

I recently got hold of an Analog Devices AD587KN high precision 10.000V reference chip.
This model of chip has an output value of 10.000V ± 5mV (that is, an output value of 9.995V to 10.005V) straight out of the factory. A voltage drift of 10ppm/°C at 25°C meaning that the output voltage will drift by 10μV for each 1°C the chip is exposed to. Additionally, the chip has a voltage trim input, so if you have access to a precision voltmeter, the chip’s output value can be adjusted even closer to 10.000V.
Alternatively, the chip’s output can be trimmed to a value of 10.24V. You may think that a value of 10.24V seems like a strangely familiar number. A value of 1024 is the decimal representation of 10bits, that is 2∧10 = 1024. Why would I want a voltage reference that outputs a value of 10.24V? Because it makes any ADC or DAC conversions much simpler.

Analog Devices AD587KN 10V reference chip  – [Link]

DIY milliohmmeter


by hwmakers.eu:

This is an example of a simple and cheap milliohmmeter that can be made by every maker. The core of the circuit are a current source (LT3092) and a current sense (INA225): a costant current flows through the milliohm resistor under test and the voltage at the current sense output gives the value of the resistor (V=R*I).

The milliohmmeter can be used as a stand alone instrument by adding a MCU with at least 10 bit ADC and a LCD display or it can be used togheter with a DMM.

DIY milliohmmeter – [Link]

TC7106 – 3 1/2 Digit ADC for LCD Display


The TC7106 3½ digit LCD direct-display drive analog-to-digital converter has a reference with a 80ppm/°C max temperature coefficient. TC7106 based systems may be upgraded without changing external passive component values to the TC7106A for a more precise system. High impedance differential inputs offer 1pA leakage current and a 1012 Ohm input impedance. The differential reference input allows ratiometric measurements for ohms or bridge transducer measurements. The 15µVp-p noise performance guarantees a great reading. The auto-zero cycle guarantees a zero display reading with a zero-volts input.

TC7106 – 3 1/2 Digit ADC for LCD Display – [Link]