Analog to Digital Converters – Tutorial – Using with your Raspberry Pi

Tutorial – Analog to Digital Converters used with your Raspberry Pi Analog to Digital Converters

Here is a set of quarantine experiments that you do at your house and really learn things about Analog to Digital Converters and the Raspberry Pi.   This is a tutorial on using analog to digital converters.

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?

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.

Analog to Digital Converters

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.

See our full Grove connector tutorial here.

The Parts ListAnalog to Digital Converters

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 BoardAnalog to Digital Converters

 

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:

Screen Shot 2016-04-18 at 5.26.29 PM

 

Hooking Up the Hardware

All of the connections (except for one jumper) are Grove connections.    All Grove Connections use the same Grove cable to connect from one to another.   Want to know more about Grove devices?   Check out the Grove Tutorial here.

 

 

 

Analog to Digital Converters

Wiring Table

From To Description
Pi2Grover / I2C 4 Channel ADC / I2C Grove Cable
4 Channel ADC / A0 Air Quality Sensor Grove Cable
4 Channel ADC / A1 O2 (Oxygen) Sensor Grove Cable
4 Channel ADC / A2 Light Sensor Grove Cable
4 Channel ADC / A3 Voltage Divider Grove Cable
Voltage Divider / VOL Raspberry Pi / Pin 2 on GPIO Header (5V) Jumper Cable

 

Following is the Grove Cable Diagram for this project.

Analog to Digital Converters

 

 

 

The Software

Analog to Digital ConvertersThis ADC board is based on the TI ADS1115 16 bit 4 channel I2C ADC.   Any software that supports the ADS1116 will work (either Arduino or Raspberry Pi) and this board supports 3.3V and 5V power supplies.   We are going to use two examples of Python Software to read the ADC devices.   The first is a simple test of the ADS1115 board, reading all the values, doing a little math and then printing the values out to the screen.   This test program is included in the Raspberry Pi DataLogger shown below.

The second piece of software is the Raspberry Pi DataLogger software that periodically samples all four channels and then builds graphs that can be displayed in a browser.

Installing the Raspberry Pi DataLogger

In order to run the testADS115.py program, we need to first install the Raspberry Pi DataLogger.   We will do this in four steps.  First, we will install the github archive of the DataLogger.   Secondly, we will run the testADS1115.py program.  Thirdly, we will install the rest of the DataLogger software, and finally, we will run the DataLogger to generate graphs for all four of the ADS1115 channels for our test project.

 

DataLogger Python Software

To install the DataLogger software do the following:

cd
git clone https://github.com/switchdoclabs/SDL_Pi_DataLogger.git

This installs the DataLogger software which includes the testADS1115.py software.   We will come back and install the rest of the DataLogger support software later.

Running the First Test of the ADS1115 setupAnalog to Digital Converters

In a terminal window on the Raspberry Pi, type the following:

cd 
cd SDL_Pi_DataLogger

Then, type the following command:

sudo python testADS1115.py

Remember in Part 2, we hooked up the following sensors:

  • – Channel 0 – Air Quality Sensor
  • – Channel 1 – Oxygen Sensor
  • – Channel 3 – Light Sensor
  • – Channel 4 – Voltage Divider hooked up to 5V on the Pi

If you have hooked up all the hardware correctly as in Part 2 of this tutorial, you should see something very similar to this:

--------------------
Channel 0 =0.171187V raw=914 raw=0x 392
Channel 1 =2.436375V raw=0x32C2 O2 Percent= 22.05
Channel 2 =2.577750V raw=0x35B6
Channel 3 =0.484875V raw=0x A1B
--------------------
--------------------
Channel 0 =0.171187V raw=911 raw=0x 38F
Channel 1 =2.436375V raw=0x32C2 O2 Percent= 22.05
Channel 2 =2.570625V raw=0x35B4
Channel 3 =0.484125V raw=0x A1A
--------------------
--------------------
Channel 0 =0.170813V raw=908 raw=0x 38C
Channel 1 =2.436375V raw=0x32C1 O2 Percent= 22.05
Channel 2 =2.574000V raw=0x360D
Channel 3 =0.483375V raw=0x A20
--------------------
--------------------
Channel 0 =0.171187V raw=908 raw=0x 38C
Channel 1 =2.436375V raw=0x32C2 O2 Percent= 22.05
Channel 2 =2.590500V raw=0x35E3
Channel 3 =0.485250V raw=0x A1F
--------------------
--------------------
Channel 0 =0.171750V raw=917 raw=0x 395
Channel 1 =2.436187V raw=0x32C1 O2 Percent= 22.05
Channel 2 =2.573437V raw=0x3611
Channel 3 =0.478875V raw=0x A1F
--------------------

 

