# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/059/223/medium800/microcontrollers_IMG_6201.jpg?1534364557)

Knowing what's in the air you breathe is important - and building an environmental monitor is a way to visualize the invisible properties of the air you inhale.

This guide covers building a small, internet-enabled environmental monitor which can track a range of data such from&nbsp;temperature to UV-level to the amount of total-volatile-organic-compounds present in the air.

Build it, place it in a location you'd like to log, and then **monitor it from anywhere in the world using our Internet-of-Things platform -&nbsp;[Adafruit IO](https://io.adafruit.com/).**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/224/medium800thumb/microcontrollers_ezgif.com-gif-maker.jpg?1534364614)

This project can be done with either Arduino or CircuitPython, too!

![](https://cdn-learn.adafruit.com/assets/assets/000/059/255/medium800/weather_IMG_6414.jpg?1534451101)

## Parts

We'll need a Feather HUZZAH and a handful of sensors to build our own environmental monitor.

Featured
### Adafruit Feather HUZZAH with ESP8266 - Loose Headers

[Adafruit Feather HUZZAH with ESP8266 - Loose Headers](https://www.adafruit.com/product/2821)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather HUZZAH ESP8266** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2821)
[Related Guides to the Product](https://learn.adafruit.com/products/2821/guides)
![Angled shot of black, rectangular WiFi development board.](https://cdn-shop.adafruit.com/640x480/2821-07.jpg)

Featured
### Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

[Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure&nbsp;and&nbsp;humidity! This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI!

This precision sensor from...

In Stock
[Buy Now](https://www.adafruit.com/product/2652)
[Related Guides to the Product](https://learn.adafruit.com/products/2652/guides)
![small, rectangle-shaped, BME280 temperature humidity pressure sensor breakout board.](https://cdn-shop.adafruit.com/640x480/2652-04.jpg)

Featured
### Adafruit SGP30 Air Quality Sensor Breakout - VOC and eCO2

[Adafruit SGP30 Air Quality Sensor Breakout - VOC and eCO2](https://www.adafruit.com/product/3709)
Breathe easy with the SGP30 Multi-Pixel Gas Sensor, a fully integrated MOX gas sensor. This is a very fine air quality sensor from the sensor experts at Sensirion, with I2C interfacing and fully calibrated output signals with a typical accuracy of 15% within...

In Stock
[Buy Now](https://www.adafruit.com/product/3709)
[Related Guides to the Product](https://learn.adafruit.com/products/3709/guides)
![Angled shot of a Adafruit SGP30 Air Quality Sensor Breakout.](https://cdn-shop.adafruit.com/640x480/3709-07.jpg)

Featured
### FeatherWing Proto - Prototyping Add-on For All Feather Boards

[FeatherWing Proto - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2884)
A Feather board without ambition is a Feather board without FeatherWings!

This is the **FeatherWing Proto** - a prototyping add-on for all Feather boards. Using our [Feather Stacking Headers](https://www.adafruit.com/products/2830) or <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2884)
[Related Guides to the Product](https://learn.adafruit.com/products/2884/guides)
![Angled Shot of the FeatherWing Proto - Prototyping Add-on For All Feather Boards.](https://cdn-shop.adafruit.com/640x480/2884-13.jpg)

Featured
### Lithium Ion Polymer Battery - 3.7v 1200mAh

[Lithium Ion Polymer Battery - 3.7v 1200mAh](https://www.adafruit.com/product/258)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 1200mAh for a total of about 4.5 Wh. If you need a larger battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/258)
[Related Guides to the Product](https://learn.adafruit.com/products/258/guides)
![Lithium Ion Polymer Battery 3.7v 1200mAh with JST 2-PH connector](https://cdn-shop.adafruit.com/640x480/258-02.jpg)

## Monitor Enclosure
If you'd like to enclosure your environmental monitor, consider picking up the following parts:

Featured
### Small Plastic Project Enclosure - Weatherproof with Clear Top

[Small Plastic Project Enclosure - Weatherproof with Clear Top](https://www.adafruit.com/product/903)
Store your project safe and sound in this nice weatherproof box with a clear top. We picked up this box because we like the machinable ABS plastic body and tough clear polycarbonate cover, the built in weatherproof gasket seal, and the easy-open screws that can be taken apart as many times as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/903)
[Related Guides to the Product](https://learn.adafruit.com/products/903/guides)
![Small weatherproof enclosure with clear lid.](https://cdn-shop.adafruit.com/640x480/903-00.jpg)

### Cable Gland PG-7 size - 0.118" to 0.169" Cable Diameter

[Cable Gland PG-7 size - 0.118" to 0.169" Cable Diameter](https://www.adafruit.com/product/762)
We have some great [waterproof and weather-proof](https://www.adafruit.com/?q=waterproof&) items in the adafruit shop, but once you have a project built, you'll want to enclose it. But how to keep an enclosure weather/waterproof while still attaching cables for power, data...

In Stock
[Buy Now](https://www.adafruit.com/product/762)
[Related Guides to the Product](https://learn.adafruit.com/products/762/guides)
![Cable Gland PG-7 size](https://cdn-shop.adafruit.com/640x480/762-00.jpg)

### Silicone Cover Stranded-Core Wire - 2m 26AWG Green

quantity: 4
[Silicone Cover Stranded-Core Wire - 2m 26AWG Green](https://www.adafruit.com/product/1880)
Silicone-sheathing wire is super-flexible and soft, and its also strong! Able to handle up to 200°C and up to 600V, it will do when PVC covered wire wimps out. We like this wire for being extremely supple and flexible, so it is great for wearables or projects where the wire-harness has to...

In Stock
[Buy Now](https://www.adafruit.com/product/1880)
[Related Guides to the Product](https://learn.adafruit.com/products/1880/guides)
![Green Silicone Cover Stranded-Core wire ](https://cdn-shop.adafruit.com/640x480/1880-00.jpg)

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Adafruit IO Setup

After logging into Adafruit IO, click the&nbsp; **VIEW AIO KEY&nbsp;** button on the left-sidebar.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/031/medium800/microcontrollers_view-aio-key.png?1533923510)

A window will pop up with your Adafruit IO key and username. Keep a copy of them in a safe place, we'll need it later.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/032/medium800/microcontrollers_aio-popup-window.png?1533923653)

## Create Feeds
We're going to have a&nbsp; **lot&nbsp;** of sources of data. Our three sensors generate&nbsp; **seven&nbsp;** different types of data.&nbsp;

Luckily for us, Adafruit IO is excellent at tracking data. It keeps data in elements called Feeds, with one feed per each unique source of data.

If you do not know how to create feeds, [head over to the&nbsp;_Adafruit IO Basics: Feeds_&nbsp;for a quick overview](https://learn.adafruit.com/adafruit-io-basics-feeds)&nbsp;of this process.

We're going to **create seven&nbsp;_unique_ feeds** to hold and display data generated by the BME280, SGP30, and VEML6070 sensors:

- **temperature**
- **humidity**
- **pressure**
- **altitude**
- **uv**
- **tvoc**
- **ecO2**

![](https://cdn-learn.adafruit.com/assets/assets/000/058/999/medium800/microcontrollers_temp-feed.png?1533918849)

Info: 

**If you have [Adafruit IO Plus](https://www.adafruit.com/product/3792) (unlimited feeds), we'll set up seven additional feeds** which will be used to specify what will be displayed using icon blocks:

- temperature-block
- humidity-block
- pressure-block
- altitude-block
- uv-block
- tvoc-block
- ecO2-block

## Create a Dashboard

Now that we have feeds to hold data and display the type of data, we need a way to consolidate these feeds in one place. Dashboards are a feature of Adafruit IO which allow us to display and control feeds using widgets called&nbsp;_Blocks_.&nbsp;

- If you haven't used an Adafruit IO Dashboard before, [check out the&nbsp;_Adafruit IO Basics: Dashboards_ learn guide](https://learn.adafruit.com/adafruit-io-basics-dashboards)&nbsp;for a quick primer.

We're going to navigate to the&nbsp; **Dashboards&nbsp;** page and click&nbsp; **Create a new Dashboard**. You can name it anything you'd like but we'll name it&nbsp; **Environmental Monitor**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/006/medium800/microcontrollers_IO_-_Dashboards.png?1533920070)

# Adding Icon Blocks

Blocks are widgets which you can add to your dashboard. We're going to first add some&nbsp;_icon blocks,&nbsp;_a _new_ type of output block which displays an icon specified by a feed.

On the dashboard, click the&nbsp; **green plus icon&nbsp;** to add a new block. Click on the Icon Block to configure it:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/013/medium800/microcontrollers_icon-block.png?1533920495)

We'll select the&nbsp;_temperature-block_ feed we created earlier:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/017/medium800/microcontrollers_icon-block-feed.png?1533920576)

Next, we're going to configure the color of the block, and pick an icon type. We're using&nbsp; **w:thermometer&nbsp;** for the temperature block, but you can pick any icon on the [Icons FAQ page](https://io.adafruit.com/icons-faq). You can also configure the color of the icon using the color-picker from the&nbsp;_Block Settings_.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/020/medium800/microcontrollers_icon-block-settings.png?1533920895)

After adding the block to the dashboard, you'll notice there's no icon on the dashboard. That's because the feed is currently empty - there's no icon to display.

Let's fix that by specifying an icon for the feed. Navigate to the&nbsp; **Feeds page** and click on the&nbsp; **temperature-block&nbsp;** feed. From the feed, we're going to click&nbsp; **Actions -\> Add Data&nbsp;** and add a the value&nbsp;_ **w:thermometer** _&nbsp;to set the icon block on the dashboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/021/medium800/microcontrollers_io-feed-thermometer.png?1533921375)

If you navigate back to the dashboard, you'll notice the thermometer icon is now displayed.&nbsp;We're going to repeat this process for each feed we'd like to display.

We set up a dashboard using the following icons, but you can use anything from the [Icon Listing page](https://io.adafruit.com/icons-faq) you'd like:

- Humidity, by setting the feed value to&nbsp; **w:humidity**
- Temperature,&nbsp; **w:thermometer**
- Pressure,&nbsp; **w:barometer**
- Altitude,&nbsp; **bar-chart**
- eCO2,&nbsp; **w:smoke**
- TVOC, **tvoc-icon**
- UV, **uv-feed-block**

Our dashboard uses the values above. We also added two&nbsp; **histogram blocks** to take a peek at some of the values over an hour.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/181/medium800/microcontrollers_env-dash-wed.png?1534351583)

# Adding Text Blocks

The icon block is a great way to graphically display what types of data are associated with a feed. We need a way to add the data from the sensors. To do this, we'll need to add&nbsp; **seven text blocks** to hold&nbsp;feeds for our sensor data.

Let's start by creating a text block to hold the temperature data from the BME280 sensor. From the dashboard, **add a block** and **select the text block.**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/024/medium800/microcontrollers_text-box.png?1533921880)

Choose the **data feed** (we're going to use the&nbsp;_temperature_ feed) to display:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/025/medium800/microcontrollers_text-block-temp.png?1533922029)

Then, select a&nbsp; **large&nbsp;** font size.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/027/medium800/microcontrollers_text-block-text.png?1533922138)

Repeat this for the&nbsp; **humidity, pressure, altitude, temperature, uv, tvoc,** and&nbsp; **eco2**** &nbsp;**feeds.&nbsp;

While you can't "see" them on the background (since those feeds are currently empty), we can view them by clicking the&nbsp; **green gear** on the dashboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/028/medium800/microcontrollers_green-gear.png?1533923057)

The outlines of the text blocks should now be visible. Reorganize the blocks however you'd like - we can always change them later.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/030/medium800/microcontrollers_dash-edit.png?1533923137)

Next, let's wire everything up!

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Arduino Wiring and Assembly

## Wiring
We will be connecting multiple I2C devices to a single I2C controller using only two wires - SCL and SDA.

- _Interested in learning more about I2C Addressing?_&nbsp;&nbsp;[Check out our learn guide on connecting multiple I2C devices](https://learn.adafruit.com/i2c-addresses).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/034/medium800/microcontrollers_airqualitymon-resize.png?1533928211)

Make the following connections between the **Adafruit Feather Huzzah** and the **BME280** :

- **Feather 3V** to **BME280 Vin**
- **Feather GND** to **BME280 GND**
- **Feather SCL** to **BME280 SCK**
- **Feather SDI** to **BME280 SDI**

Make the following connections between the&nbsp; **BME280** &nbsp;and the **SGP30** :

- **BME280 SCK** to **SGP30 SCL**
- **BME280 SDI** to **SGP30 SDA**
- **Feather 3V** to **SGP30&nbsp;Vin**
- **Feather GND** to **SGP30 GND**

Make the following connections between the **VEML6070** and the **SGP30**

- **SGP30 SCL&nbsp;** to **VEML6070 SCL**
- **SGP30 SDA&nbsp;** to **VEML6070&nbsp;SDA**
- **Feather 3V&nbsp;** to **VEML6070 Vin**
- **Feather GND&nbsp;** to **VEML6070 GND**

## Assembly
If you'd like to make this portable using the&nbsp;[Adafruit Featherwing Proto](https://www.adafruit.com/product/2884)&nbsp;and a project enclosure, we have some great news, You can fit _all_ the sensors on the FeatherWing Proto. The wiring between the sensors and the feather are identical to the connections made above.

**Note:&nbsp;** The ACK pin for the VEML6070 is unused, so we're going to hang it off the side so we can fit everything on the board.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/095/medium800/microcontrollers_fritzing-perma-proto.png?1534260598)

The [small plastic project enclosure](https://www.adafruit.com/product/903) is the perfect size for a feather and a medium-sized LiPo battery. It's also rugged and has a waterproof gasket seal.&nbsp;

Connect the Feather Huzzah's JST port to a [lipo battery](https://www.adafruit.com/product/2011) using the included JST connector on the battery:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/169/medium800thumb/microcontrollers_ezgif.com-video-to-gif.jpg?1534346891)

Next, we're going to test-fit the feather and the lipo battery in the project enclosure. Use a non-permanent marker to outline the positions of the battery and the feather on the bottom of the case.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/098/medium800/microcontrollers_IMG_6134.jpg?1534264240)

Put the lid on the box and screw it down to ensure everything fits correctly. Use a ruler and a marker to mark locations for holes on the plastic lid of your project box. Be sure to mark the locations closer to the sensors.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/096/medium800/microcontrollers_IMG_6128.jpg?1534263427)

Let's drill some holes! I used a rotary tool with a 4mm drill bit mounted to a drill press. Be sure to hold the lid tightly, use a low RPM on your tool, and watch your fingers!

![](https://cdn-learn.adafruit.com/assets/assets/000/059/097/medium800thumb/microcontrollers_ezgif.com-video-to-gif.jpg?1534263581)

Next, we're going to attach a [cable gland](https://www.adafruit.com/product/762)&nbsp;to seal off the USB cable from the elements. Drill a 5/8" hole on the side of the enclosure where the Feather HUZZAH's USB port is located. The cable gland has integrated screw threads - twist it into the hole you drilled and attach the retaining nut.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/176/medium800/microcontrollers_IMG_6195.jpg?1534348273)

You'll need to cut and splice the Micro USB cable to fit it into the enclosure through the cable gland. Plug a Micro-USB cable into the Feather HUZZAH and your computer. The green **CHG&nbsp;** LED should turn on to indicate the lipo is charging.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/186/medium800/microcontrollers_IMG_6199.jpg?1534351953)

Next, we're going to load the environmental monitoring code on your Feather.&nbsp;

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Arduino Setup

This guide assumes you've completed the setup required to get your ESP8266 up and running with Arduino IDE and Adafruit IO.&nbsp;

- If you haven't yet set up your ESP8266 for use with Adafruit IO and the Arduino IDE,&nbsp;[follow along with this guide](https://learn.adafruit.com/adafruit-io-basics-esp8266-arduino/arduino-io-library). The setup only needs to be performed once.

To read sensor data from the SGP30,&nbsp;you will need to&nbsp;[install the Adafruit\_SGP30 library (code on our github repository)](https://github.com/adafruit/Adafruit_SGP30 "Link: https://github.com/adafruit/Adafruit\_SGP30"). It is available from the Arduino library manager so we recommend using that.

- Not sure how to use the&nbsp; **Library Manager**? [We have a great learn guide about installing libraries](https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use):&nbsp;

From the Arduino IDE, open the **Library Manager**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/084/medium800/microcontrollers_adafruit_products_managelib.png?1534187101)

Type in&nbsp; **Adafruit SGP30** to search for the library. Click&nbsp; **Install**.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/085/medium800/microcontrollers_adafruit_products_lib.png?1534187145)

Next, we're going to install the&nbsp; **Adafruit BME280 Sensor Library** &nbsp;.&nbsp;In the Library Manager, type in&nbsp; **Adafruit BME280&nbsp;** to search for the library. Click&nbsp; **Install.&nbsp;**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/086/medium800/microcontrollers_bme-lib.png?1534187485)

The BME280 uses the **Adafruit Unified Sensor** library, so we also need to install that. In the Library Manager, type in **Unified Sensor abstract** to search for the library. Click **Install**.

![](https://cdn-learn.adafruit.com/assets/assets/000/070/792/medium800/weather_unified_sensor.png?1549473326)

Finally, we'll install the&nbsp; **Adafruit VEML6070&nbsp;** library. In the Library Manager, type in&nbsp; **Adafruit VEML6070&nbsp;** to search for the library. Then, click **Install.**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/087/medium800/microcontrollers_veml-lib.png?1534187625)

The code for this learn guide is contained within the Adafruit IO Arduino Library's examples.

To open it from the Arduino IDE, navigate to:&nbsp; **File -\> Examples -\> Adafruit IO Arduino -\> adafruitio\_22\_environmental\_monitor**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/099/medium800/microcontrollers_Adafruit_IO_Arduino_and_Examples_and_File_and_Menubar.png?1534265461)

At this point, you should see two tabs open on your Arduino IDE: **`adafruitio_22_environmental_monitor`&nbsp;** and&nbsp;`config.h`

![](https://cdn-learn.adafruit.com/assets/assets/000/059/088/medium800/microcontrollers_open-sketch.png?1534188757)

Next, we're going to configure our Feather for use with Adafruit IO.

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Arduino Network Config

To configure the network settings, click on the **config.h** tab in the sketch. You will need to set your Adafruit IO username in the **IO_USERNAME** define, and your Adafruit IO key in the **IO_KEY** define.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/317/medium800/adafruit_io_03_config.png?1487185264)

## WiFi Config

WiFi is enabled by default in **config.h** so if you are using one of the supported WiFi boards, you will only need to modify the **WIFI_SSID** and **WIFI_PASS** options in the **config.h** tab.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/318/medium800/adafruit_io_04_wifi.png?1487185900)

## FONA Config

If you wish to use the FONA 32u4 Feather to connect to Adafruit IO, you will need to first comment out the WiFi support in **config.h**

![](https://cdn-learn.adafruit.com/assets/assets/000/039/319/medium800/adafruit_io_05_wifi_disable.png?1487186164)

Next, remove the comments from both of the FONA config lines in the FONA section of **config.h** to enable FONA support.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/320/medium800/adafruit_io_06_fona.png?1487186409)

## Ethernet Config

If you wish to use the Ethernet Wing to connect to Adafruit IO, you will need to first comment out the WiFi support in **config.h**

![](https://cdn-learn.adafruit.com/assets/assets/000/039/321/medium800/adafruit_io_05_wifi_disable.png?1487186577)

Next, remove the comments from both of the Ethernet config lines in the Ethernet section of **config.h** to enable Ethernet Wing support.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/322/medium800/adafruit_io_07_ethernet.png?1487186729)

Next, we will look at how the example sketch works.

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Arduino Code

The code waits ten seconds between sensor reads and publishing to Adafruit IO. We can adjust this by increasing or decreasing the `READ_DELAY`&nbsp;variable at the top of our code.&nbsp;

```auto
// Delay between sensor reads, in seconds
#define READ_DELAY 10
```

The next chunk of code sets up feed instances to hold the data produced by the sensors.

```auto
// set up the feeds for the BME280
AdafruitIO_Feed *temperatureFeed = io.feed("temperature");
AdafruitIO_Feed *humidityFeed = io.feed("humidity");
AdafruitIO_Feed *pressureFeed = io.feed("pressure");
AdafruitIO_Feed *altitudeFeed = io.feed("altitude");
// set up feed for the VEML6070
AdafruitIO_Feed *uvFeed = io.feed("uv");
// set up feeds for the SGP30
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
AdafruitIO_Feed *ecO2Feed = io.feed("ecO2");
```

In the setup function, we make calls to `setupBME280()` and `setupSGP30()`, which set up both of these sensors. We're also going to set up the VEML6070 by calling `uv.begin()`, then connect to Adafruit IO. The code will wait until you have a valid connection to Adafruit IO before continuing with the sketch.

**If you have any issues connecting, check `config.h`&nbsp;for any typos in your username, key, or WiFi credentials.&nbsp;**

```auto
void setup() {
  // start the serial connection
  Serial.begin(9600);

  // wait for serial monitor to open
  while (!Serial);

  Serial.println("Adafruit IO Environmental Logger");

  // set up BME280
  setupBME280();
  // set up SGP30
  setupSGP30();
  // setup VEML6070
  uv.begin(VEML6070_1_T);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while (io.status() < AIO_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
}
```

The code inside the `loop()`&nbsp;obtains values from the sensors and saves their current state.&nbsp; The SGP30 sometimes fails on read (due to timing). If this occurs, we'll set the measurements of `tvocReading` and `ECO2Reading`&nbsp;to -1&nbsp; so we can catch this type of error in our dashboard.&nbsp;

```auto
Serial.println("Reading Sensors...");

  // Read the temperature from the BME280
  temperatureReading = bme.readTemperature();

  // convert from celsius to degrees fahrenheit
  temperatureReading = temperatureReading * 1.8 + 32;
  
  Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F");

  // Read the pressure from the BME280
  pressureReading = bme.readPressure() / 100.0F;
  Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa");

  // Read the altitude from the BME280
  altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA);
  Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m");
  
  // Read the humidity from the BME280
  humidityReading = bme.readHumidity();
  Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%");

  // VEML6070
  uvReading = uv.readUV();
  Serial.print("UV Light Level: "); Serial.println(uvReading);
  if(! sgp.IAQmeasure()){
    tvocReading = -1;
    ecO2Reading = -1;  
  } else {
    tvocReading = sgp.TVOC;
    ecO2Reading = sgp.eCO2;  
  }
```

The final chunk of the `loop()`&nbsp;function sends sensor data to the feeds associated with that data. We also delay the polled loop to wait for the temperature to change.

```auto
  // send data to Adafruit IO feeds
  temperatureFeed->save(temperatureReading);
  humidityFeed->save(humidityReading);
  altitudeFeed->save(altitudeReading);
  pressureFeed->save(pressureReading);
  uvFeed->save(uvReading);
  ecO2Feed->save(ecO2Reading);
  tvocFeed->save(tvocReading);
```

Upload the sketch to your board and open the Arduino Serial Monitor ( **Tools -\> Serial Monitor** ). You should see the board connecting to Adafruit IO, obtain sensor readings, and send them to Adafruit IO:

```auto
Adafruit IO Environmental Logger
BME Sensor is set up!
Found SGP30 serial #064F41A
Connecting to Adafruit IOAdafruitIO::connect()
.
Adafruit IO connected.
Reading Sensors...
Temperature = 82 *F
Pressure = 1006 hPa
Approx. Altitude = 56 m
Humidity = 43%
UV Light Level: 3
TVOC: 0 ppb	eCO2: 400 ppm

```

Check your Dashboard on Adafruit IO and you should see your dashboard populated with values. You should also see them change every ten seconds.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/226/medium800/microcontrollers_env-dash-wed.png?1534367041)

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Python Wiring and Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/059/262/medium800/weather_IMG_6420.jpg?1534451945)

We're going make an environmental monitor using a **Raspberry Pi Zero W and a Perma Proto Bonnet.** We'll wire it up, build an enclosure for it, install dependencies, and program it with Python & [CircuitPython](http://adafruit.com/circuitpython)

The Pi Zero W has&nbsp; **built-in WiFi** - which is great for connecting our environmental monitor to Adafruit IO. It's also smaller than a regular Raspberry Pi 3, making it the perfect size to bring with you (monitor the air in the subway station) or stick it in a small corner of your room.&nbsp;

Featured
### Raspberry Pi Zero W

[Raspberry Pi Zero W](https://www.adafruit.com/product/3400)
If you didn't think that the Raspberry Pi Zero could possibly get any better, then boy do we have a pleasant surprise for you!&nbsp;The new **Raspberry Pi Zero W** offers all the benefits of the Pi Zero v1.3, but with one big difference – **built-in...**

In Stock
[Buy Now](https://www.adafruit.com/product/3400)
[Related Guides to the Product](https://learn.adafruit.com/products/3400/guides)
![Angled shot of Raspberry Pi Zero W computer.](https://cdn-shop.adafruit.com/640x480/3400-06.jpg)

We're going to be building our own pHAT for monitoring environmental data by using a Perma Proto Bonnet.&nbsp;

Featured
### Adafruit Perma Proto Bonnet Mini Kit

[Adafruit Perma Proto Bonnet Mini Kit](https://www.adafruit.com/product/3203)
Design your own Bonnet or pHAT, attach custom circuitry and otherwise dress your Pi Zero with this jaunty prototyping Bonnet kit!

To add to&nbsp;the [Adafruit Bonnet party](https://www.adafruit.com/categories/929), we have this Perma-Proto inspired plug in daughter board. It...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3203)
[Related Guides to the Product](https://learn.adafruit.com/products/3203/guides)
![Angled shot of a Adafruit Perma Proto Bonnet on a Pi zero](https://cdn-shop.adafruit.com/640x480/3203-02.jpg)

## Wiring
First, solder the included 20x2 GPIO Header to the Perma Proto Bonnet

![](https://cdn-learn.adafruit.com/assets/assets/000/059/248/medium800thumb/weather_ezgif.com-gif-maker_%281%29.jpg?1534446922)

We will be connecting multiple I2C devices to a single I2C controller using only two wires - SCL and SDA.

- _Interested in learning more about I2C Addressing?_&nbsp;&nbsp;[Check out our learn guide on connecting multiple I2C devices](https://learn.adafruit.com/i2c-addresses).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/234/medium800/weather_rezpythonfritz.png?1534438617)

 **Note:** The SDA and SCL lines are located at the top- of the Proto-Bonnet and do not run down the side.

Make the following connections between the **Raspberry Pi** &nbsp;and the **VEML6070** :

- **Pi 3V** to&nbsp; **VEML6070**** &nbsp;Vin**
- **Pi GND** to&nbsp; **VEML6070**** &nbsp;GND**
- **Pi SCL** to&nbsp; **VEML6070**** &nbsp;SCK**
- **Pi SDI** to&nbsp; **VEML6070**** &nbsp;SDI**

Make the following connections between the&nbsp; **VEML6070** &nbsp;and the **SGP30** :

- **VEML6070 SCL** to **SGP30 SCL**
- **VEML6070 SDA&nbsp;** to **SGP30 SDA**
- **Pi 3V** to **SGP30&nbsp;Vin**
- **Pi GND** to **SGP30 GND**

Make the following connections between the **SGP30** and the **BME280:**

- **VEML 6070 SCL&nbsp;** to&nbsp; **BME280**** &nbsp;SCK**
- **VEML 6070 SDA&nbsp;** to&nbsp; **BME280**** &nbsp;SDI**
- **Pi 3V&nbsp;** to **VEML6070 Vin**
- **Pi GND&nbsp;** to **VEML6070 GND**

## Assembly
The [small plastic project enclosure](https://www.adafruit.com/product/903) is the perfect size for a Pi Zero W and Environmental Logger Bonnett.&nbsp;

Featured
### Small Plastic Project Enclosure - Weatherproof with Clear Top

[Small Plastic Project Enclosure - Weatherproof with Clear Top](https://www.adafruit.com/product/903)
Store your project safe and sound in this nice weatherproof box with a clear top. We picked up this box because we like the machinable ABS plastic body and tough clear polycarbonate cover, the built in weatherproof gasket seal, and the easy-open screws that can be taken apart as many times as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/903)
[Related Guides to the Product](https://learn.adafruit.com/products/903/guides)
![Small weatherproof enclosure with clear lid.](https://cdn-shop.adafruit.com/640x480/903-00.jpg)

We're going to test-fit the Pi in the project enclosure. Use a non-permanent marker to outline the positions of the Pi on the bottom of the case.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/256/medium800/weather_IMG_6397.jpg?1534451188)

Put the lid on the box and screw it down to ensure everything fits correctly. Use a ruler and a marker to mark locations for holes on the plastic lid of your project box. Be sure to mark the locations closer to the sensors.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/235/medium800/weather_microcontrollers_IMG_6128.jpg?1534440144)

Let's drill some holes! I used a rotary tool with a 4mm drill bit mounted to a drill press. Be sure to hold the lid tightly, use a low RPM on your tool, and watch your fingers!

![](https://cdn-learn.adafruit.com/assets/assets/000/059/236/medium800thumb/weather_microcontrollers_ezgif.com-video-to-gif.jpg?1534440210)

Next, let's set up our Raspberry Pi to be used with both CircuitPython and our sensors.

Next, we're going to attach a [cable gland](https://www.adafruit.com/product/762)&nbsp;to seal off the USB cable from the elements. Drill a 5/8" hole on the side of the enclosure where the Pi's USB port is located. The cable gland has integrated screw threads - twist it into the hole you drilled and attach the retaining nut.&nbsp;

You'll need to cut and splice the Micro USB cable to fit it into the enclosure through the cable gland. Plug a Micro-USB cable into the Pi Zero W.&nbsp;

## Making it Portable

If you want to take your Environmental Monitor on-the-go, you might want to add a Rechargeable USB Battery Pack. We used a [smaller rechargeable model with a 2200mAh capacity](https://www.adafruit.com/product/1959). Charge up your battery pack, and then plug it into the Pi's&nbsp; **PWR\_IN&nbsp;** port.&nbsp;

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Python Setup

If you're following along with a Raspberry Pi, Beaglebone or any other supported small linux computer, we'll use a special library called&nbsp;[**adafruit\_blinka**](https://pypi.org/project/Adafruit-Blinka/)&nbsp;([named after Blinka, the CircuitPython mascot](https://www.adafruit.com/?q=blinka)) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. It's CircuitPython, on Pi!

If you haven't set up Blinka and the Adafruit IO Python Library yet on your Raspberry Pi, follow our guide:

- [Blinka and Adafruit IO Setup](https://learn.adafruit.com/adafruit-io-basics-digital-input/python-setup)

# Enable I2C

We use two pins on the Pi (SDA/SCL) to communicate over I2c with the&nbsp;PCA9685. You only have to do this step&nbsp;_once_ per Raspberry Pi, the I2C interface is disabled by default.

- [Enabling I2C](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c)

Once you're done with this and have rebooted, verify you have the SPI devices with the command:

`sudo i2cdetect -y 1`

The output from running this command should look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/108/medium800/microcontrollers_1__pi_io-pi_____ssh_.png?1534279858)

# Adafruit IO Environmental Monitor for Feather or Raspberry Pi

## Python Code

First, we're going to import the libraries used by our code to read sensor values, use CircuitPython on our Pi, and read/write to Adafruit IO using the REST client.

```auto
# Import standard python modules
import time

# import Adafruit Blinka
import board
import busio

# import sensor libraries
import adafruit_sgp30
import adafruit_veml6070
import adafruit_bme280

# import Adafruit IO REST client
from Adafruit_IO import Client, Feed, RequestError
```

Next, we'll set up our code with our Adafruit IO username and secret key. If you need these values, [navigate to your Adafruit IO profile](https://io.adafruit.com/profile). We'll also create an instance of the REST client with these values.

```auto
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'

# Create an instance of the REST client
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
```

The code next assigns feeds, or creates and assigns them. Then, we create an I2C busio object and create objects for the VEML6070, BME280, and SGP30 sensors.

```auto
# Create busio I2C
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
# Create VEML6070 object.
uv = adafruit_veml6070.VEML6070(i2c)
# Create BME280 object.
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
bme280.sea_level_pressure = 1013.25
# Create SGP30 object using I2C.
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
sgp30.iaq_init()
sgp30.set_iaq_baseline(0x8973, 0x8aae)
```

in the `while True`&nbsp;loop, we read data from the SGP30, VEML6070, and the BME280. The VEML6070 samples ten times before arriving at a final data.

```auto
    # Read SGP30.
    eCO2_data = sgp30.eCO2
    tvoc_data = sgp30.TVOC

    # Read VEML6070, sample ten times.
    for j in range(10):
      uv_data = uv.read

    # Read BME280.
    temp_data = bme280.temperature
    # convert temperature (C->F)
    temp_data = int(temp_data) * 1.8 + 32
    humid_data = bme280.humidity
    pressure_data = bme280.pressure
    alt_data = bme280.altitude
```

Then, we send our data to Adafruit IO. Since we'll be sending a lot of data to our feeds, we added a pause between sending each sensor's data to its corresponding Adafruit IO Feeds.&nbsp;

```auto
 # Send SGP30 Data to Adafruit IO.
    print('eCO2:', eCO2_data)
    aio.send(eCO2_feed.key, eCO2_data)
    print('tvoc:', tvoc_data)
    aio.send(tvoc_feed.key, tvoc_data)
    time.sleep(SENSOR_DELAY)
```

Finally, we wait for `LOOP_DELAY` minutes. If you want to report data more quickly or slowly, adjust the `LOOP_DELAY` variable at the start of the code.

Make sure you have your Adafruit IO Username and Key set up and that your Pi is connected to the internet. Then, enter the following in your terminal to run the code:

`python3 environmental_monitor.py`

You should see the following output in your terminal:

```auto
Reading sensors...
sending data to adafruit io...
eCO2: 400
tvoc: 0
UV Level:  3
Temperature: 75.2 C
Humidity: 54.8 %
Pressure: 1008.1 hPa
Altitude = 42.68 meters
```

Your dashboard should populate with values. Note that it will take the SGP30 at least ten reads before it obtains a baseline measurement.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/203/medium800/microcontrollers_IO_-_Environmental_Monitor-dash.png?1534355960)

## Code
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/AIO_Environmental_Monitor/code.py


## Guide Products

### Adafruit Feather HUZZAH with ESP8266 - Loose Headers

[Adafruit Feather HUZZAH with ESP8266 - Loose Headers](https://www.adafruit.com/product/2821)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather HUZZAH ESP8266** &nbsp;- our take on an...

In Stock
[Buy Now](https://www.adafruit.com/product/2821)
[Related Guides to the Product](https://learn.adafruit.com/products/2821/guides)
### Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor

[Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
Bosch has stepped up their game with their new BME280 sensor, an environmental sensor with temperature, barometric pressure&nbsp;and&nbsp;humidity! This sensor is great for all sorts of indoor environmental sensing and can even be used in both I2C and SPI!

This precision sensor from...

In Stock
[Buy Now](https://www.adafruit.com/product/2652)
[Related Guides to the Product](https://learn.adafruit.com/products/2652/guides)
### Adafruit SGP30 Air Quality Sensor Breakout - VOC and eCO2

[Adafruit SGP30 Air Quality Sensor Breakout - VOC and eCO2](https://www.adafruit.com/product/3709)
Breathe easy with the SGP30 Multi-Pixel Gas Sensor, a fully integrated MOX gas sensor. This is a very fine air quality sensor from the sensor experts at Sensirion, with I2C interfacing and fully calibrated output signals with a typical accuracy of 15% within...

In Stock
[Buy Now](https://www.adafruit.com/product/3709)
[Related Guides to the Product](https://learn.adafruit.com/products/3709/guides)
### Adafruit VEML6070 UV Index Sensor Breakout

[Adafruit VEML6070 UV Index Sensor Breakout](https://www.adafruit.com/product/2899)
[Discontinued - **you can grab** Adafruit LTR390 UV Light Sensor - STEMMA QT / Qwiic **instead!&nbsp;**](https://www.adafruit.com/product/4831)

This little sensor is a great way to add UV light sensing to any microcontroller project. The VEML6070 from Vishay has a true...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2899)
[Related Guides to the Product](https://learn.adafruit.com/products/2899/guides)
### FeatherWing Proto - Prototyping Add-on For All Feather Boards

[FeatherWing Proto - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2884)
A Feather board without ambition is a Feather board without FeatherWings!

This is the **FeatherWing Proto** - a prototyping add-on for all Feather boards. Using our [Feather Stacking Headers](https://www.adafruit.com/products/2830) or <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2884)
[Related Guides to the Product](https://learn.adafruit.com/products/2884/guides)
### Lithium Ion Polymer Battery - 3.7v 1200mAh

[Lithium Ion Polymer Battery - 3.7v 1200mAh](https://www.adafruit.com/product/258)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 1200mAh for a total of about 4.5 Wh. If you need a larger battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/258)
[Related Guides to the Product](https://learn.adafruit.com/products/258/guides)
### Small Plastic Project Enclosure - Weatherproof with Clear Top

[Small Plastic Project Enclosure - Weatherproof with Clear Top](https://www.adafruit.com/product/903)
Store your project safe and sound in this nice weatherproof box with a clear top. We picked up this box because we like the machinable ABS plastic body and tough clear polycarbonate cover, the built in weatherproof gasket seal, and the easy-open screws that can be taken apart as many times as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/903)
[Related Guides to the Product](https://learn.adafruit.com/products/903/guides)
### Cable Gland PG-7 size - 0.118" to 0.169" Cable Diameter

[Cable Gland PG-7 size - 0.118" to 0.169" Cable Diameter](https://www.adafruit.com/product/762)
We have some great [waterproof and weather-proof](https://www.adafruit.com/?q=waterproof&) items in the adafruit shop, but once you have a project built, you'll want to enclose it. But how to keep an enclosure weather/waterproof while still attaching cables for power, data...

In Stock
[Buy Now](https://www.adafruit.com/product/762)
[Related Guides to the Product](https://learn.adafruit.com/products/762/guides)

## Related Guides

- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
- [Feather RP2040 DVI Video Synth](https://learn.adafruit.com/feather-rp2040-dvi-video-synth.md)
- [Single Channel LoRaWAN Gateway for Raspberry Pi](https://learn.adafruit.com/raspberry-pi-single-channel-lorawan-gateway.md)
- [HalloWing Interactive Cat Toy](https://learn.adafruit.com/hallowing-cat-toy.md)
- [Twin Peaks Light Reactive Picture Frame](https://learn.adafruit.com/twin-peaks-light-reactive-pyportal-picture-frame.md)
- [PyLeap App](https://learn.adafruit.com/pyleap-app.md)
- [Superhero Power Gauntlet](https://learn.adafruit.com/superhero-power-gauntlet.md)
- [LED Bubble Hair Extensions with Motion Controlled Effects](https://learn.adafruit.com/led-bubble-hair-extensions-with-motion-controlled-effects.md)
- [NES Emulator for RP2040 & RP2350 DVI Boards](https://learn.adafruit.com/nes-emulator-for-rp2040-dvi-boards.md)
- [Boomy Pi Airplay Boombox](https://learn.adafruit.com/boomy-pi-airplay.md)
- [Blahaj Alarm and Lamp](https://learn.adafruit.com/blahaj-alarm.md)
- [Adding a WiFi Co-Processor to CircuitPython](https://learn.adafruit.com/adding-a-wifi-co-processor-to-circuitpython-esp8266-esp32.md)
- [Sparkle Skirt Playground](https://learn.adafruit.com/sparkle-skirt-playground.md)
- [MagTag Progress Displays](https://learn.adafruit.com/magtag-progress-displays.md)
- [Cellular Data for CircuitPython with FONA](https://learn.adafruit.com/cellular-data-for-circuitpython-with-fona.md)
- [Sketch Drawing Toy with CircuitPython](https://learn.adafruit.com/sketch-drawing-toy.md)
