# Adafruit IO Home: Lights and Temperature 

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/060/145/medium800thumb/raspberry_pi_hero-houseseries-1.jpg?1535390262)

Interested in making your house a bit smarter?&nbsp;

Why not start _small&nbsp;_by building a&nbsp; **Cardboard**  **Smart**  **Home**!

Adafruit IO Home is a series of learning guides covering all aspects of a smart house: from temperature monitoring to an intelligent home security system.&nbsp;

_Want to scale up from the cardboard home to a real home?_&nbsp; We've selected real-world components, sensors, and hardware which can also be installed in your home, office or laboratory!

This is the first guide in the series, and there's more to come!

## **Parts**
### Temperature and Humidity
If you want to install a temperature and humidity sensor in your home, you're in luck. [There's a plethora **&nbsp;** of these dual-use-type sensors available on the Adafruit Shop](https://www.adafruit.com/category/56)&nbsp;to select from.

We're going to use the **Si7021** , a digital temperature and humidity sensor which is less expensive than the popular [DHTxx sensors](https://www.adafruit.com/?q=dht). In addition to being inexpensive, it uses an I2C interface, freeing up digital pins on our Feather HUZZAH microcontroller for other things - like pretty lights and loud buzzers.&nbsp;

### Adafruit Si7021 Temperature & Humidity Sensor Breakout Board

[Adafruit Si7021 Temperature & Humidity Sensor Breakout Board](https://www.adafruit.com/product/3251)
It's summer and you're sweating and your hair's all frizzy and all you really want to know is why the weatherman said this morning that today's relative humidity would max out at a perfectly reasonable 42% when it feels more like 77%. Enter the&nbsp; **Si7021 Temperature +...**

In Stock
[Buy Now](https://www.adafruit.com/product/3251)
[Related Guides to the Product](https://learn.adafruit.com/products/3251/guides)
![Angled shot of black, rectangular temperature and humidity sensor breakout.](https://cdn-shop.adafruit.com/640x480/3251-05.jpg)

### Lighting
_Is anyone home?_&nbsp; We're going to add lighting both inside&nbsp;_and&nbsp;_outside our house.&nbsp;

Our lighting system will be comprised of a two different form factors of NeoPixels, which can be chained together and individually addressed, making them perfect for a home-automation system.

For lighting inside the house, we'll be using a **NeoPixel Jewel** comprised of seven NeoPixels on a round PCB. This light will serve as the lighting inside the house. As a bonus - it looks like a chandelier or a lamp when it's wired using solid-core wire.

### NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers

[NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/2226)
Be the belle of the ball with the NeoPixel Jewel! &nbsp;We fit seven of our tiny&nbsp;5050 (5mm x 5mm) smart RGB LEDs onto a beautiful, round&nbsp;PCB with mounting holes and a chainable design to create what we think is our most elegant (and evening-wear appropriate) NeoPixel board...

In Stock
[Buy Now](https://www.adafruit.com/product/2226)
[Related Guides to the Product](https://learn.adafruit.com/products/2226/guides)
![NeoPixel Jewel - 7 x 5050 RGB LED wired to Trinket, lit up rainbow](https://cdn-shop.adafruit.com/640x480/2226-01.jpg)

We'll also be using a 1 meter long Mini Skinny NeoPixel RGB LED Strip to add some lighting around the edges of the roof. This strip is thin enough to wrap around the roof of the house and you can cut it to-length.&nbsp;

In addition to serving an aesthetic purpose, the outdoor lighting will also be used in later guides which will involve home security.&nbsp;

### Adafruit Mini Skinny NeoPixel Digital RGB LED Strip - 60 LED/m

[Adafruit Mini Skinny NeoPixel Digital RGB LED Strip - 60 LED/m](https://www.adafruit.com/product/2964)
So thin. So mini. So teeeeeeny-tiny. It's the 'skinny' version of our classic NeoPixel strips!

These NeoPixel strips have 60 digitally-addressable pixel Mini LEDs per meter and are very affordable and are only 7.5 mm wide, 5 mm if you remove the strip from the...

In Stock
[Buy Now](https://www.adafruit.com/product/2964)
[Related Guides to the Product](https://learn.adafruit.com/products/2964/guides)
![Video of an Adafruit NeoPixel Digital RGB LED Strip with all the LEDs illuminating various colors. ](https://cdn-shop.adafruit.com/product-videos/640x480/2964-06.jpg)

## Hardware
For the controller, we're going to use a Feather HUZZAH with ESP8266. This board is used by most of our Adafruit IO guides since the ESP8266 is a highly popular and versatile IoT platform.&nbsp;

This guide is also CircuitPython-compatible. You can use a Raspberry Pi with the IO House series.

### 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)

### Materials
### Part: Breadboard
quantity: 1
Half-Size Breadboard
[Breadboard](https://www.adafruit.com/product/64)

### Part: Breadboarding Wire Bundle
quantity: 1
You'll want some of these wires to hook up your temperature sensor.
[Breadboarding Wire Bundle](https://www.adafruit.com/product/153)

### Part: 3-Pin JST Plug
quantity: 1
3-pin JST SM Plug + Receptacle Cable Set
[3-Pin JST Plug](https://www.adafruit.com/product/1663)

### Part: Hook-up Wire
quantity: 1
Hook-up Wire Spool Set - 22AWG Stranded-Core - 6 x 25ft
[Hook-up Wire](https://www.adafruit.com/product/3111)

### Part: Solder
quantity: 1
Mini Spool, 100g of 60/40 rosin-core solder.
[Solder](https://www.adafruit.com/product/145)

### Part: Right Angle USB Cable
quantity: 1
USB Cable which bends at a right angle, can fit easily inside the house.
[Right Angle USB Cable](https://www.adafruit.com/product/1318)

### Tools
The following tools will make this guide much easier to follow. If you do not have access to them, pick some up from the Adafruit Store:

### Part: Wire Cutters
quantity: 1
Hakko Professional Quality 20-30 AWG Wire Strippers - CSP-30-1
[Wire Cutters](https://www.adafruit.com/product/527)

### Part: Soldering Station
quantity: 1
Hakko FX-888D
[Soldering Station](https://www.adafruit.com/product/1204)

### Part: Helping Hands
quantity: 1
Helping Third Hand Magnifier W/Magnifying Glass Tool 
[Helping Hands](https://www.adafruit.com/product/291)

# Adafruit IO Home: Lights and Temperature 

## Putting it Together

![](https://cdn-learn.adafruit.com/assets/assets/000/059/698/medium800thumb/raspberry_pi_roof-to-base.jpg?1535055954)

## Installing the Roof NeoPixel Strip
First, we're going to test-fit the Mini Skinny NeoPixel strip by lining it around the edge of the roof. Temporarily tape it down to the roof and ensure a snug fit.&nbsp;

Make sure when you're lining it up that the 2-Pin JST faces the&nbsp;_back_ of the house. This'll keep the wires hidden behind the house.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/633/medium800/raspberry_pi_IMG_6562.jpg?1534972643)

We're going to cut the NeoPixel strip to fit the exact length of the roofline. There are cut-lines every 7mm along the strip. When you feel satisfied with the roof's NeoPixel strip layout, use a pair of wire cutters to cut along one of these lines.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/636/medium800/raspberry_pi_IMG_6751.png?1534973772)

While the NeoPixel strip will fit underneath the roof with the waterproof sheathing, we want it to have a more flush fit. You can easily cut the sheathing with wire cutters to remove it completely.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/634/medium800/raspberry_pi_IMG_6738.jpg?1534973359)

Using a hot glue gun, affix the NeoPixel strip to the roof. Lay down a line of hot glue, and press the strip into the roof edges. Hold it in place for at least five seconds to ensure it sticks and stays. Repeat along all edges of the roof.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/637/medium800thumb/raspberry_pi_gluegif.jpg?1534973989)

After you're finished with all sides of the roof, flip it upside down to let the hot glue dry for an hour or so.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/640/medium800/raspberry_pi_IMG_6569.jpg?1534974850)

While the roof dries, lets wire up the Si7021 sensor.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/641/medium800/raspberry_pi_arduino-wiring-sensor-only.png?1534975150)

Make the following connections **between the Feather HUZZAH and the Si7021:**

- **Feather Huzzah 3V** to **Si7021 Vin**
- **Feather Huzzah GND&nbsp;** to&nbsp; **Si7021 GND**
- **Feather Huzzah SCL&nbsp;** to&nbsp; **Si7021 SCL**
- **Feather Huzzah SDA&nbsp;** to&nbsp; **Si7021 SDA**

## Wiring the NeoPixel Jewel
Start by cutting three lengths of solid-core wire for the power (_red_), ground (_black_) and data-in (_green_). You can use a ruler to measure the height from the breadboard to the middle of the house and cut all three of the wires to the same length.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/643/medium800/raspberry_pi_cutters.png?1534975379)

Strip one end of the red wire and push it through the hole for power (PWR) on the&nbsp;_front_&nbsp;of the NeoPixel Jewel. Once it's secured, solder it to the pad on the back of the jewel. You can use a pair of helping hands to hold the wire and the jewel so that your hands are free to solder.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/668/medium800thumb/raspberry_pi_solderjewel.jpg?1535032502)

Clip the excess wire from the back of the NeoPixel Jewel

![](https://cdn-learn.adafruit.com/assets/assets/000/059/649/medium800/raspberry_pi_IMG_6689.jpg?1534975771)

And repeat the process for the data and ground wires.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/650/medium800/raspberry_pi_IMG_6700.jpg?1534975843)

The hot glue should have cured completely by now - let's finish the wiring.

## Wiring the Strip and Jewel
Put the roof back on the house. The 2-Pin JST cable bundle should be facing the back of the house.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/651/medium800/raspberry_pi_IMG_6574.jpg?1534976015)

While the 2-Pin JST connector connects data and ground, we'd like to include power in our quick-disconnect. To do this, we'll remove the 2-Pin JST connector&nbsp; and replace it with a 3-Pin JST connector. With a pair of wire cutters, snip off the 2-Pin JST header.&nbsp;

We'll attach the NeoPixel Jewel to the 3-Pin JST receptacle. While the order of these wires do not matter, make sure you solder Power, Ground and Data Out to the pads on the NeoPixel Jewel.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/671/medium800/raspberry_pi_jst-hold.png?1535033255)

## Arduino Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/059/673/medium800/raspberry_pi_arduino-wiring-bb.png?1535034452)

Make the following connections **between the Feather Huzzah and the NeoPixel Jewel:**

- **Feather Huzzah 3V&nbsp;** to **NeoPixel Jewel PWR**
- **Feather Huzzah GND&nbsp;** to&nbsp; **NeoPixel Jewel GND**
- **Feather Huzzah Digital Pin 16&nbsp;** to&nbsp; **Jewel Din**

This wiring diagram also illustrates the wiring for the JST SM plug and receptacle.&nbsp;

The breadboard wiring should look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/674/medium800/raspberry_pi_jst-jewel.png?1535034780)

Cut a small, rectangular, hole in the back of the house large enough for the JST plug and a USB Cable.

Place the breadboard inside the house and route the Mini-USB and 3-Pin JST Plug outside of the house.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/675/medium800/raspberry_pi_inside-house-layout.png?1535034874)

Connect the JST plug into the receptacle and connect the USB to your computer.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/676/medium800thumb/raspberry_pi_jst_plug_in.jpg?1535035693)

Next, we'll setup Adafruit IO for this project.

# Adafruit IO Home: Lights and Temperature 

## Adafruit IO Setup

If you are new to using Adafruit IO, [you can read all about it in this guide](https://learn.adafruit.com/welcome-to-adafruit-io?view=all "Welcome to Adafruit IO Guide"). Go ahead and get your account started.

Visit your [Adafruit IO Profile page](https://io.adafruit.com/profile) and click the&nbsp; **VIEW AIO KEY&nbsp;** button on the left-sidebar.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/677/medium800/raspberry_pi_microcontrollers_view-aio-key.png?1535042490)

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

![](https://cdn-learn.adafruit.com/assets/assets/000/059/678/medium800/raspberry_pi_microcontrollers_aio-popup-window.png?1535042506)

## Set Up Feeds
The IO House Series will eventually contain a large amount of Adafruit IO Feeds, which store data. There is one feed per each unique source of data.&nbsp;

To create a feed for the lights inside the house, navigate to the&nbsp;[Adafruit IO Feeds Page](https://io.adafruit.com/feeds)&nbsp;and click **Actions-\>Create a New Feed.&nbsp;** Name the new feed _inside-lights.&nbsp;_

![](https://cdn-learn.adafruit.com/assets/assets/000/059/962/medium800/raspberry_pi_IO_-_Feeds.png?1535133487)

Next, we're going to create the other feeds which will be used by our house. Create a feed for each of the following: **temperature** , **humidity** ,&nbsp; **outside-lights**.

- If you do not know how to create feeds,&nbsp;[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.

## Creating an Adafruit IO Dashboard
![](https://cdn-learn.adafruit.com/assets/assets/000/059/898/medium800thumb/raspberry_pi_dashboard_create.jpg?1535127946)

Next, we'll create an Adafruit IO Dashboard to display and control our feeds. [Navigate to the Adafruit IO Dashboard page](https://io.adafruit.com/dashboards) and click **Actions-\>Create a New Dashboard**.

Name this dashboard&nbsp; **IO House** and **click**  **Create.&nbsp;** You'll be re-directed to the new Dashboard.

We're going to **create two Color Picker blocks** to control our inside and outside lighting.

From the IO House Dashboard, **click the blue plus icon** to add a new block to the dashboard.&nbsp;Then, from the list of available blocks, **click the color-picker&nbsp;** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/682/medium800/raspberry_pi_io-color-block.png?1535044760)

&nbsp;Select the _indoor-lights_ feed created earlier.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/963/medium800/raspberry_pi_lights-selection.png?1535133738)

A new Color Picker block should appear on your dashboard. Repeat these steps to create another color picker for the outside lights. Your dashboard should look like the following:

![](https://cdn-learn.adafruit.com/assets/assets/000/059/685/medium800/raspberry_pi_io-lights-dash.png?1535045155)

We also need a way to display our temperature and humidity feeds. We'll **create a new block** , this time picking the Gauge block, a read-only block that shows a fixed range of values. Select the temperature feed from&nbsp;_My Feeds._

We're going to **configure the gauge block** with a title of&nbsp;temperature, a minimum value of zero degrees Fahrenheit, and a maximum of 220 degrees&nbsp;Fahrenheit.

The gauges in Adafruit IO have recently been improved to include warning values. We'll set them to the freezing point (32 degrees&nbsp;Fahrenheit) and the boiling point (212 degrees&nbsp;Fahrenheit) of water.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/687/medium800/raspberry_pi_io-gauge-temp.png?1535045695)

Then, repeat the process of creating a gauge element to display the relative humidity. Your dashboard should look like the following (I added two text blocks to separate the light control and data monitoring parts of the dashboard).

![](https://cdn-learn.adafruit.com/assets/assets/000/059/688/medium800/raspberry_pi_dash-lights-main.png?1535046086)

Next, let's set up the Arduino IDE for use with this project.

# Adafruit IO Home: Lights and Temperature 

## 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.

Next, we'll need to install the Adafruit Si7021 library. In the Arduino Library Manager's search-bar, type&nbsp;  
**Adafruit Si7021&nbsp;** to search for the library. Click&nbsp; **Install.&nbsp;**

![](https://cdn-learn.adafruit.com/assets/assets/000/059/691/medium800/raspberry_pi_si7021_lib_manager.png?1535047239)

We'll need a library to control the NeoPixels. In the search bar, enter&nbsp; **Adafruit** &nbsp; **NeoPixel.&nbsp;** Click&nbsp; **Install.**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/426/medium800/raspberry_pi_Library_Manager_NeoPixels.png?1535647623)

## Opening the Code

The code for this guide is stored within the latest Adafruit IO Arduino Library release&nbsp;(versions =\>2.7.17). From the Arduino IDE, navigate to **File-\>Examples-\>Adafruit IO Arduino -\> io\_home\_series -\> neopixel\_and\_thermometer.**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/203/medium800/raspberry_pi_sketch_Selection.png?1535401872)

The IDE should open the sketch (_neopixel\_and\_thermometer.ino_) and the configuration file (_config.h_):

![](https://cdn-learn.adafruit.com/assets/assets/000/060/166/medium800/raspberry_pi_sketch_config.png?1535397646)

You should now have all the libraries and code required for the IO Home set up. Let's move on to configuring the sketch with your wireless network and Adafruit IO credentials.&nbsp;

# Adafruit IO Home: Lights and Temperature 

## 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 Home: Lights and Temperature 

## Arduino Code

We're going to take a walk through the code, load it onto our Feather Huzzah, and interact with it using the Adafruit IO Dashboard we made earlier.&nbsp;

The code assumes the **NeoPixel strip is connected to the Feather Huzzah's digital pin 2** and the **NeoPixel jewel is connected to digital pin 16**. Both of these pins can be changed by modifying the `STRIP_PIN` and `JEWEL_PIN` variables at the beginning of the code.

The code initializes the NeoPixel strip,&nbsp;NeoPixel jewel and the Si7021 sensor objects. It also sets up feeds for the outdoor lights, indoor lights, humidity, and temperature.

```
// initalize neopixel strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
// initalize neopixel jewel
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);

// initalize the sensor object
Adafruit_Si7021 sensor = Adafruit_Si7021();

// set up the Adafruit IO feeds
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
AdafruitIO_Feed *humidity = io.feed("humidity");
AdafruitIO_Feed *temperature = io.feed("temperature");
```

The next chunk of code within `setup()`&nbsp;connects to Adafruit IO, registers two messages handlers to subscribe to the&nbsp;_indoorLights&nbsp;_and&nbsp;_outdoorLights_&nbsp;feeds. We also initialize the Si7021 sensor, NeoPixel strip, and NeoPixel jewel. Then, we set all NeoPixels in the house to `off`.&nbsp;

```
void setup() {

  // start the serial connection
  Serial.begin(115200);

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

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

  // subscribe to lighting feeds and register message handlers
  indoorLights-&gt;onMessage(indoorLightHandler);
  outdoorLights-&gt;onMessage(outdoorLightHandler);


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

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

  // initalize the Si7021 sensor
  if (!sensor.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    while (true);
  }
  Serial.println("Si7021 sensor set up!");
  
  // initalize the neopixel strip and jewel.
  strip.begin();
  jewel.begin();

  // set all neopixels on the strip and jewel to `off`.
  strip.show();
  jewel.show();
}
```

The next chunk of code is the main `loop()`. First, we call `io.run()`, which keeps the client connected to Adafruit IO. Then, we query the Si7021 for temperature and humidity values and print them to the Serial Monitor.

The code sends the feeds to Adafruit IO by saving the individual feeds to the data obtained. Finally, it delays the loop by `TEMP_DELAY` seconds to avoid flooding Adafruit IO with requests - you only get so many requests within a certain time period.

```
void loop() {
  io.run();

  temperatureData = sensor.readTemperature() * 1.8 + 32;
  humidityData = sensor.readHumidity();
  
  Serial.print("-&gt; Sending Temperature to Adafruit IO: ");
  Serial.println(temperatureData);
  Serial.print("-&gt; Sending Humidity to Adafruit IO: ");
  Serial.println(humidityData);

  // send the state of the feed to adafruit io
  temperature-&gt;save(temperatureData);
  humidity-&gt;save(humidityData);
  
  // delay the loop to avoid flooding Adafruit IO
  delay(1000*TEMP_DELAY);
}
```

The code uses have two separate message handlers: one for the outdoor lights and one for the indoor house light. Both of these functions operate in a similar fashion - whenever a message from either the&nbsp;_humidity&nbsp;_or&nbsp;_temperature_&nbsp;feed is received from Adafruit IO, the function is called. The function prints out the `data`&nbsp;value from the Adafruit IO feed as a hexadecimal value and converts it to a RGB value which the NeoPixel light can display.

Then, it sets the color of each individual pixel in the strip from zero to the \_PIXEL\_COUNT declared at the top of the file. Finally, it calls `strip.show()`&nbsp;to set the NeoPixel strip to the new color.

```
void indoorLightHandler(AdafruitIO_Data *data) {
  Serial.print("-&gt; indoor light HEX: ");
  Serial.println(data-&gt;value());

  long color = data-&gt;toNeoPixel();

  // set the color of each NeoPixel in the jewel
  for(int i=0; i&lt;JEWEL_PIXEL_COUNT; ++i) {
    jewel.setPixelColor(i, color);
  }
  // 'set' the neopixel jewel to the new color
  jewel.show();
}
```

Compile the code ( **Sketch-\>Verify/Compile** ) and upload (**Sketch-\>Upload)**&nbsp;it to your Feather Huzzah. Open the Serial Monitor ( **Tools-\>Serial Monitor** ) and you should see the following output:

```
Adafruit IO connected.
Si7021 sensor set up!
-&gt; Sending Temperature to Adafruit IO: 75
-&gt; Sending Humidity to Adafruit IO: 41

```

Navigate to your IO House's Dashboard. The temperature and humidity gauges should display the values from the Arduino Serial Monitor.

![](https://cdn-learn.adafruit.com/assets/assets/000/059/894/medium800thumb/raspberry_pi_scroll_temp_humid.jpg?1535127198)

Next, we'll test out the inside and outdoor lights from the dashboard. Click (or tap if you're on mobile) the color picker and select a color to set the lights to. You should see either the outdoor or inside lights change depending on which color picker was selected.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/143/medium800thumb/raspberry_pi_hero-houseseries-1.jpg?1535389785)

# Adafruit IO Home: Lights and Temperature 

## Python Wiring

This guide is also compatible with the Raspberry Pi using CircuitPython. We're going to build the house's lighting system, wire up the temperature and humidity monitoring circuit, and program it with CircuitPython.

The Pi Zero W has&nbsp; **built-in WiFi&nbsp;** - 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;

### 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)

While we could use a breadboard, we'll build our own pHAT for our IO House.

### 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...

In 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/699/medium800thumb/raspberry_pi_pi_zero_bonnet_solder.jpg?1535056100)

Follow the steps on the Putting it Together page until you reach the&nbsp;**[Arduino Wiring](https://learn.adafruit.com/adafruit-io-house-lights-and-temperature/putting-it-together#arduino-wiring)**. Instead of following that, use the Python Wiring below:

## Python Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/060/204/medium800/raspberry_pi_py-wiring.png?1535402380)

Make the following connections **between the Si7021 sensor to the Pi:**

- **Si7021 Vin&nbsp;** to **Pi 3V**
- **Si7021 GND&nbsp;** to&nbsp; **Pi Ground**
- **Si7021 SCL** to **Pi SCL**
- **Si7021 SDA&nbsp;** to&nbsp; **Pi SDA**

Make the following connections **between the NeoPixel Jewel to the Pi** :

- **NeoPixel Jewel GND** to **Pi GND**
- **NeoPixel Jewel PWR** to **Pi 3V**
- **NeoPixel Jewel DIN** &nbsp;to **Pi Digital Pin #18**

Make the following connections **between the 3-Pin JST Plug to the NeoPixel Jewel:**

- **NeoPixel Jewel GND** to&nbsp; **JST Left Pin**
- **NeoPixel Jewel DOUT** to **JST Middle Pin**
- **NeoPixel Jewel PWR** to **JST Right Pin**

Lastly, we'll connect the **NeoPixel stick to the 3-Pin JST receptacle:**

- **NeoPixel Stick GND** to **JST Left Pin**
- **NeoPixel Stick DI** to **&nbsp;JST&nbsp;Middle Pin**
- **NeoPixel Stick +5V** to **&nbsp;JST Right Pin**

 **Note:** &nbsp;Make sure the NeoPixel strip has arrows pointing **upwards** ,&nbsp;towards the NeoPixel

![raspberry_pi_fritzing_python_closeup.png](https://cdn-learn.adafruit.com/assets/assets/000/059/967/medium640/raspberry_pi_fritzing_python_closeup.png?1535138762)

After wiring it up, plug the 3-Pin JST from your bonnet into the&nbsp;receptacle from the roof.&nbsp; Plug the Pi's **PWR IN&nbsp;** into a [5V 2.5A switching power supply](https://www.adafruit.com/product/1995).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/059/705/medium800/raspberry_pi_si-temp-python.jpg?1535057364)

Next, we're going to set up the Raspberry Pi Zero for use with CircuitPython, Adafruit IO, NeoPixels, and the Si7021.

# Adafruit IO Home: Lights and Temperature 

## Python Setup

![](https://cdn-learn.adafruit.com/assets/assets/000/060/135/medium800/raspberry_pi_blinka-hearts-pi-io.png?1535384171)

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/or the Adafruit IO Python Library yet on your Raspberry Pi** , follow our guide before continuing with the steps on this page:

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

## Enable I2C

We "talk" to the Si7021 sensor over I2C. To do this, we'll need to set up our Pi's I2C interface. You only have to do this&nbsp;_once per Raspberry Pi_,&nbsp;the 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 I2C 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/973/medium800/raspberry_pi_i2cdetect.png?1535142074)

## Installing the Adafruit\_CircuitPython\_Si7021 Sensor Library

We'll need libraries to communicate with the Si7021 sensor. Since we're using Adafruit Blinka (CircuitPython), we can install CircuitPython libraries straight to our Raspberry Pi by using PyPi.

Enter the following command into your terminal to install the **adafruit\_circuitpython\_si7021** library:

`sudo pip3 install adafruit-circuitpython-si7021`

## Installing the Adafruit\_CircuitPython\_NeoPixel Library

To control our NeoPixels, we'll use the [NeoPixel Library for CircuitPython](https://pypi.org/project/adafruit-circuitpython-neopixel/).&nbsp;

Enter the following command into your terminal to install the&nbsp; **Adafruit\_CircuitPython\_NeoPixel** library:

`sudo pip3 install Adafruit_CircuitPython_NeoPixel`

## Python Code Setup

The code for this guide is located on the [Adafruit Learning Guides repository on GitHub under the IO House Series](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/IO_House_Series/).&nbsp;

If you'd like to directly load this code on your Pi, **type the following in your terminal and press enter:**

`git clone https://github.com/adafruit/Adafruit_Learning_System_Guides.git`

Then, navigate to the directory where the code for this tutorial is located by typing the following into your terminal:

`cd Adafruit_Learning_System_Guides/IO_House_Series/Lights_and_Temp`

Let's check to make sure the python code is within that directory. **To do this, type `ls` into your terminal and hit enter.&nbsp;** You should see `io_house_light_temp.py` in this directory:

![](https://cdn-learn.adafruit.com/assets/assets/000/060/132/medium800/raspberry_pi_1__pi_io-pi____Adafruit_Learning_System_Guides_IO_House_Series_Lights_and_Temp__ssh_.png?1535382276)

 **Before running the code, we need to set our Adafruit IO Key** (`ADAFRUIT_IO_KEY`) **and Adafruit IO Username** (`ADAFRUIT_IO_USERNAME`).

To do this, open the code in your text editor of choice (I'm using nano for this example) by entering the following into your terminal:

` nano code.py`

The code should open in the nano editor. Scroll down to the&nbsp;`Adafruit_IO_KEY`&nbsp;variable and set it to the your Adafruit IO Key. Then, set the `Adafruit_IO_USERNAME` to your Adafruit IO Username.

- If you do not have these values, [navigate to your Adafruit IO Profile page](https://io.adafruit.com/profile) and click_&nbsp;ACTIVE IO KEY_

![](https://cdn-learn.adafruit.com/assets/assets/000/060/134/medium800thumb/raspberry_pi_Kapture_2018-08-27_at_11.16.27.jpg?1535383896)

When you're done editing the values, **save the file by pressing control + x**.

When prompted to save the modified buffer, **type _Y&nbsp;_and press enter**.

At the&nbsp;_File Name to Write&nbsp;_prompt, **press enter** and you should be directed back to the terminal.

Next, we're going to learn how the code works and run it from our Pi.

# Adafruit IO Home: Lights and Temperature 

## Python Code

The first large chunk of code creates an instance of the Adafruit IO REST client and sets up the feeds we created earlier in the guide. Then, it creates an I2C interface object and passes it to the sensor.

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

# set up Adafruit IO feeds
temperature = aio.feeds('temperature')
humidity = aio.feeds('humidity')
outdoor_lights = aio.feeds('outdoor-lights')
indoor_lights = aio.feeds('indoor-lights')

# create an i2c interface object
i2c = I2C(SCL, SDA)

# instanciate the sensor object
sensor = adafruit_si7021.SI7021(i2c)
```

In the `while True`&nbsp;loop, we obtain the temperature and humidity data from the sensor. Then, we print out and send this data to Adafruit IO using&nbsp;`aio.send()`

```
# get data from the si7021 sensor
temperature_data = sensor.temperature
humidity_data = sensor.relative_humidity

# send data to adafruit io
print('&gt; Temperature: ', int(temperature_data))
aio.send(temperature.key, int(temperature_data))
print('&gt; Humidity :', int(humidity_data))
aio.send(temperature.key, int(humidity_data))
```

Next, we get the hex value from the color picker on the dashboard by using the `aio.receive()` method. The hex is then converted to individual RGB values using the io-python-client library's helper functions.&nbsp;

```
# get the indoor light color picker feed
indoor_light_data = aio.receive(indoor_lights.key)
# convert the hex values to RGB values
red = aio.toRed(indoor_light_data.value)
green = aio.toGreen(indoor_light_data.value)
blue = aio.toBlue(indoor_light_data.value)
```

To set the color of the NeoPixel Strip or Jewel, we use a loop to set the color of each pixel.&nbsp;

```
    # set the jewel's color
    for i in range(JEWEL_PIXEL_COUNT):
        pixels[i] = (red, green, blue)
        pixels.show()
```

Enter the following command into your terminal to run the code:

`sudo python3 io_house_light_temp.py`

**Note:&nbsp;** The NeoPixel library will&nbsp;_not_ work without prepending the script with `sudo`, as peripherals need to be run as root on the Raspberry Pi.

You should see the code sending the humidity and temperature values to the Adafruit IO dashboard:

```
Adafruit IO Home: Lights and Climate Control
&gt; Temperature:  24
&gt; Humidity : 57

```

Visit the IO-Home Dashboard you created on Adafruit IO. You should see the temperature and humidity gauges reflect the values sent from your code.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/015/medium800thumb/raspberry_pi_scroll_temp_humid.jpg?1535216020)

Change the color picker on the Adafruit IO dashboard and you should see the colors change!

```
&lt; Indoor Light HEX:  #52ff00
&lt; Outdoor Light HEX:  #000000
```

![](https://cdn-learn.adafruit.com/assets/assets/000/060/014/medium800thumb/raspberry_pi_colorchangeio.jpg?1535215998)

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


## Featured Products

### Assembled Adafruit Feather HUZZAH with ESP8266 With Headers

[Assembled Adafruit Feather HUZZAH with ESP8266 With Headers](https://www.adafruit.com/product/3046)
Feather is the flagship 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 **Assembled Adafruit Feather HUZZAH ESP8266**  **with...**

In Stock
[Buy Now](https://www.adafruit.com/product/3046)
[Related Guides to the Product](https://learn.adafruit.com/products/3046/guides)
### 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)
### Adafruit Si7021 Temperature & Humidity Sensor Breakout Board

[Adafruit Si7021 Temperature & Humidity Sensor Breakout Board](https://www.adafruit.com/product/3251)
It's summer and you're sweating and your hair's all frizzy and all you really want to know is why the weatherman said this morning that today's relative humidity would max out at a perfectly reasonable 42% when it feels more like 77%. Enter the&nbsp; **Si7021 Temperature +...**

In Stock
[Buy Now](https://www.adafruit.com/product/3251)
[Related Guides to the Product](https://learn.adafruit.com/products/3251/guides)
### NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers

[NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/2226)
Be the belle of the ball with the NeoPixel Jewel! &nbsp;We fit seven of our tiny&nbsp;5050 (5mm x 5mm) smart RGB LEDs onto a beautiful, round&nbsp;PCB with mounting holes and a chainable design to create what we think is our most elegant (and evening-wear appropriate) NeoPixel board...

In Stock
[Buy Now](https://www.adafruit.com/product/2226)
[Related Guides to the Product](https://learn.adafruit.com/products/2226/guides)
### Adafruit Mini Skinny NeoPixel Digital RGB LED Strip - 60 LED/m

[Adafruit Mini Skinny NeoPixel Digital RGB LED Strip - 60 LED/m](https://www.adafruit.com/product/2964)
So thin. So mini. So teeeeeeny-tiny. It's the 'skinny' version of our classic NeoPixel strips!

These NeoPixel strips have 60 digitally-addressable pixel Mini LEDs per meter and are very affordable and are only 7.5 mm wide, 5 mm if you remove the strip from the...

In Stock
[Buy Now](https://www.adafruit.com/product/2964)
[Related Guides to the Product](https://learn.adafruit.com/products/2964/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Right Angle USB cable - A/MicroB

[Right Angle USB cable - A/MicroB](https://www.adafruit.com/product/1318)
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0, but with a twist! Literally! Instead of the cable coming straight out from the connector, there's a right angle bend. We thought this might make a good pair for a Raspberry Pi **Model A or B** as the cable...

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

## Related Guides

- [Adafruit Si7021 Temperature + Humidity Sensor](https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor.md)
- [NeoPixel LED Necklace Insert with USB Charging](https://learn.adafruit.com/neopixel-led-necklace-insert-with-usb-charging.md)
- [LED Harness Bra](https://learn.adafruit.com/neopixel-led-harness-bra.md)
- [Jewel Hair Stick](https://learn.adafruit.com/jewel-hair-stick.md)
- [NeoPixel Flame Torch](https://learn.adafruit.com/neopixel-flame-torch.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Edge-Lit Tavern Sign with WLED - Control with WiFi or IR Remote](https://learn.adafruit.com/edge-lit-tavern-sign-with-wled-control-with-wifi-or-ir-remote.md)
- [Introducing Adafruit Feather](https://learn.adafruit.com/adafruit-feather.md)
- [Overwatch Prop Gun: Lucio's Blaster Pt. 3](https://learn.adafruit.com/overwatch-prop-gun-lucios-blaster-pt-3.md)
- [IoT Temperature Logger with Analog Devices ADT7410, Feather and Adafruit IO](https://learn.adafruit.com/iot-temperature-logger-with-arduino-and-adafruit-io.md)
- [Adafruit NeoPixel Überguide](https://learn.adafruit.com/adafruit-neopixel-uberguide.md)
- [Fiber Optic Whip](https://learn.adafruit.com/fiber-optic-whip.md)
- [CircuitPython 2FA TOTP Authentication Friend](https://learn.adafruit.com/circuitpython-totp-otp-2fa-authy-authenticator-friend.md)
- [Humidity and Temperature Monitor with E-Ink Display](https://learn.adafruit.com/humidity-and-temperature-monitor-redux-e-ink-display.md)
- [3D Printed Glowing Mace Prop](https://learn.adafruit.com/3d-printed-glowing-mace-prop.md)
- [Adafruit IO Home: Security ](https://learn.adafruit.com/adafruit-io-home-security.md)