Raspberry Pi 3

Installation of the Raspberry Pi Software

We will need to install the following three major software packages.   MySQL/phpMyAdmin/Apache web server, apscheduler, MatPlotLib and then the DataLogging Python software itself.

MySQL/phpMyAdmin/Apache

MySQL is used to store the data from the DataLogger software to provide a database that can be used for later analysis and graphing.   The phpMyAdmin software is used to setup and control the MySQL database server and finally Apache is used to serve phpMyAdmin webpages and the DataLogger graphs.

Installing MySQL/phpMyAdmin/Apache – Use the following excellent tutorial:  https://pimylifeup.com/raspberry-pi-mysql-phpmyadmin/

Apscheduler

apscheduler is a very good Python package that is used to schedule events from within a main Python program that run in different threads.  One good thing about running tasks like this in another thread, is that a hang in one of the threads does not stop the whole system.  Just that thread.

sudo pip install setuptools --upgrade 
sudo pip install apscheduler

MatPlotLib

MatPlotLib is a python library for making publication quality plots using methods similar to MATLIB on the Raspberry Pi. You can output formats such as PDF, Postscript, SVG, and PNG.

Install the following packages (This will take quite a while)

$ sudo apt-get install libblas-dev        ## 1-2 minutes
$ sudo apt-get install liblapack-dev      ## 1-2 minutes
$ sudo apt-get install python-dev        ## Optional
$ sudo apt-get install libatlas-base-dev ## Optional speed up execution
$ sudo apt-get install gfortran           ## 2-3 minutes
$ sudo apt-get install python-setuptools  ## ?
$ sudo easy_install scipy                 ## 2-3 hours

$ sudo apt-get install python-matplotlib  ## 1 hour

Now you have all the required software installed.

Two last things:

  1. If you have phpMyAdmin, go to the SQL Tab and copy the contents of DataLogger.sql into the MySQL Box and hit “Go” to build the database.  If not, use the following commands:
    example: mysql -u root -p < DataLogger.sql
    
    user: root
    
    password: password
    

    Obviously with these credentials, don’t connect port 3306 to the Internet. Change them if you aren’t sure.

  2. Copy DataLogger.html to /var/www/html:
sudo cp DataLogger.html /var/www/html

Now you are ready to go.

Running the ADC DataLogger

Now we are ready to run the full Analog to Digital DataLogger and look at some graphs of our data.

In a terminal window on the Raspberry Pi, type the following:

cd 
cd SDL_Pi_DataLogger

Then, let’s start the DataLogger.

sudo python DataLogger.py

The you should see something similar to this. If you have errors, go back and check your setup.

SDL_Pi_Datalogger

 Will work with the INA3221 SwitchDoc Labs Breakout Board
 Will work with the ADS1115 SwitchDoc Labs Breakout Board
 Will work with OurWeather - Complete Weather Kit
 Will work with SwitchDoc Labs WxLink Wireless LInk 
Program Started at:2017-01-03 09:14:07

readADS1115Data - The time is: 2017-01-03 09:14:07.021874
------------------------------
writing SQLdata 
query=INSERT INTO ADS1115Table(timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw) VALUES(CURRENT_TIMESTAMP(),  0,  0.166, 885, 2.440, 13014, 2.592, 13870, 0.485, 2588)
buildADS1115Graph0 - The time is: 2017-01-03 09:14:07.099378
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 40, 17), 0L, 0.196, 1046L, 2.419, 12899L, 0.645, 3429L, 0.486, 2589L, 391L)
('count of t=', 2000)
------ADS1115Graph0 finished now
buildADS1115Graph1 - The time is: 2017-01-03 09:14:11.459563
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 40, 17), 0L, 0.196, 1046L, 2.419, 12899L, 0.645, 3429L, 0.486, 2589L, 391L)
('count of t=', 2000)
------ADS1115Graph1 finished now
buildADS1115Graph2 - The time is: 2017-01-03 09:14:14.952826
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 40, 17), 0L, 0.196, 1046L, 2.419, 12899L, 0.645, 3429L, 0.486, 2589L, 391L)
('count of t=', 2000)
------ADS1115Graph2 finished now
buildADS1115Graph3 - The time is: 2017-01-03 09:14:19.056077
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 40, 17), 0L, 0.196, 1046L, 2.419, 12899L, 0.645, 3429L, 0.486, 2589L, 391L)
('count of t=', 2000)
------ADS1115Graph3 finished now
Jobstore default:
    readADS1115Data (trigger: interval[0:01:00], next run at: 2017-01-03 09:15:23 PST)
    tick (trigger: interval[0:01:00], next run at: 2017-01-03 09:15:23 PST)
    doAllGraphs (trigger: cron[minute='*/2'], next run at: 2017-01-03 09:16:00 PST)
    killLogger (trigger: interval[6 days, 22:40:00], next run at: 2017-01-10 07:54:23 PST)
