Tutorial – Using an Analog to Digital Converter with your Raspberry Pi
Happy Holidays from SwitchDoc Labs. In this tutorial, we are going to have a lot of fun. Did you ever want to read a voltage (rather than a 1 or 0) on your Raspberry Pi? You can do this with an Analog to Digital Converter.
Have you ever wanted to read analog (voltage level) levels and sensors on your Raspberry Pi? While you can read digital sensors with the Raspberry Pi, there is no built in analog to digital converter on your Raspberry Pi.
In this Tutorial, you will learn how use an 4 Channel 16 bit Analog to Digital Converter (ADC) on your Raspberry Pi.
There are many different reasons to read analog signals. Here are some examples:
What is the supply voltage on my Raspberry Pi?
What is the voltage on that resistor?
What is the O2 Level by reading the analog O2 sensor?
The Four Parts to this TutorialPart 1 - Overview of the ADC Raspberry Pi Project
Part 2 - Hooking up the Hardware
Part 3 - The ADC Raspberry Pi Project Software
Part 4 - Two Really Cool Experiments with the ADC Raspberry Pi
In This Tutorial
We are going to show you how to read these four sensors:
- An O2 (Oxygen Gas Sensor)
- An analog light sensor (light variable resistor)
- An analog air quality sensor
- A voltage divider connected to 5V on the Raspberry Pi
In order read these devices, we are going to use a Grove connector based 4 Channel 16bit ADC board. Why Grove Connectors? They are easy to attach correctly and quickly to other Grove sensors and devices. We are also going to use a board, the Pi2Grover which easily allows us to connect Grove devices (the 4 Channel 16 bit ADC Board in this case) to the Raspberry Pi.
What are Grove Connectors?
Grove connectors are a standardized way of hooking up devices to Raspberry Pi and Arduino devices. They are polarized and cannot be plugged in backwards. Reduces additions to the Box Of Death.
There are four types of Grove connectors: I2C, Digital, Analog and Serial. In this tutorial we are going to use an I2C connection between the Raspberry Pi and the 4 Channel ADC board, and four Analog Grove connectors between the 4 Channel ADC Board and all the respective sensors. We will also use one jumper wire to test the Raspberry Pi power voltage.
Note: all Grove connectors look physically the same. The key is what they are designed for. They are not reversible and if you plug a Grove cable into an Analog port and then into a Digital port by mistake, no problem and no fire! It just won’t work and won’t damage anything, Like magic.
The Parts List
- – Pi2Grover Raspberry Pi to Grove Interface Board (SwitchDoc Store and Amazon)
- – Grove 4 Channel 16 Bit ADC Board (SwitchDoc Store and Amazon)
- – Grove Light Sensor (Amazon and seeedstudio.com – any of the light sensor versions will work)
- – Grove O2 Oxygen Sensor (Amazon and seeedstudio.com)
- – Grove Voltage Divider (Amazon )
- – Grove Air Quality Sensor (SwitchDoc Store – includes Grove 4 Channel ADC board and hub )
What are These Parts?
Pi2Grover Raspberry Pi to Grove Interface Board
The Pi2Grover board provides 15 Grove connectors. 10 Grove Digital, 4 Grove I2C, and one Grove UART. Fast prototyping with many, many Grove devices available. No software drivers required. You are right next to the hardware.
It plugs right into your Raspberry Pi with a special connector that allows you to plug boards or hats on top of the Grove board.
Grove 4 Channel 16 Bit ADC Board
This is the missing board for a Raspberry Pi. It is an 16 bit 4 channel ADC for the Raspberry Pi (based on the industry standard ADS1115). 3.3V and 5V compatible and uses Grove connectors. It has four 16 bit Analog to Digital Channels that can be programmed in many different ways.
Grove Light Sensor
The Grove – Light Sensor (P) v1.1 uses the LS06-S phototransistor. The LS06-S light sensor has much more linear analog output conforming to illuminance, which ranges from 0 to the supplying voltage (normally 5V). A value equals to the supplying voltage can be detected when it’s exposed to daylight, and it gives 0V when you covered it with your hand.
Grove O2 Oxygen Sensor
The Grove-Gas Sensor (O₂) is a sensor to test the oxygen concentration in air. You can detect the current oxygen concentration and it outs pus voltage values proportional to the concentration of oxygen. You can interpret these numbers by referring to the oxygen concentration linear characteristic graph.
This sensor value only reflects the approximate trend of gas concentration in a permissible error range, it DOES NOT represent the exact gas concentration. The detection of certain components in the air usually requires a more precise and costly instrument, which can not be done with a single gas sensor. This sensor also requires about a 30 minute warm up time.
Grove Voltage Divider
The Grove – Voltage Divider provides an method for measuring an external voltage via a buffered voltage divider. It will divide the input by a factor of 3 or 10 (switch selectable) and will protect your computer from too high of voltage (> 3.3V or 5V depending on your power). It also warns you of an over voltage situation by turning on an LED. For you more experienced folks, the input resistance to this device varies from 300K ohms (when using the 10) to about 100K ohms (when using the 3). Nice little addition to your testing lab.
Grove Air Quality Sensor
The Air Quality Extender Kit works by measuring a wide scope of harmful gases such as carbon monixide, alcohol, acetone, thinner, formaldehyde and so on as well as being sensitive to particulate count. Due to the method used to measure the contaminants, this Air Quality sensor can not output specific data to describe target gases’ concentrations quantitatively. But it’s still good enough to be used to describe qualitative air quality. The Air Quality sensor requires a warm up time of about 2 minutes after power on before it will be reporting good data. The Air Quality sensor is based on a Winsen MP503 Air-Quality Gas Sensor. This sensor is designed for indoor use but can be used outdoors if it is covered and protected from high humidity.
The AirQuailty sensor reports a single analog voltage describing the overall air quality. We take this analog value and convert it to a digital reading (from 0 to about 65000). The OurWeather software then interprets this number and reports the qualitative air quality. Following is digital reading and the qualitative interpretation:
Now you know all about the hardware, Part 2 shows how to wire all these parts up. Part 3 will show all the software and show you the results!
Looking For A Specific Topic?
Recent Blog Posts
- Guest Blog – Tutorial: Repairing an Anemometer in the WeatherRack
- Guest Blog – Smart Garden System 3D Printed Top for Sensors
- Tutorial – Part 4 – Experiments! Using an Analog to Digital Converter with your Raspberry Pi
- Tutorial – Part 3 – Using an Analog to Digital Converter with your Raspberry Pi
- Tutorial – Part 2 – Using an Analog to Digital Converter with your Raspberry Pi