# Adafruit IO Home: Security 

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/061/004/medium800thumb/sensors_front_alarm.jpg?1536181793)

## Home Security

A _smart_ home is a&nbsp;_safe_&nbsp;home. In this guide, we're going to take our cardboard smart-home and equip it with sensors to protect the home against intruders, wanna-be burglars, and invisible chemicals.&nbsp;

### What is the IO Home?

Interested in making your house a bit smarter?&nbsp; Why not start&nbsp;_small&nbsp;_by building a&nbsp; **Cardboard** &nbsp; **Smart** &nbsp; **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!

# Parts
### Door Sensor

We'll be building a small front door (out of cardboard, of course) for our home. We'll use a reed switch and magnet to detect if the door is open or closed. We'll be adding a toggle-block on our Adafruit IO dashboard to arm/dis-arm the system.

### Magnetic contact switch (door sensor)

[Magnetic contact switch (door sensor)](https://www.adafruit.com/product/375)
This sensor is essentially a reed switch, encased in an ABS plastic shell. Normally the reed is 'open' (no connection between the two wires). The other half is a magnet. When the magnet is less than 13mm (0.5") away, the reed switch closes. They're often used to detect when a...

In Stock
[Buy Now](https://www.adafruit.com/product/375)
[Related Guides to the Product](https://learn.adafruit.com/products/375/guides)
![Top view of magnetic contact switch with three screws.](https://cdn-shop.adafruit.com/640x480/375-01.jpg)

### Motion Sensor

We'll also utilize a PIR sensor to detect any intruders who hang out in front of our house after dark.

### PIR (motion) sensor

[PIR (motion) sensor](https://www.adafruit.com/product/189)
PIR sensors are used to detect motion from pets/humanoids from about 20 feet away (possibly works on zombies, not guaranteed). This one has an adjustable delay before firing (approx 2-4 seconds), adjustable sensitivity **and** we include a 1 foot (30 cm) cable with a socket so you...

In Stock
[Buy Now](https://www.adafruit.com/product/189)
[Related Guides to the Product](https://learn.adafruit.com/products/189/guides)
![PIR (motion) sensor with a cable around it.](https://cdn-shop.adafruit.com/640x480/189-00.jpg)

### Air Quality Sensor

Now, what about the thing most people don't think to monitor? We're talking about _invisible_ intruders&nbsp;- gasses and air particulates. While gasses and volatile organic compounds are already inside your home - you'd benefit from adding the ability to measure them. The SGP30 Air Quality Sensor is one of our favorite sensors - it can monitor both the amount of&nbsp;[Carbon Dioxide](https://www.co2meter.com/blogs/news/1209952-co-and-co2-what-s-the-difference)&nbsp;and [Volatile Organic Compounds](http://www.npi.gov.au/resource/total-volatile-organic-compounds) in your home's air.

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

Out of 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)

## Alarm System

&nbsp;A piezo buzzer and a NeoPixel Jewel are used in this guide as a combination of visual and audio alerts to notify you when your home has detected an after-dark intruder.

### Part: Piezo Buzzer
quantity: 1
Small, but mighty, buzzer.
[Piezo Buzzer](https://www.adafruit.com/product/160)

### Part: NeoPixel Jewel
quantity: 1
NeoPixel Jewel - 7 x 5050 RGB LED with Integrated Drivers
[NeoPixel Jewel](https://www.adafruit.com/product/2226)

To use this guide, we'll need a microcontroller capable of connecting to Adafruit IO. The Feather HUZZAH with ESP8266 is used in most of our Adafruit IO Guides.

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

Out of 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

You'll need these extra materials to assemble the home security system.

### 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 sensors.
[Breadboarding Wire Bundle](https://www.adafruit.com/product/153)

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

Owning, or having access to, these 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: Ruler
quantity: 1
Our snazzy PCB reference ruler. You don't need THIS ruler, but you do need a ruler. 
[Ruler](https://www.adafruit.com/product/1554)

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

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

- X-Acto Knife, Box Cutter, or Sharp Knife
- Hot Glue Gun
- Double Sided Tape

# Adafruit IO Home: Security 

## Putting it Together

If you've been following along with the Adafruit IO Home Series, you should have already built and wired the house's lighting system.

- [If you need to assemble your house, click here to read the previous guide's Putting it Together page.](https://learn.adafruit.com/adafruit-io-house-lights-and-temperature/putting-it-together)

## Adding a Motion Sensor (PIR)
A PIR sensor will be used to detect motion in front of the home. PIR sensors can detect motion from about twenty feet away.&nbsp;

&nbsp;

- Interested in learning more about PIR Sensors? We have a&nbsp;[full tutorial with information about these Pyroelectric InfraRed Sensors.](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor)

&nbsp;

We're going to mount it on the front-face of the home. The PIR sensor used for this guide has a lens with a square base of 23mm x 23mm.&nbsp;

![sensors_IMG_6948.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/304/medium640/sensors_IMG_6948.jpg?1535486669)

&nbsp;

Measure and mark a 24mm x 24mm square on the front face of the home. We'll leave a little bit of room to push the sensor's lens through the home.

![sensors_IMG_6956.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/306/medium640/sensors_IMG_6956.jpg?1535486996)

![sensors_IMG_6958.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/319/medium640/sensors_IMG_6958.jpg?1535488668)

Using an X-Acto knife or a box cutter, make small scores on each side of the rectangle, one-by-one, until you have a rectangular hole.&nbsp;

Test-fit the sensor through the hole. The lens should poke through.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/313/medium800thumb/sensors_box_cutting.jpg?1535487810)

Before pushing the PIR sensor through the hole we created, ensure the 3-pin cable is properly connected to the ground, signal, and power pins.

&nbsp;

Then, push it through the hole we cut in the cardboard.

![sensors_IMG_6966.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/316/medium640/sensors_IMG_6966.jpg?1535487994)

![sensors_IMG_6964.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/317/medium640/sensors_IMG_6964.jpg?1535488051)

## Adding the Door Sensor
Next, we're going to add a door and a sensor to detect when the door is either open or closed. We'll be using a [reed switch](https://www.adafruit.com/product/375) to accomplish this. These super simple sensors operate on the principle that when a magnet is less than 0.5" away, the reed switch internally closes. We'll detect this change with the Feather HUZZAH and send the value to the Adafruit IO Dashboard's&nbsp;_Door Status Indicator_.

These switches aren't _just_ for an IO Cardboard Home, they've been used in real-world Adafruit Learning Guides such as the&nbsp;[_IO Door Detector_](https://learn.adafruit.com/using-ifttt-with-adafruit-io).&nbsp;

Using a hot glue gun, glue the reed switch to the side of the door-frame.&nbsp;

&nbsp;

If you don't have a hot glue gun handy, you can substitute a piece of double-sided tape instead.&nbsp;

![sensors_glue-magnet.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/320/medium640thumb/sensors_glue-magnet.jpg?1535488926)

_Oh no..._our house does not have a door.&nbsp;But we can **build one out of _CARDBOARD_!**

First, take measurements of the doorframe using a [ruler](https://www.adafruit.com/product/1554) or pair of [digital calipers](https://www.adafruit.com/product/3720). We measured ours to be 58mm tall and 28.6mm wide, but rounded down for cutting out the door.

![sensors_IMG_7062.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/326/medium640/sensors_IMG_7062.jpg?1535489761)

Next, grab the closest empty Adafruit/Amazon/DigiKey box (We&nbsp;_know_&nbsp;you have some around, we do!).

&nbsp;

Using a ruler, sketch a door on a this piece of cardboard. Then, cut it out using a pair of scissors or a knife.

![sensors_IMG_7111.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/405/medium640/sensors_IMG_7111.jpg?1535556283)

![sensors_IMG_7133.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/406/medium640/sensors_IMG_7133.jpg?1535556296)

We'll want a a way for the door to open and close. To create the door hinge, use a Bamboo skewer and poke it through the corrugated cardboard's fluting.

&nbsp;

![sensors_bamboo_door.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/324/medium640thumb/sensors_bamboo_door.jpg?1535489698)

Using double sided tape or hot glue, affix the magnet onto the door.&nbsp;

![sensors_glue-hinge.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/328/medium640thumb/sensors_glue-hinge.jpg?1535490458)

Test-fit the hinge and make sure the door doesn't catch on the either the sensor or the frame.

Also - make sure the magnet passes the reed switch when it's opened.&nbsp;

![sensors_hinge-fit.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/327/medium640thumb/sensors_hinge-fit.jpg?1535490101)

To finish off the assembly, we'll use transparent tape to affix the PIR sensor and the top of the door skewer to the front face of the home.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/060/329/medium800/sensors_IMG_7067.jpg?1535490741)

Next, we'll wire up our hardware!

# Adafruit IO Home: Security 

## Adafruit IO Setup

_New to Adafruit IO?_&nbsp;[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 set up, and come back to this page when you're ready.

We'll need to obtain our Adafruit IO Key and Username. Visit your&nbsp;[Adafruit IO Profile page](https://io.adafruit.com/profile)&nbsp;and click the&nbsp; **VIEW AIO KEY&nbsp;** button on the left-sidebar.

![sensors_io-active-key.png](https://cdn-learn.adafruit.com/assets/assets/000/060/268/medium640/sensors_io-active-key.png?1535485392)

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/060/269/medium800/sensors_raspberry_pi_microcontrollers_aio-popup-window.png?1535483696)

## Setting up Adafruit IO Feeds
We are going to create a new feed per each unique source of data. We'll use feeds for a variety of data, from the home's eCO2 level to the colors of the lights inside the house.

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/060/270/medium800/sensors_raspberry_pi_IO_-_Feeds.png?1535483858)

Next, we're going to create the other feeds which will be used by our house. Create a feed for each of the following:&nbsp;_ **outside-lights, eco2, tvoc, front-door, motion-detector,&nbsp;and&nbsp;alarm-status** _

- 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 the Adafruit IO Dashboard
![](https://cdn-learn.adafruit.com/assets/assets/000/060/914/medium800thumb/sensors_dash_create.jpg?1536093270)

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 Home** and **click**  **Create.&nbsp;** You'll be re-directed to the new Dashboard. If you have already created a dashboard using the previous IO Home learning guide, you can disregard this step.

## Adding Status Indicators
We're going to&nbsp; **create three Indicator Blocks&nbsp;** to monitor the status of our security system and environmental sensor.&nbsp;

From the IO Home dashboard, click the&nbsp; **blue plus icon&nbsp;** to add a new block to the dashboard. Click the&nbsp; **indicator block** , select the front-door feed, configure its settings, and click&nbsp; **create block**.&nbsp;

We're going to&nbsp; **create three Indicator Blocks&nbsp;** to monitor the status of our security system and environmental sensor.&nbsp;&nbsp;

&nbsp;

From the IO Home dashboard, **click the&nbsp;blue plus icon&nbsp;** to add a new block to the dashboard. **Click the&nbsp;indicator block** , **select the front-door feed** , **configure its settings** , and **click&nbsp;create block.&nbsp;**

&nbsp;

Repeat this process for the _motion-detector&nbsp;_feed.

![sensors_io-indicator-block.png](https://cdn-learn.adafruit.com/assets/assets/000/060/295/medium640/sensors_io-indicator-block.png?1535485312)

![sensors_io-feed-indicator-choose.png](https://cdn-learn.adafruit.com/assets/assets/000/060/296/medium640/sensors_io-feed-indicator-choose.png?1535485331)

![sensors_io-indicator-block-3.png](https://cdn-learn.adafruit.com/assets/assets/000/060/297/medium640/sensors_io-indicator-block-3.png?1535485361)

We'll take advantage of the&nbsp;_Conditions_ feature of the Indicator Block. You can set conditions to trigger the block's off color. We're going to set a condition for "when the CO2 sensor (SGP30) feed receives a value greater than 2000 (parts per million), set the indicator to the off color".&nbsp;

![sensors_notification-co2-block.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/298/medium640thumb/sensors_notification-co2-block.jpg?1535485743)

## Adding Alarm Controls

What good is an is a security system if it can only notify you? Let's add controls for an alarm system to scare off wanna-be intruders.

**Add a toggle block** to your dashboard, and **connect it to an&nbsp;_alarm-status&nbsp;_feed**.

Here's an example of the dashboard we made for this guide. You can go crazy and add buttons/switches/colors, or keep it tame and add only what you need.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/303/medium800/sensors_io-dashboard.png?1535486272)

 **Note:&nbsp;** The color picker blocks for lighting was created in the previous guide, [click here to read the Adafruit IO Setup portion of the guide](https://learn.adafruit.com/adafruit-io-house-lights-and-temperature/adafruit-io-setup).

Next, we're going to set up our hardware for use with Adafruit IO.

# Adafruit IO Home: Security 

## Arduino Wiring

The Wiring for this sketch is less complicated than it looks. We'll connect each sensor/output to the Feather individually.&nbsp;

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

&nbsp;

- **Feather 3V** to **SGP30 Vin**
- **Feather GND** to **SGP30 GND**
- **Feather SCL** to **SGP30 SCL**
- **Feather SDA** to **SGP30 SDA**

![sensors_sgp-wiring.png](https://cdn-learn.adafruit.com/assets/assets/000/060/420/medium640/sensors_sgp-wiring.png?1535646912)

Connect one end of the Piezo to Feather SCK.

&nbsp;

Connect the other end to GND.

![sensors_piezo.png](https://cdn-learn.adafruit.com/assets/assets/000/060/421/medium640/sensors_piezo.png?1535646989)

Make the following connections between the **Feather Huzzah and the Door Sensor (Reed Switch):**

&nbsp;

- **Feather Pin 2** to one end of the reed switch
- **Feather GND** to the other end of the reed switch

![sensors_reed-switch.png](https://cdn-learn.adafruit.com/assets/assets/000/060/422/medium640/sensors_reed-switch.png?1535647125)

![](https://cdn-learn.adafruit.com/assets/assets/000/060/419/medium800/sensors_arduino-hero-wiring.png?1535645531)

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

- **Feather GND** to **NeoPixel Jewel GND**
- **Feather 3V** to **NeoPixel Jewel PWR**
- **Feather Pin 12** to **NeoPixel Jewel DIN**

Make the following connections between the **Feather Huzzah and the PIR Sensor:**

- **Feather USB** to **PIR +5V**
- **Feather GND** to **PIR GND**
- **Feather 13** to **PIR Signal**

Next, let's set up our Arduino for this project.

# Adafruit IO Home: Security 

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

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/424/medium800/sensors_Library_Manager_NeoPixels.png?1535647569)

We'll need a library to read the SGP30 sensor. In the search bar, enter&nbsp; **Adafruit** &nbsp; **SGP30.&nbsp;** Click&nbsp; **Install.**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/425/medium800/sensors_Library_Manager_SGP30.png?1535647578)

## 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 -\> io\_home\_security.ino**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/870/medium800/sensors_io-home-sketch.png?1536077516)

The IDE should open the sketch (_io\_home\_security.ino_) and the configuration file (_config.h_):

![](https://cdn-learn.adafruit.com/assets/assets/000/060/431/medium800/sensors_io_home_security___Arduino_1_8_5.png?1535647832)

With those files open, let's configure the sketch for use with your Adafruit IO account and network.&nbsp;

# Adafruit IO Home: Security 

## 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: Security 

## Arduino Code

## Setting up the Sketch

Since we don't want our motion detector to alert us of daytime activities (like a dog passing by, or a skateboarder), we'll need to give the sketch (prior to uploading) the current hour, minutes and seconds. In the sketch, set `startingHour`, `currentMinutes`, and `currentSeconds` to the current time (we're using 24-hour time for this sketch). For the sketch to work properly, you'll need to change these values on every upload.

- While we're not using one for this project, you can add a Real-Time-Clock (like the [RTC FeatherWing](https://www.adafruit.com/product/3028)) if you'd like more precise timekeeping.&nbsp;

```
/**** Time Setup ****/
// set the current hour
int startingHour = 0;
// set the current minutes
int currentMinutes = 0;
// set the current seconds
int currentSeconds = 0;
```

## Code Overview
The first chunk of the code (`setup()`) starts a&nbsp;MQTT connection to the Adafruit IO server. We also add three message handlers to handle changes from the _indoor-lights, outdoor-lights_, and&nbsp;_home-alarm_&nbsp;feeds from the dashboard blocks. We also set up the PIR sensor, reed switch, SGP30 sensor, and initalize the NeoPixel strip.

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

  // wait for serial monitor to open
  while(! Serial);
  Serial.println("Adafruit IO Home: Security");
  
  Serial.println("Connecting to Adafruit IO");
  // start MQTT connection to io.adafruit.com
  io.connect();
  
  // attach a message handler for the `home-alarm` feed
  alarm-&gt;onMessage(handleAlarm);
  // subscribe to lighting feeds and register message handlers
  indoorLights-&gt;onMessage(indoorLightHandler);
  outdoorLights-&gt;onMessage(outdoorLightHandler);

  // wait for an MQTT connection
  // NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
  // method to check on MQTT connection status specifically
  while(io.mqttStatus() &lt; AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  // we are connected
  Serial.println();
  Serial.println(io.statusText());
  
  // declare PIR sensor as input
  pinMode(pirPin, INPUT);
  // declare reed switch as input
  pinMode(doorPin, INPUT);
  // set up the SGP30 sensor
  setupSGP30();
  // init the neopixel strip and set to `off`
  strip.begin();
  strip.show();
}
```

The next chunk of code (`loop()`) calls `io.run()`&nbsp;which keeps the client connected to Adafruit IO. Next, it makes a call to `getTime()` which calculates and returns the current time. Then we read the door, SGP30, and PIR sensor (`readDoorSensor`, `readPIR`, `readSGP30`) and send their values to their respective Adafruit IO feeds.

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

  getTime();
  Serial.println("* read door sensor...");
  readDoorSensor();
  Serial.println("* read motion detector");
  readPIR();
  Serial.println("* reading SGP30...");
  readSGP30();
}
```

The toggle button on your Adafruit IO dashboard is connected to the `handleAlarm` message handler. When the toggle button's value is changed, it receives the current value of the feed and checks if it's `ON` or `OFF`&nbsp;and sets the `isAlarm` boolean.

```
void handleAlarm(AdafruitIO_Data *data) {
// handle the alarm toggle on the Adafruit IO Dashboard
  String toggleValue = data-&gt;toString();
  Serial.print("&gt; rcv alarm: ");
  Serial.println(toggleValue);
  if(toggleValue == String("ON")) {
    Serial.println("* Alarm Set: ON");
    isAlarm = true;
  } else {
    Serial.println("* Alarm Set: OFF");
    isAlarm = false;
  }
}
```

Finally, we'll check if the alarm is armed (`isAlarm==true`). If the alarm is armed, we check if the door is open (`doorState == HIGH`) _or_ if the hour is later than `alarmHour`&nbsp; **and** if the motion detector is triggered, we'll make a call to the&nbsp;`playAlarmAnimation()`&nbsp;function.

```
  // check if the alarm toggle is armed from the dashboard
  if (isAlarm == true) {
    if (doorState == HIGH || (hour&gt;alarmHour &amp;&amp; pirState == HIGH)) {
      playAlarmAnimation();
   }
  }
```

## Using the Smart Home Security System
Connect your Feather Huzzah to USB and upload the **io\_home\_security** sketch.&nbsp;

Open up the IO-Home dashboard to interact with your smart home. Push the door open. You should see the&nbsp; **Front Door Indicator** change from green to red.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/434/medium800thumb/sensors_front_alarm.jpg?1535650707)

Switch the toggle from&nbsp; **OFF&nbsp;** to&nbsp; **ON&nbsp;** to arm your house's security system. When you push the front door open (or move past the PIR sensor past the time set by `alarmHour`), the inside lights will blink red and the piezo will make noise.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/432/medium800thumb/sensors_arm_front_alarm.jpg?1535650675)

Tired of the alarm? Want some peace and quiet? Toggle the alarm **OFF**.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/433/medium800thumb/sensors_disarm_system.jpg?1535650684)

# Adafruit IO Home: Security 

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

## Home&nbsp;Surveillance

Since we're using a Raspberry Pi, we're going to use the eight-megapixel Raspberry Pi Camera v2 to capture images from outside our home.&nbsp;

### Raspberry Pi Camera Board v2 - 8 Megapixels

[Raspberry Pi Camera Board v2 - 8 Megapixels](https://www.adafruit.com/product/3099)
Snap, snap! The Camera v2 is the new official camera board released by the Raspberry Pi Foundation!

The **Raspberry Pi Camera Board v2** is a high quality 8 megapixel Sony IMX219 image sensor custom designed add-on board for Raspberry Pi, featuring a fixed focus lens....

In Stock
[Buy Now](https://www.adafruit.com/product/3099)
[Related Guides to the Product](https://learn.adafruit.com/products/3099/guides)
![Angled shot of Raspberry Pi Camera Board v2 - 8 Megapixels connected to a flex cable and a Raspberry Pi.](https://cdn-shop.adafruit.com/640x480/3099-02.jpg)

Because the Pi Camera Board is designed for the Raspberry Pi and not the Raspberry Pi Zero, we'll use a Raspberry Pi Zero camera cable.

### Raspberry Pi Zero v1.3 Camera Cable

[Raspberry Pi Zero v1.3 Camera Cable](https://www.adafruit.com/product/3157)
This camera cable is specifically designed to work with the [Raspberry Pi Zero - Version 1.3](https://www.adafruit.com/product/2885)! Just plug it into your Pi Zero's camera port and then the other end into one of the official [Pi...](https://www.adafruit.com/categories/802)

In Stock
[Buy Now](https://www.adafruit.com/product/3157)
[Related Guides to the Product](https://learn.adafruit.com/products/3157/guides)
![Angled shot of a Raspberry Pi Zero v1.3 Camera Cable. ](https://cdn-shop.adafruit.com/640x480/3157-02.jpg)

Warning: 

## Connect the Raspberry Pi Camera
Remove the CSI cable which comes from the Pi Camera and replace it with the Pi Zero camera cable by lifting the collar of the camera module and removing the cable.

![sensors_remove_cable.png](https://cdn-learn.adafruit.com/assets/assets/000/060/437/medium640/sensors_remove_cable.png?1535660991)

Connect the wider end of the Pi Zero camera cable into to the Pi Camera.&nbsp;

![sensors_IMG_7212.jpg](https://cdn-learn.adafruit.com/assets/assets/000/060/438/medium640/sensors_IMG_7212.jpg?1535661078)

Open the collar on the Pi Zero W's camera connector. Push the camera cable through the connector, making sure the cable is seated firmly in place and the contacts are facing the back of the Pi Zero.

![sensors_connect_pi_Cam.png](https://cdn-learn.adafruit.com/assets/assets/000/060/439/medium640/sensors_connect_pi_Cam.png?1535661695)

## (Optional) Adding Quick Connects
While going through this project, I found it easiest to add a JST SM receptacle to the bonnet and attach the plug to the end of the cable. It makes it easy to quick connect / disconnect everything in your home from the Pi.

&nbsp;

I did this for both the PIR sensor (using a&nbsp;[3-pin JST)](https://www.adafruit.com/product/1663)&nbsp;and the reed switch (using a&nbsp;[2-pin JST](https://www.adafruit.com/product/2880)).

![sensors_jst-cable.png](https://cdn-learn.adafruit.com/assets/assets/000/060/440/medium640/sensors_jst-cable.png?1535662274)

![sensors_jst_qc.gif](https://cdn-learn.adafruit.com/assets/assets/000/060/441/medium640thumb/sensors_jst_qc.jpg?1535662401)

## Wiring the Pi
_\*pi camera not shown_

![](https://cdn-learn.adafruit.com/assets/assets/000/060/864/medium800/sensors_python-wiring-hero.png?1536068275)

 **NOTE:** Since this is a series, **we'll be building off what we built in&nbsp;[the previous guide](https://learn.adafruit.com/adafruit-io-house-lights-and-temperature/python-wiring)**, but adding a SGP30 (you can wire it by chaining SCL/SDA pins), the motion detector (PIR sensor), and a PiCam.

Connect the SGP30 to the Pi:

- **SGP30 SCL** to **Pi SCL**
- **SGP30 SDA** to **Pi SDA**
- **SGP30 GND** to **Pi GND**
- **SGP30 Vin** to **Pi 3V**

Connect the PIR Sensor to the Pi:

- **PIR 5V** to **Pi 5V**
- **PIR Signal** to **Pi GPIO #22**
- **PIR GND** to **Pi GND**

Connect the NeoPixel Jewel to the Pi:

- NeoPixel **Jewel GND** to **Pi GND**
- NeoPixel **Jewel PWR** to **Pi 3V**
- NeoPixel **Jewel IN** to **Pi GPIO #18**

Connect one wire of the **Reed Switch to Pi GPIO #24** , and connect the other wire to GND.

We're ready to power up - connect the plugs for the sensors and the neopixel strip/jewel to the appropriate receptacles and connect your Pi to a power supply.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/728/medium800thumb/sensors_jst_snap_pi.jpg?1535727265)

Next, let's move on to setting up your Pi.

# Adafruit IO Home: Security 

## Python Setup

![](https://cdn-learn.adafruit.com/assets/assets/000/060/729/medium800/sensors_blinka-hearts-pi-io.png?1535728597)

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&nbsp; **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)

## Enabling I2C

We "talk" to the Si7021 and SGP30 sensors 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/060/730/medium800/sensors_1__pi_io-pi_____ssh_.png?1535728686)

## Installing the Adafruit\_CircuitPython\_SGP30 Sensor Library

We'll need libraries to communicate with the SGP30 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\_SGP30** &nbsp;library:

`sudo pip3 install adafruit-circuitpython-sgp30`

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

## Installing and Configuring picamera

Depending on what distro you are using, picamera may be installed by default. You can check this by entering the following into your terminal:

```
python3 -c "import picamera"
```
If you get an error, something like the following:

```
Traceback (most recent call last):
File "&lt;string&gt;", line 1, in &lt;module&gt;
ImportError: No module named 'picamera'
```

You'll need to install picamera. We're going to enter two commands into our terminal to install it:

```
sudo apt-get update
sudo apt-get install python-picamera python3-picamera
```
Once you've got it installed, _or if you did not get an error earlier_, we'll configure our Raspberry Pi Zero for use with the camera.

**Type&nbsp;** `raspi-config`&nbsp;into your terminal and **press enter.**

You'll be greeted with the following screen. Using your arrow keys, navigate to&nbsp; **Interfacing Options&nbsp;** and **press the enter key**.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/748/medium800/sensors_raspi-config-1.png?1535748149)

The first option is to enable the camera, use your arrow keys to navigate to this option and&nbsp; **press enter.**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/749/medium800/sensors_pi-config-2.png?1535748161)

You'll be prompted to reboot the Pi. Use the arrow keys to select the&nbsp; **Yes&nbsp;** option and **press enter**.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/750/medium800/sensors_raspi-config-3.png?1535748168)

After the Pi reboots, test that the camera works by using the [raspistill](https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md) command:

`raspistill -o cam_test.jpg`

_If this command fails_, go back and check that you have enabled the camera using `raspi-config`&nbsp;and the cable is firmly connected to both the Pi's connector and the camera board's connector.&nbsp;

Typing `ls`&nbsp;into the terminal should return the `cam_test.jpg`&nbsp;file. You can copy this file off of the Pi and view it on your computer, too!

The Pi Camera is set up and ready to use!

![sensors_1__pi_io-pi____camera__ssh_.png](https://cdn-learn.adafruit.com/assets/assets/000/060/867/medium640/sensors_1__pi_io-pi____camera__ssh_.png?1536071969)

![sensors_camera-finder.png](https://cdn-learn.adafruit.com/assets/assets/000/060/868/medium640/sensors_camera-finder.png?1536072378)

## Adafruit IO Security Camera Dashboard Setup

Since we're using a camera, we'll need to make a small modification to our dashboard to display the feed with the images captured.&nbsp;

To do this, we'll **create a new feed called&nbsp;`picam`**.

Adafruit IO has a limit when it comes to image feeds - you can not store history for feeds containing large values (like base64-encoded images).&nbsp;

To avoid this, we'll turn off the feed's history. **N**** avigate to the feed page for the picam **and** click&nbsp;_Feed History_**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/060/912/medium800/sensors_IO_-_Feed__picam-1.png?1536091918)

From the popup, **disable feed history by setting it to _OFF_**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/060/913/medium800/sensors_IO_-_Feed__picam.png?1536091970)

## Python Code Setup

The code for this guide is located on the&nbsp;[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,&nbsp; **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/Security`

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

 **Before running the code, we need to set our Adafruit IO Key** (`ADAFRUIT_IO_KEY`)&nbsp; **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&nbsp;`Adafruit_IO_USERNAME`&nbsp;to your Adafruit IO Username.

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

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

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

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

At the&nbsp;_File Name to Write&nbsp;_prompt,&nbsp; **press enter** &nbsp;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: Security 

## Python Code

The first chunk of our code sets up the Adafruit IO Feeds:

```
tvoc_feed = aio.feeds('tvoc')
eco2_feed = aio.feeds('eco2')
door_feed = aio.feeds('front-door')
motion_feed = aio.feeds('motion-detector')
alarm_feed = aio.feeds('home-alarm')
outdoor_lights_feed = aio.feeds('outdoor-lights')
indoor_lights_Feed = aio.feeds('indoor-lights')
picam_feed = aio.feeds('picam')
```

Then, it sets up the camera, sensors, and NeoPixel Strip:

```
# set up PiCamera
camera = picamera.PiCamera()
camera.resolution = (320, 240)

# set up door sensor
door_sensor = digitalio.DigitalInOut(D5)
door_sensor.direction = digitalio.Direction.INPUT

# set up motion sensor
pir_sensor = digitalio.DigitalInOut(D6)
pir_sensor.direction = digitalio.Direction.INPUT
prev_pir_value = pir_sensor.value
is_pir_activated = False

# set up sgp30
i2c_bus = I2C(SCL, SDA, frequency=100000)
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus)

# set up the neopixel strip
pixels = neopixel.NeoPixel(D18, NUM_PIXELS_STRIP)
pixels.fill((0, 0, 0))
pixels.show()
```

In the loop (`while True`), we first take measurements for the `co2eq` and `tvoc` from the SGP30 and send those values to Adafruit IO.

```
  co2eq, tvoc = sgp30.iaq_measure()
  print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))
  # send SGP30 values to Adafruit IO
  aio.send(eco2_feed.key, co2eq)
  aio.send(tvoc_feed.key, tvoc)
  time.sleep(0.5)
```

Next, the code reads the door and motion sensor. If the door is open, or if motion is detected, a value of&nbsp; **3** is sent the corresponding feed to change the indicator block's color. For the motion detector, we also keep track of the motion using a boolean,&nbsp;`is_pir_activated`.

```
  # read/send door sensor
  if door_sensor.value:
    print('Door Open!')
    # change indicator block to red
    aio.send(door_feed.key, 3)
  else:
    print('Door Closed.')
    # reset indicator block to green
    aio.send(door_feed.key, 0)
  # read/send motion sensor
  if door_sensor.value:
    if not prev_pir_value:
      print('Motion detected!')
      is_pir_activated = True
      # change indicator block to red
      aio.send(motion_feed.key, 3)
  else:
    if prev_pir_value:
      print('Motion ended.')
      is_pir_activated = False
      # reset indicator block to green
      aio.send(motion_feed.key, 0)
```

Next, we'll take a picture with the picam (using `camera.capture()`), convert it to a base64-encoded string (for use with the image block on an Adafruit IO Dashboard), and send it to Adafruit IO (`aio.send()`)

```
  camera.capture('picam_img.jpg')
  print('snap!')
  with open("picam_img.jpg", "rb") as imageFile:
    str = base64.b64encode(imageFile.read())
    try:
      aio.send('picam', str)
    except:
      print('Sending camera image failed...')
```

Finally, we check if the alarm toggle block on the dashboard has been enabled. If it has been, we take a sample of the current hour (according to the Pi's internal clock. You can set this in **`raspi-config`-\>Internationalization Options-\>Change Time Zone)**. Then, if the hour is later than the ALARM\_HOUR variable and if the PIR has been triggered - we call the `alarm_trigger()` method.

```
  # Alarm System 
  is_alarm = aio.receive(alarm_feed.key)
  if (is_alarm.value == "ON"):
    # sample the current hour
    cur_time = time.localtime()
    cur_hour = time.tm_hour
    if (cur_hour &gt; ALARM_HOUR and is_pir_activated == True):
      alarm_trigger()
```

The alarm toggle on your Adafruit IO dashboard is dependent on if the alarm set in the&nbsp;`ALARM_HOUR`&nbsp;variable. You can also set the delay between executing the loop (`while True`), `LOOP_INTERVAL`

```
# Set to the hour at which to arm the alarm system, 24hr time
ALARM_HOUR = 16

# Set to the interval between loop execution, in seconds
LOOP_INTERVAL = 2
```

To run the script, enter:

`sudo python3 io_home_security.py`

**Note:&nbsp;** You'll need to prefix the script with&nbsp;_sudo&nbsp;_to write to the NeoPixels.

If everything went correctly, you should see the following in your terminal:

```
Adafruit IO Home: Security
CO2eq = 400 ppm 	 TVOC = 0 ppb
Door Closed.
Motion detected!
snap!
sent to AIO!
```

Let's interact with our home from the IO-Home Dashboard! From your Adafruit IO account, select the IO-Home dashboard and push the door open. You should see the&nbsp; **Front Door Indicator** &nbsp;change from green to red.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/755/medium800thumb/sensors_front_alarm.jpg?1535750112)

Switch the toggle from&nbsp; **OFF&nbsp;** to&nbsp; **ON&nbsp;** to arm your house's security system. When you push the front door open (or move past the PIR sensor past the time set by `alarmHour`), the inside lights will blink red.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/753/medium800thumb/sensors_arm_front_alarm.jpg?1535750093)

Tired of the alarm? Want some peace and quiet? Toggle the alarm **OFF**.

![](https://cdn-learn.adafruit.com/assets/assets/000/060/754/medium800thumb/sensors_disarm_system.jpg?1535750101)

If you set up the Raspberry Pi Camera, you'll also be able to see the camera feed from the Image Block element created in&nbsp; **Python Setup**

![](https://cdn-learn.adafruit.com/assets/assets/000/060/902/medium800/sensors_IO_-_IO_Home-PI-DASH.png?1536083464)


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

Out of Stock
[Buy Now](https://www.adafruit.com/product/2821)
[Related Guides to the Product](https://learn.adafruit.com/products/2821/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)
### Magnetic contact switch (door sensor)

[Magnetic contact switch (door sensor)](https://www.adafruit.com/product/375)
This sensor is essentially a reed switch, encased in an ABS plastic shell. Normally the reed is 'open' (no connection between the two wires). The other half is a magnet. When the magnet is less than 13mm (0.5") away, the reed switch closes. They're often used to detect when a...

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

[PIR (motion) sensor](https://www.adafruit.com/product/189)
PIR sensors are used to detect motion from pets/humanoids from about 20 feet away (possibly works on zombies, not guaranteed). This one has an adjustable delay before firing (approx 2-4 seconds), adjustable sensitivity **and** we include a 1 foot (30 cm) cable with a socket so you...

In Stock
[Buy Now](https://www.adafruit.com/product/189)
[Related Guides to the Product](https://learn.adafruit.com/products/189/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...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3709)
[Related Guides to the Product](https://learn.adafruit.com/products/3709/guides)
### Piezo Buzzer

[Piezo Buzzer](https://www.adafruit.com/product/160)
Piezo buzzers are used for making beeps, tones and alerts. This one is petite but loud! Drive it with 3-30V peak-to-peak square wave. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz,...

In Stock
[Buy Now](https://www.adafruit.com/product/160)
[Related Guides to the Product](https://learn.adafruit.com/products/160/guides)
### Raspberry Pi Camera Board v2 - 8 Megapixels

[Raspberry Pi Camera Board v2 - 8 Megapixels](https://www.adafruit.com/product/3099)
Snap, snap! The Camera v2 is the new official camera board released by the Raspberry Pi Foundation!

The **Raspberry Pi Camera Board v2** is a high quality 8 megapixel Sony IMX219 image sensor custom designed add-on board for Raspberry Pi, featuring a fixed focus lens....

In Stock
[Buy Now](https://www.adafruit.com/product/3099)
[Related Guides to the Product](https://learn.adafruit.com/products/3099/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)

## Related Guides

- [PIR Motion Sensor](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor.md)
- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
- [Neopixel Jewel 10 Minute Necklace](https://learn.adafruit.com/10-minute-neopixel-necklace.md)
- [Glowing Fascinator Hat with Gemma M0 and MakeCode](https://learn.adafruit.com/glowing-fascinator-hat-gemma-m0-makecode.md)
- [Wires and Connections](https://learn.adafruit.com/wires-and-connections.md)
- [Lemon Mechanical Keypad](https://learn.adafruit.com/qtpy-lemon-mechanical-keypad-macropad.md)
- [Using Crickit and Adafruit IO together](https://learn.adafruit.com/crickit-and-adafruitio.md)
- [Festive Feather Holiday Lights](https://learn.adafruit.com/festive-feather-holiday-lights.md)
- [MicroPython Basics: Load Files & Run Code](https://learn.adafruit.com/micropython-basics-load-files-and-run-code.md)
- [MicroPython Hardware: I2C Devices](https://learn.adafruit.com/micropython-hardware-i2c-devices.md)
- [Circuit Playground - P is for PCB](https://learn.adafruit.com/circuit-playground-p-is-for-pcb.md)
- [DIY ESP8266 Home Security with Lua and MQTT](https://learn.adafruit.com/diy-esp8266-home-security-with-lua-and-mqtt.md)
- [MicroPython Smart Holiday Lights](https://learn.adafruit.com/micropython-smart-holiday-lights.md)
- [NeoPixel Bike Light](https://learn.adafruit.com/neopixel-headlight.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)
- [CircuitPython 2FA TOTP Authentication Friend](https://learn.adafruit.com/circuitpython-totp-otp-2fa-authy-authenticator-friend.md)