Press Ctrl+C to exit
readADS1115Data - The time is: 2017-01-03 09:15:23.564634
------------------------------
Tick! The time is: 2017-01-03 09:15:23.582201
writing SQLdata 
query=INSERT INTO ADS1115Table(timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw) VALUES(CURRENT_TIMESTAMP(),  0,  0.170, 905, 2.438, 13003, 2.605, 13846, 0.485, 2585)
buildADS1115Graph0 - The time is: 2017-01-03 09:16:00.006283
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 41, 17), 0L, 0.197, 1049L, 2.419, 12903L, 0.647, 3438L, 0.486, 2590L, 392L)
('count of t=', 2000)
------ADS1115Graph0 finished now
buildADS1115Graph1 - The time is: 2017-01-03 09:16:03.053961
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 41, 17), 0L, 0.197, 1049L, 2.419, 12903L, 0.647, 3438L, 0.486, 2590L, 392L)
('count of t=', 2000)
------ADS1115Graph1 finished now
buildADS1115Graph2 - The time is: 2017-01-03 09:16:06.501289
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 41, 17), 0L, 0.197, 1049L, 2.419, 12903L, 0.647, 3438L, 0.486, 2590L, 392L)
('count of t=', 2000)
------ADS1115Graph2 finished now
buildADS1115Graph3 - The time is: 2017-01-03 09:16:09.982362
2000
query= (SELECT timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw, id FROM ADS1115Table ORDER BY id DESC LIMIT 2000) ORDER BY id ASC
(datetime.datetime(2017, 1, 1, 22, 41, 17), 0L, 0.197, 1049L, 2.419, 12903L, 0.647, 3438L, 0.486, 2590L, 392L)
('count of t=', 2000)
------ADS1115Graph3 finished now
readADS1115Data - The time is: 2017-01-03 09:16:23.568773
------------------------------
Tick! The time is: 2017-01-03 09:16:23.580755
writing SQLdata 
query=INSERT INTO ADS1115Table(timestamp, deviceid, channel0_voltage, channel0_raw, channel1_voltage, channel1_raw, channel2_voltage, channel2_raw, channel3_voltage, channel3_raw) VALUES(CURRENT_TIMESTAMP(),  0,  0.169, 903, 2.438, 13001, 2.617, 13879, 0.486, 2592)


And after a few minutes, open up a browser to:

https:///DataLogger.html and you will see graphs

Note: Replace with your local IP Number. You can find your local IP number by typing:

ifconfig

Then you can read your IP number from the appropriate interface (the wlan0 in our case – 192.168.1.62 as below).

