Skip to main content
Engineering LibreTexts

Grove Analog Air Quality Sensor

  • Page ID
    51680
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

     

    Grove Air Quality Sensor.png

    The grove air quality sensor is an analog device.

    Therefore it interfaces through an analog port.  The required input voltage is 3.3 to 5 volts.

    Save the script with the name air_quality_sensor.py.

     

    #!/usr/bin/python3
    
    import time
    from grove.grove_air_quality_sensor_v1_3 import GroveAirQualitySensor
             # mport the sensor library and name it GroveAirQualitySensor for this script.
    # connect to analog pin 0(slot A0)
    PIN = 0
    # Set the port (pin) to use for analog input.
    sensor = GroveAirQualitySensor(PIN) # Make a sensor object set to the analog pin input.
    
    print('Detecting ...')
    while True:             # Using while true makes this an infinite loop.  Use Ctrl-C to exit the loop.
      value = sensor.value
      if value > 100:
        print("{}, High Pollution.".format(value)) # The if else block.
      else:
        print("{}, Air Quality OK.".format(value))
      time.sleep(.1)        # Sleep for X seconds.
    

     

    This is what the output looks like when a swap of hand sanitizer (Ethyl Alcohol 62%) is placed over the sensor.

    75, Air Quality OK.
    76, Air Quality OK.
    79, Air Quality OK.
    81, Air Quality OK.
    84, Air Quality OK.
    87, Air Quality OK.
    91, Air Quality OK.
    93, Air Quality OK.
    97, Air Quality OK.
    100, Air Quality OK.
    104, High Pollution.
    105, High Pollution.
    108, High Pollution.
    110, High Pollution.
    113, High Pollution.
    117, High Pollution.
    119, High Pollution.
    121, High Pollution.
    125, High Pollution.
    129, High Pollution.
    

    The recovery after removing the swap.

    110, High Pollution.
    110, High Pollution.
    108, High Pollution.
    108, High Pollution.
    108, High Pollution.
    106, High Pollution.
    102, High Pollution.
    102, High Pollution.
    101, High Pollution.
    101, High Pollution.
    100, Air Quality OK.
    99, Air Quality OK.
    97, Air Quality OK.
    98, Air Quality OK.
    96, Air Quality OK.
    94, Air Quality OK.
    94, Air Quality OK.
    94, Air Quality OK.
    92, Air Quality OK.
    91, Air Quality OK.
    91, Air Quality OK.
    90, Air Quality OK.
    

     

     

     

     


    Grove Analog Air Quality Sensor is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?