eth0      Link encap:Ethernet  HWaddr b8:27:eb:2c:33:13  
          inet6 addr: fe80::b6db:516d:7659:b6f9/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:121546 errors:0 dropped:0 overruns:0 frame:0
          TX packets:121546 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:12010576 (11.4 MiB)  TX bytes:12010576 (11.4 MiB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:79:66:46  
          inet addr:192.168.1.62  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe79:6646/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1418961 errors:0 dropped:122860 overruns:0 frame:0
          TX packets:781759 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:240284835 (229.1 MiB)  TX bytes:386959850 (369.0 MiB)

Here are our graphs after running overnight. Note that the Air Quality varies, the O2 is flat (as expected), you can see the lights being turned on and off in the Laboratory and you can see the Voltage divider switch being moved from divide by 10 to divide by 3 and back again.

Analog to Digital

 

Analog to Digital

Experiments!

We are showing two experiments.   The first is a complete documented  test of the Air Quality sensor and the second is burning a candle in a glass bowl to see what the Oxygen percent goes down to before the candle burns out.

Air Quality Sensor Test

It is always interesting to know what is going on in your indoor environment.   With that in mind, the gremlins at SwitchDoc Labs decided it was time to test out the Air Quality sensor and see just how sensitive it is.   After running the whole ADC for a while at the Labs, our CTO said he would take it home for the weekend and try it out in the home environment.   His results were interesting and showed that the unit was a lot more sensitive than we initially expected.

The chip on the Air Quality Sensor is a TP-401A.

What is the TP-401A?

Air Quality Sensor TestThe TP-401A sensor is very sensitive to a number of air-contaminating substances at low concentrations.   Some of these are:   Second hand smoke, carbon monoxide (CO), alcohol, volatiles of cosmetics (especially hair spray as we will see later), acetone, thinner, insecticides, benzene, formaldehyde, etc.

The sensor is composed of SnO2 materials doped with a catalyst making it a metal oxide semiconductor type of gas sensor.    The resistance of the sensor will decrease when there are contaminating gases and will increase when the gases are removed from the environment.   To operate the device needs to be heated to about 200-400 degrees C and this is what causes the current for this device to be about 50mA.   A typical response of the sensor to 20 ppm (parts per million) of CO  will to take the voltage up about 0.25V ~ 0.60V when the CO is detected.

The Results

 

Annotations from the Weekend at SwitchDoc Labs CTO House, all times in UTC (+8 Hours to Pacific Time):

A – Dryer Door opened, ironing begun.   Could smell fabric softener.

B – Door opened to outside first for Panther The Cat, then door left open for a while.   Finally dinner was cooked in oven.

F – Night time – ripples are probably auto fan and air conditioning effects.

C – Door opened for cat.  Cat slow to go out.  Very slow.

D – First hairspray test.   Short sets of hairspray in the bathroom – noted air conditioner was on.

E – Dinner was cooked.   Spinach Salad (with fresh Bacon bits).

F – Night again.

G – Hairspray in bathroom, this time the real thing as the family got ready for work.

We were amazed at how sensitive this inexpensive sensor was.   We could detect all sorts of events in the entire house.    One thing to point out is that virtually all of the time the sensor was under 3200 (rated fresh air) and the average was 2727 across the entire period.

We waited for the morning particulate count to drop and we ran one more test.  We decided to do the ultimate hairspray test and use the hairspray near the sensor to see how fast it would react and how bad it would conclude the air was.

 

Test findings?  The Air Quality System really does not like hairspray.    The hairspray was sprayed about 18 inches above the sensor and not directly into the sensor.   It peaked about 11,000 (High Pollution) and quickly trailed down in the next 15 minutes.

Conclusion of Air Quality Sensor Test

The Air Quality Sensor using the TP-401A device is a pretty sensitive sensor.   While it is not very discriminating (with the possible exception of Hairspray), it is sensitive to a wide range of different air contaminants.    The system was very easy to build using Grove devices and was a piece of cake to setup to log the data using the DataLogger software.

 

Oxygen Candle Burning Test

In this experiment, we took the Grove Oxygen sensor (see Part 1 for description) and placed it under a more-or-less sealed glass jar with a lit candle.   The idea was to measure the Oxygen in the glass jar and watch it go down as the candle consumes the Oxygen.    After a quick search on the Internet, we expected it to drop about 30% before the flame was extinguished.   That would be from 21% Oxygen  to about 14.7% Oxygen.

We set up the DataLogger system to sample the Oxygen every second, store the data in the MySQL database and then generate a graph update every minute.

Then we lit the candle and watched the data on the browser window connected to the Raspberry Pi.

 

Results

The candle stayed lit for about 90 seconds and then slowly went out.

 

 

 

 

 

 

Next we started looking at the data,  Our annotated chart is shown below.

Looking at the numbers, we determined that we started with about 21% Oxygen and the candle went out about 15.8% Oxygen level a reduction of about 25%.    This is lower than the expected 30%   The differences?   We would guess a combination of sensor accuracy and candle type.   One more thing to note:   Look at the graph right after the candle went out.   You can see that the seal wasn’t perfect as the Oxygen started to creep up.

Tutorial Conclusion

As you can see there is a lot you can do with an Analog to Digital Converter and a Raspberry Pi.   We use an Analog to Digital converter in many of our products, such as OurWeather and the Smart Garden System.