# IoT Bird Feeder with Camera

## Overview

https://youtu.be/LhUypbEh9XU

![](https://cdn-learn.adafruit.com/assets/assets/000/128/797/medium800/adafruit_products_hero-fake-bird.jpg?1710865456)

## WiFi Bird Feeder Camera

This project captures images of birds that you can view on an Adafruit IO feed or dashboard.

We designed and 3D printed a bird feeder to house the Adafruit MEMENTO, a large battery, and a PIR sensor.&nbsp; It’s got a tray for holding birdseed and a perch so birds can visit and have a meal.

![adafruit_products_bird-feeding.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/793/medium640/adafruit_products_bird-feeding.jpg?1710864912)

## Adafruit IO Camera Feed

When the PIR sensor detects motion, the MEMENTO takes a photo and sends a JPEG to Adafruit IO.

On the Adafruit IO website, you can view the image within seconds of it being captured. Using Adafruit IO’s Actions feature, you can receive email notifications whenever a new photo is uploaded.

![adafruit_products_hero-phone.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/796/medium640/adafruit_products_hero-phone.jpg?1710865254)

## Capture Wild Life

The bird feeder isn’t exclusive to just birds - squirrels and chipmunks are fans too and they seem to be a bit more photogenic!

Our build features a large battery that has about eight hours of run time and can be recharged over the MEMENTO USB port.

![adafruit_products_squirrel-3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/794/medium640/adafruit_products_squirrel-3.jpg?1710865030)

![adafruit_products_new-bird-D.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/795/medium640/adafruit_products_new-bird-D.jpg?1710865067)

## Parts
### MEMENTO - Python Programmable DIY Camera - Bare Board

[MEMENTO - Python Programmable DIY Camera - Bare Board](https://www.adafruit.com/product/5420)
Make memories, or just a cool camera-based project,&nbsp;with **Adafruit's MEMENTO Camera Board**. It's a development board with everything you need to create programmable camera and vision projects: with a camera module, TFT preview screen, buttons, SD card slot and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5420)
[Related Guides to the Product](https://learn.adafruit.com/products/5420/guides)
![Video of a DIY camera on a lazy susan.](https://cdn-shop.adafruit.com/product-videos/640x480/5420-05.jpg)

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

### STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm

[STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm](https://www.adafruit.com/product/3894)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" female header sockets on the end. We're carrying these to match up with our Hallowing, for extending and connecting sensors or LEDs - and the wires are even color coded!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3894)
[Related Guides to the Product](https://learn.adafruit.com/products/3894/guides)
![Angled shot of STEMMA JST PH 3-Pin to Female Header Cable - 200mm.](https://cdn-shop.adafruit.com/640x480/3894-03.jpg)

### Adafruit IO+ Subscription Pass – One Year

[Adafruit IO+ Subscription Pass – One Year](https://www.adafruit.com/product/3792)
The all-in-one Internet of Things service from Adafruit you know and love is now _even better_ with IO+. The 'plus' stands for MORE STUFF! More feeds, dashboards, storage, speed. Power up your [Adafruit IO](https://io.adafruit.com/) with the $99 pass for 1 year of the...

In Stock
[Buy Now](https://www.adafruit.com/product/3792)
[Related Guides to the Product](https://learn.adafruit.com/products/3792/guides)
![Text image that reads "IO+"](https://cdn-shop.adafruit.com/640x480/3792-01.jpg)

### Part: USB Type A to Type C Cable
quantity: 1
USB Type A to Type C Cable - approx 1 meter / 3 ft long
[USB Type A to Type C Cable](https://www.adafruit.com/product/4474)

### Part: 2200mAh Battery
quantity: 1
Lithium Ion Cylindrical Battery - 3.7v 2200mAh
[2200mAh Battery](https://www.adafruit.com/product/1781)

The following parts are useful, but optional for completion of this project.

### Part: Heat Shrink Pack
quantity: 1
Multi-Colored Heat Shrink Pack - 3/32" + 1/8" + 3/16" Diameters
[Heat Shrink Pack](https://www.adafruit.com/product/1649)

## Hardware

The following hardware is necessary for the case assembly.

- 2x M2.5 x 6mm long machine screws
- 2x M3 x 10mm long FF standoffs
- 10x M3 x 6mm long machine screws
- 4x M3 x 10mm long machine screws
- 6x M3 hex nuts

# IoT Bird Feeder with Camera

## Wiring

## Connect PIR Sensor to JST PH 3-Pin Plug

In the wiring diagram below, the PIR sensor is connected to one of the MEMENTO's JST PH 3-Pin sockets. However, it's not as simple as the diagram makes it out to be.&nbsp; The PIR sensor comes with a 30cm cable ending in a socket.

There are a few options for connecting this cable to the MEMENTO's JST-PH socket:

### Alligator Clips

This option requires _no soldering_. Simply follow the wiring diagram and connect the JST PH cable's alligator clips to the wires from the PIR sensor's cable.

### JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable

[JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable](https://www.adafruit.com/product/4030)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with grippy mini alligator clips. We're carrying these to match up with any of our boards or breakouts with 3-pin 'STEMMA' connectors on them such as the&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4030)
[Related Guides to the Product](https://learn.adafruit.com/products/4030/guides)
![Angled shot of JST PH 3-pin Plug to Color Coded Alligator Clips Cable.](https://cdn-shop.adafruit.com/640x480/4030-04.jpg)

### DIY Wiring Harness

This option requires soldering. However, it is permanent and elegant compared to the alligator clips.

You'll need the following parts for this step:

### JST PH 2mm 3-pin Plug-Plug Cable - 100mm long

[JST PH 2mm 3-pin Plug-Plug Cable - 100mm long](https://www.adafruit.com/product/4336)
This cable is a little over 100mm / 4" long&nbsp;and fitted with JST-PH 3-pin connectors on either end.&nbsp;

We dig the solid and compact nature of these connectors and the latch that keeps the cable from coming apart easily. We're carrying these to <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4336)
[Related Guides to the Product](https://learn.adafruit.com/products/4336/guides)
![Angled shot of JST PH 3-pin Plug-Plug Cable - 100mm long.](https://cdn-shop.adafruit.com/640x480/4336-01.jpg)

### Part: Heat Shrink
quantity: 1
Multi-Colored Heat Shrink Pack - 3/32" + 1/8" + 3/16" Diameters
[Heat Shrink](https://www.adafruit.com/product/1649)

Using wire cutters, cut a JST PH 2mm 3-pin Plug-Plug cable in half. Then, add heat shrink tubing over the cable.

![adafruit_products_cut_cable_add_hs-ezgif.com-video-to-gif-converter.gif](https://cdn-learn.adafruit.com/assets/assets/000/127/059/medium640thumb/adafruit_products_cut_cable_add_hs-ezgif.com-video-to-gif-converter.jpg?1705351357)

Solder each wire of the JST PH cable to the corresponding wire on the PIR sensor's harness.&nbsp;

![adafruit_products_solder_hs-ezgif.com-video-to-gif-converter.gif](https://cdn-learn.adafruit.com/assets/assets/000/127/060/medium640thumb/adafruit_products_solder_hs-ezgif.com-video-to-gif-converter.jpg?1705351967)

Then, slide the heat shrink tubing over the soldering joint and apply heat.

![adafruit_products_hs_tube-ezgif.com-video-to-gif-converter.gif](https://cdn-learn.adafruit.com/assets/assets/000/127/061/medium640thumb/adafruit_products_hs_tube-ezgif.com-video-to-gif-converter.jpg?1705351992)

After soldering and applying heat shrink to all three cables, your PIR sensor is ready to be plugged into the MEMENTO.

![adafruit_products_IMG_7682.jpg](https://cdn-learn.adafruit.com/assets/assets/000/127/058/medium640/adafruit_products_IMG_7682.jpg?1705350156)

## Wiring Diagram
![](https://cdn-learn.adafruit.com/assets/assets/000/126/872/medium800/adafruit_products_memento-bird-camera_bb.png?1704397786)

After connecting the PIR sensor to a JST cable, connect the cable to the MEMENTO.

The wiring for this project is as follows:

- **PIR Sensor VCC** to **Memento A0 VIN**
- **PIR Sensor GND** to **Memento A0 GND**
- **PIR Sensor Output** to **Memento A0 Signal**

# IoT Bird Feeder with Camera

## CAD Files

## 3D Printed Parts

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material using PLA filament. Original design source may be downloaded using the links below.

![adafruit_products_3d-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/755/medium640/adafruit_products_3d-parts.jpg?1710772831)

[Download STLs.zip](https://cdn-learn.adafruit.com/assets/assets/000/128/758/original/STLs.zip?1710773149)
[CAD_Source.zip](https://cdn-learn.adafruit.com/assets/assets/000/128/759/original/CAD_Source.zip?1710773661)
## Build Volume

The parts require a 3D printer with a minimum build volume.

- 182mm (X) x 128mm (Y) x 92mm (Z)

![adafruit_products_CURA-slice.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/756/medium640/adafruit_products_CURA-slice.jpg?1710773078)

## CAD Assembly

The PIR sensor and battery is secured to brackets using machine screws. The brackets are secured to the MEMENTO using machine screws. The MEMENTO is secured to the front half of the enclosure using machine screws. The back half of the enclosure is secured to the house plate using screws, hex nuts and standoffs. The roof and feeding tray are secured to the house plate using machine screws and hex nuts. The front and back enclosure parts snap fit together.

![adafruit_products_CAD.gif](https://cdn-learn.adafruit.com/assets/assets/000/128/769/medium640thumb/adafruit_products_CAD.jpg?1710778148)

## Design Source Files

The project assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, STL and more.

Electronic components like Adafruit's boards, displays, connectors and more can be downloaded from the&nbsp;[Adafruit CAD parts GitHub Repo](https://github.com/adafruit/Adafruit_CAD_Parts/).

![adafruit_products_5420_MEMENTO.gif](https://cdn-learn.adafruit.com/assets/assets/000/128/757/medium640thumb/adafruit_products_5420_MEMENTO.jpg?1710773117)

# IoT Bird Feeder with Camera

## Get Started with Adafruit IO

Adafruit IO is integrated with your&nbsp;[adafruit.com account](https://accounts.adafruit.com/)&nbsp;so you don't need to create yet another online account! You need an Adafruit account to use Adafruit IO because we want to make sure the data you upload is available to only you (unless you decide to publish your data).

## I have an Adafruit.com Account already

**If you already have an Adafruit account, then you already have access to Adafruit IO**. It doesn't matter how you signed up, your account will make all three available.

To access Adafruit IO, simply visit [https://io.adafruit.com](https://io.adafruit.com) to start streaming, logging, and interacting with your data.

## Create an Adafruit Account (for Adafruit IO)

An Adafruit account makes Adafruit content and services available to you in one place. Your account provides access to the [Adafruit shop](https://www.adafruit.com/), the [Adafruit Learning System](https://learn.adafruit.com/), and [Adafruit IO](https://io.adafruit.com/). This means only one account, one username, and one password are necessary to engage with the content and services that Adafruit offers.

If you do not have an Adafruit account, signing up for a new Adafruit account only takes a couple of steps.

Begin by visiting [https://accounts.adafruit.com](https://accounts.adafruit.com).

**Click the Sign Up button** under the "Need An Adafruit Account?" title, below the Sign In section.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/220/medium800/adafruit_io_Create_account_sign_in_up_page.png?1697479894)

This will take you to the **Sign Up** page.

**Fill in the requested information,** and **click the Create Account button.**

![](https://cdn-learn.adafruit.com/assets/assets/000/125/219/medium800/adafruit_io_Create_Account_info_entered.png?1697479894)

This takes you to your Adafruit Account home page. From here, you can access all the features of your account.

You can also access the Adafruit content and services right from this page. Along the top of the page, you'll see a series of links beginning with "Shop". To access any of these, simply click the link.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/217/medium800/adafruit_io_Create_account_home_page.png?1697479894)

For example, **to begin working with Adafruit IO, click the IO link** to the right of the rest of the links. This is the same for the other links as well.

That's all there is to creating a new Adafruit account, and navigating to Adafruit IO.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/218/medium800/adafruit_io_Create_Account_io_homepage.png?1697479770)

# IoT Bird Feeder with Camera

## Create Adafruit IO Feed

Warning: 

Feeds are the core of the Adafruit IO system. A feed holds&nbsp; **data&nbsp;** and&nbsp; **meta-data** &nbsp;that you have sent to Adafruit IO.

- **Data** &nbsp;is the information you want Adafruit IO to store. For example, image data from the MEMENTO's camera.
- **Meta-data** &nbsp;includes settings for the data such as privacy settings and data retention options.

Before using the IoT Birdfeeder, a new Adafruit IO Feed must be created to store the&nbsp; MEMENTO camera's image. Then, the feed's history must be disabled to allow larger data points to be sent to Adafruit IO, such as a large amount of data to represent an image.&nbsp;

To create a feed, navigate to your [Adafruit IO Feeds](https://io.adafruit.com/feeds) page. Then, click _New Feed_.

![](https://cdn-learn.adafruit.com/assets/assets/000/127/219/medium800/adafruit_products_new-feed.png?1706206187)

Name the feed&nbsp;_birdfeeder_ and click Create.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/773/medium800/adafruit_products_IO_-_Feeds.png?1710785135)

The feeds list now lists a _birdfeeder_ feed. Click this feed.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/774/medium800/adafruit_products_birdfeeder.png?1710785148)

## Disable Feed History

On the camera feed's sidebar, click _Feed History_.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/775/medium800/adafruit_products_feedhist1.png?1710785208)

Set _History_ to _OFF_ and click Save. This will change the feed's data storage from 1KB to 100KB, large enough to store image data.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/776/medium800/adafruit_products_fh2.png?1710785232)

# IoT Bird Feeder with Camera

## Create Your settings.toml File

CircuitPython works with WiFi-capable boards to enable you to make projects that have network connectivity. This means working with various passwords and API keys. As of [CircuitPython 8](https://circuitpython.org/downloads), there is support for a **settings.toml** file. This is a file that is stored on your **CIRCUITPY** drive, that contains all of your secret network information, such as your SSID, SSID password and any API keys for IoT services. It is designed to separate your sensitive information from your **code.py** file so you are able to share your code without sharing your credentials.

CircuitPython previously used a **secrets.py** file for this purpose. The **settings.toml** file is quite similar.

Warning: Your **settings.toml** file should be stored in the main directory of your **CIRCUITPY** drive. It should not be in a folder.

## CircuitPython **settings.toml** File

This section will provide a couple of examples of what your **settings.toml** file should look like, specifically for CircuitPython WiFi projects in general.

The most minimal **settings.toml** file must contain your WiFi SSID and password, as that is the minimum required to connect to WiFi. Copy this example, paste it into your **settings.toml** , and update:

- `your_wifi_ssid`
- `your_wifi_password`

```auto
CIRCUITPY_WIFI_SSID = "your_wifi_ssid"
CIRCUITPY_WIFI_PASSWORD = "your_wifi_password"
```

Many CircuitPython network-connected projects on the Adafruit Learn System involve using Adafruit IO. For these projects, you must _also_ include your Adafruit IO username and key. Copy the following example, paste it into your settings.toml file, and update:

- `your_wifi_ssid`
- `your_wifi_password`
- `your_aio_username`
- `your_aio_key`

```auto
CIRCUITPY_WIFI_SSID = "your_wifi_ssid"
CIRCUITPY_WIFI_PASSWORD = "your_wifi_password"
ADAFRUIT_AIO_USERNAME = "your_aio_username"
ADAFRUIT_AIO_KEY = "your_aio_key"
```

Some projects use different variable names for the entries in the **settings.toml** file. For example, a project might use `ADAFRUIT_AIO_ID` in the place of `ADAFRUIT_AIO_USERNAME`. **If you run into connectivity issues, one of the first things to check is that the names in the settings.toml file match the names in the code.**

Warning: Not every project uses the same variable name for each entry in the **settings.toml** file! Always verify it matches the code.

## **settings.toml** File Tips
Here is an example **settings.toml** file.

```auto
# Comments are supported
CIRCUITPY_WIFI_SSID = "guest wifi"
CIRCUITPY_WIFI_PASSWORD = "guessable"
CIRCUITPY_WEB_API_PORT = 80
CIRCUITPY_WEB_API_PASSWORD = "passw0rd"
test_variable = "this is a test"
thumbs_up = "\U0001f44d"
```

In a **settings.toml** file, it's important to keep these factors in mind:

- Strings are wrapped in double quotes; ex: `"your-string-here"`
- Integers are _ **not** _ quoted and may be written in decimal with optional sign (`+1`, `-1`, `1000`) or hexadecimal (`0xabcd`).
  - Floats (decimal numbers), octal (`0o567`) and binary (`0b11011`) are not supported.

- Use `\u` escapes for weird characters, `\x` and `\ooo` escapes are not available in **.toml** files
  - Example: `\U0001f44d` for 👍 (thumbs up emoji) and `\u20ac` for € (EUR sign)

- Unicode emoji, and non-ASCII characters, stand for themselves as long as you're careful to save in "UTF-8 without BOM" format

&nbsp;

&nbsp;

When your&nbsp; **settings.toml&nbsp;** file is ready, you can save it in your text editor with the **.toml** &nbsp;extension.

![adafruit_products_dotToml.jpg](https://cdn-learn.adafruit.com/assets/assets/000/117/071/medium640/adafruit_products_dotToml.jpg?1671034293)

## Accessing Your **settings.toml** Information in **code.py**
In your **code.py** file, you'll need to `import` the `os` library to access the **settings.toml** file. Your settings are accessed with the `os.getenv()` function. You'll pass your settings entry to the function to import it into the **code.py** file.

```python
import os

print(os.getenv("test_variable"))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/117/072/medium800/adafruit_products_tomlOutput.jpg?1671034496)

In the upcoming CircuitPython WiFi examples, you'll see how the **settings.toml&nbsp;** file is used for connecting to your SSID and accessing your API keys.

# IoT Bird Feeder with Camera

## Code

![](https://cdn-learn.adafruit.com/assets/assets/000/128/798/medium800/adafruit_products_hero-code.jpg?1710865624)

Once you've finished setting up your MEMENTO camera with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download to your computer as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MEMENTO/IoT_Bird_Feeder/code.py

After downloading the Project Bundle, plug your MEMENTO into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the MEMENTO's&nbsp; **CIRCUITPY** &nbsp;drive.

- **lib** &nbsp;folder
- **code.py**

Your MEMENTO&nbsp; **CIRCUITPY** &nbsp;drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py** &nbsp;file.

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/MEMENTO_IoT_Bird_Feeder.png )

## Code Walkthrough
The following code snippet connects the MEMENTO camera to a WiFi network.

```auto
### WiFi ###
# Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys
# with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.

# Set your Adafruit IO Username, Key and Port in settings.toml
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = os.getenv("ADAFRUIT_AIO_USERNAME")
aio_key = os.getenv("ADAFRUIT_AIO_KEY")

print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}")
wifi.radio.connect(
    os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
)
print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}!")
```

The `io` object is created to interface with the Adafruit IO HTTP API.

```auto
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(os.getenv("ADAFRUIT_AIO_USERNAME"), os.getenv("ADAFRUIT_AIO_KEY"), requests)
```

We'll attempt to get the _birdfeeder_ feed from Adafruit IO. If it does not exist on the account, the Adafruit IO CircuitPython library will automatically create one.

```auto
# Manage Adafruit IO Feed
try:
    # Get the 'birdfeeder' feed from Adafruit IO
    feed_camera = io.get_feed("birdfeeder")
except AdafruitIO_RequestError:
    # If no 'birdfeeder' feed exists, create one
    feed_camera = io.create_new_feed("birdfeeder")
```

The camera is initialized and its display backlight is disabled.

```auto
# initialize camera
pycam = adafruit_pycamera.PyCamera()
# turn off the display backlight
pycam.display.brightness = 0.0
```

The PIR sensor is initialized as a digital input on the MEMENTO's A0 port.

```auto
# initialize PIR sensor
pir = digitalio.DigitalInOut(board.A0)
pir.direction = digitalio.Direction.INPUT
```

The loop reads the value of the PIR sensor. If the value of the PIR sensor has changed, movement is detected and the MEMENTO takes a photo. The photo is saved into a JPEG (bytes) object.

```auto
print("Waiting for movement...")
old_pir_value = pir.value
while True:
  pir_value = pir.value
  # if we detect movement, take a photo
  if pir_value:
    if not old_pir_value:
      print("Movement detected, taking picture!")
      # force camera autofocus
      pycam.autofocus()
      # take a picture and save it into a jpeg bytes object
      jpeg = pycam.capture_into_jpeg()
```

If the camera successfully captures a photo, the `jpeg` object will be full of _bytes._ The code checks if the jpeg capture was successful and then calls a function to send the jpeg data to Adafruit IO.

If the image is not captured, an error will be printed to the REPL.

```auto
# if the camera successfully captured a jpeg, send it to IO
      if jpeg is not None:
        send_jpeg_to_io()
      else:
        print("ERROR: JPEG capture failed!")
```

The following function, `send_jpeg_to_io()`, is called by the snippet above. In this function, the jpeg data gets encoded from bytes into a base 64 object to reduce its size. Then, the encoded data is sent to the Adafruit IO feed we specified earlier.

```auto
def send_jpeg_to_io():
  """ Sends a JPEG image to Adafruit IO. """
  # before we send the image to IO, it needs to be encoded into base64
  encoded_data = binascii.b2a_base64(jpeg).strip()
  # then, send the encoded_data to Adafruit IO camera feed
  print("Sending image to IO...")
  io.send_data(feed_camera["key"], encoded_data)
  print("Sent image to IO!")
```

Finally, if the new value detected by the PIR sensor was the previous value, we'll print to the REPL that movement has stopped being detected. The `old_pir_value` is updated each loop iteration.

```auto
else:
    if old_pir_value:
      print("Movement ended")
# update old_pir_value
old_pir_value = pir_value
```

# IoT Bird Feeder with Camera

## Assembly

## Wired PIR Sensor

The PIR sensor cable is shorted to be 3.5 inches (8.9mm) long to better fit inside the 3D printed enclosure. (See **Wiring** page in this guide for more info.)

![adafruit_products_PIR-JST-wired.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/722/medium640/adafruit_products_PIR-JST-wired.jpg?1710529011)

## PIR Sensor Bracket

Use the following hardware to secure the PIR senosor to the 3D printed bracket.

- 2x M2.5 x 6mm long machine screws

![adafruit_products_PIR-bracket-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/723/medium640/adafruit_products_PIR-bracket-screws.jpg?1710529051)

![adafruit_products_PIR-bracket-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/724/medium640/adafruit_products_PIR-bracket-installing.jpg?1710529129)

## Secure PIR Sensor

Place the PIR sensor PCB over the 3D printed bracket using the photo to reference the correct placement and orientation.

Install and fasten the machine screws to secure the PIR sensor to the 3D printed bracket.

![adafruit_products_PIR-backet-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/725/medium640/adafruit_products_PIR-backet-install.jpg?1710529193)

![adafruit_products_PIR-bracket-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/726/medium640/adafruit_products_PIR-bracket-secured.jpg?1710529200)

## Secure PIR Sensor Bracket

Use two M3 x 6mm long screws to secure to the 3D printed PIR sensor bracket to the back side of the MEMENTO.

The 3D printed bracket for the PIR sensor is placed below the two lower standoffs on the MEMENTO PCB.

Install and fasten the M3 machine screws to secure the PIR sensor bracket to the MEMENTO.

![adafruit_products_PIR-mem-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/727/medium640/adafruit_products_PIR-mem-screws.jpg?1710529225)

![adafruit_products_PIR-mem-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/728/medium640/adafruit_products_PIR-mem-install.jpg?1710529342)

## Connect PIR Sensor&nbsp;

Plug the 3-pin JST connector from the PIR sensor to the JST connector on the side of the MEMENTO labeled **A0**.&nbsp;

Take a moment to ensure the bracket is tightly secured and the PIR sensor is connected to the correct port on the MEMENTO.

![adafruit_products_PIR-mem-plug.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/729/medium640/adafruit_products_PIR-mem-plug.jpg?1710529369)

![adafruit_products_PIR-mem-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/730/medium640/adafruit_products_PIR-mem-secured.jpg?1710529378)

## Battery Bracket

Use the following hardware to secure the battery bracket to the MEMENTO.

- 2x M3 x 6mm long machine screws

![adafruit_products_bat-bracket-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/731/medium640/adafruit_products_bat-bracket-screws.jpg?1710529506)

## Secure Battery Bracket

Place the 3D printed battery bracket over the two upper standoffs on the back side of the MEMENTO.

Use the M3 machine screws to secure the 3D printed battery bracket to the MEMENTO.

Plug in the cable from the 2200mAh battery to the battery port on the front side of the MEMENTO.

![adafruit_products_bat-bracket-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/732/medium640/adafruit_products_bat-bracket-installing.jpg?1710529525)

![adafruit_products_bat-mem-plug.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/733/medium640/adafruit_products_bat-mem-plug.jpg?1710529535)

## Install Battery

Press or slide the 2200mAh battery into the clip on the 3D printed battery bracket.

Take a moment to ensure the battery and bracket are installed correctly.

![adafruit_products_bat-mem-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/734/medium640/adafruit_products_bat-mem-secured.jpg?1710529546)

## Front Case

Use the following hardware to secure the MEMENTO to the front half of the 3D printed enclosure.

- 4x M3 x 6mm long machine screws&nbsp;

Fit the MEMENTO into the 3D printed enclosure with the front side facing down.

![adafruit_products_Fcase-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/735/medium640/adafruit_products_Fcase-screws.jpg?1710529585)

![adafruit_products_Fcase-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/738/medium640/adafruit_products_Fcase-installing.jpg?1710529634)

## Secure Memento

Install and fasten the M3 machine screws to secure the MEMENTO to the front half of the 3D printed enclosure.

The lens and PIR sensor should fit through the corresponding cutouts.

Ensure the print-in-place slide switch is positioned to actuate the built-in ON/OFF slide switch onboard the MEMENTO.

![adafruit_products_Fcase-securing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/737/medium640/adafruit_products_Fcase-securing.jpg?1710529620)

![adafruit_products_Fcase-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/739/medium640/adafruit_products_Fcase-secured.jpg?1710529653)

## House and Tray

Use the following hardware to secure the 3D printed house plate to the feeder tray.

- 2x M3 x 10mm long machine screws
- 2x M3 hex nuts

![adafruit_products_house-tray-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/740/medium640/adafruit_products_house-tray-screws.jpg?1710529872)

## Secure Tray to House

Slide the feeder tray into the bottom of the house plate and line up the mounting holes.

Insert and fasten the M3 screws through the side of the 3D printed house plate.

Use the M3 hex nuts to secure the house plate to the feeder tray.

![adafruit_products_house-tray-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/741/medium640/adafruit_products_house-tray-installing.jpg?1710529892)

![adafruit_products_house-tray-nuts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/742/medium640/adafruit_products_house-tray-nuts.jpg?1710529907)

## House & Roof

Use the following hardware to secure the 3D printed house plate to the 3D printed roof.

- 2x M3 x 10mm long screws
- 2x M3 hex nuts

![adafruit_products_house-roof-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/743/medium640/adafruit_products_house-roof-screws.jpg?1710529922)

## Secure Roof to House Plate

Place the 3D printed roof over the top of the 3D printed house plate and line up the mounting holes.&nbsp;

Insert and fasten the M3 screws through the side of the 3D printed roof.

Use the M3 hex nuts to secure the 3D printed roof to the house plate.

![adafruit_products_house-roof-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/744/medium640/adafruit_products_house-roof-installing.jpg?1710529948)

![adafruit_products_house-roof-nuts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/745/medium640/adafruit_products_house-roof-nuts.jpg?1710529956)

## Back Case

Use the following hardware to secure the back half of the 3D printed enclosure.

- 6x M3 x 6mm long machine screws
- 2x M3 hex nuts
- 2x M3 x 10mm long FF standoffs

![adafruit_products_house-bcase-screws.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/746/medium640/adafruit_products_house-bcase-screws.jpg?1710529978)

## Install Standoffs

Secure the two M3 standoffs using two M3 machine screws to the two upper mounting holes on the 3D printed house plate.

![adafruit_products_house-standoff.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/747/medium640/adafruit_products_house-standoff.jpg?1710530005)

## Secure Back Case

Place the back half of the 3D printed enclosure over the standoffs with the side indentation oriented towards the right side.

Install and fasten two M3 screws to secure the back half of the enclosure to the standoffs on the 3D printed house plate.

![adafruit_products_house-bcase-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/748/medium640/adafruit_products_house-bcase-installing.jpg?1710530039)

![adafruit_products_house-bcase-back-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/749/medium640/adafruit_products_house-bcase-back-installing.jpg?1710530056)

## Secured Case

Install and fasten two M3 screws to the remaining mounting holes.

Use two M3 hex nuts to secure the back half of the 3D printed enclosure to the 3D printed house plate.

Take a moment to ensure the parts are correctly oriented.

![adafruit_products_house-bcase-nuts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/750/medium640/adafruit_products_house-bcase-nuts.jpg?1710530073)

![adafruit_products_house-bcase-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/753/medium640/adafruit_products_house-bcase-secured.jpg?1710530133)

## Snap Fit Case Closed

Orient the front half of the 3D printed enclosure to match the back half.

Line up the edges and firmly press the two halves to snap fit them together.

Congratulations on building your IoT Bird Feeder!

![adafruit_products_fcase-bcase-installing.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/751/medium640/adafruit_products_fcase-bcase-installing.jpg?1710530105)

![adafruit_products_fcase-bcase-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/752/medium640/adafruit_products_fcase-bcase-secured.jpg?1710530123)

# IoT Bird Feeder with Camera

## Usage

![](https://cdn-learn.adafruit.com/assets/assets/000/128/800/medium800/adafruit_products_new-bird-F.jpg?1710877029)

## Using Outdoors

The 3D printed enclosure is not fully weather proof and should only be used outdoors during the day under dry conditions.&nbsp;

Add your preferred bird food to the 3D printed tray.

Birds can be very cautious when eating. Allow a few days for birds to be conformable with your location before expecting them to feed.

![adafruit_products_hero-outdoors.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/799/medium640/adafruit_products_hero-outdoors.jpg?1710870031)

## Viewing the latest photo on Adafruit IO

The MEMENTO takes a photo when a bird (or any other object) is detected by the feeder's motion sensor. This photo is then uploaded to Adafruit IO.

To view the image from the camera, navigate to your Adafruit IO Feeds page and click on the _birdhouse_&nbsp;feed.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/771/medium800/adafruit_products_birdfeeder.png?1710784991)

The image captured by the camera should appear on the feed as a data-point and an image preview will be visible.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/772/medium800/adafruit_products_bird.png?1710785017)

If the PIR sensor is not detecting motion in front of it, or if it's too sensitive, follow the instructions below to adjust the sensor's settings.

## Adjusting PIR Sensor Sensitivity&nbsp;
The PIR sensor sold by Adafruit has two potentiometers on the back, with one labeled SENSITIVITY. You can adjust the sensitivity if your PIR is too sensitive or not sensitive enough.

Turning the potentiometer clockwise makes it more sensitive, and turning it counter-clockwise makes it less sensitive.&nbsp;

![adafruit_products_pir_sensitivity.png](https://cdn-learn.adafruit.com/assets/assets/000/126/952/medium640/adafruit_products_pir_sensitivity.png?1704748573)

## Adjusting PIR Sensor Pulse Time and Timeout Length

There are two 'timeouts' associated with the PIR sensor. One is the " **Tx**" timeout: how long the LED is lit after it detects movement - this is easy to adjust on Adafruit PIR sensors because there's a potentiometer labeled TIME.

- For information about the math to adjust pulse time and timeout length, [visit this Adafruit Learning System Guide \>\>\>](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/testing-a-pir#changing-pulse-time-and-timeout-length-2927247)

### PIR Motion Sensor - Testing a PIR

[PIR Motion Sensor](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor)
[Testing a PIR](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/testing-a-pir)

## Featured Products

### MEMENTO - Python Programmable DIY Camera - Bare Board

[MEMENTO - Python Programmable DIY Camera - Bare Board](https://www.adafruit.com/product/5420)
Make memories, or just a cool camera-based project,&nbsp;with **Adafruit's MEMENTO Camera Board**. It's a development board with everything you need to create programmable camera and vision projects: with a camera module, TFT preview screen, buttons, SD card slot and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/5420)
[Related Guides to the Product](https://learn.adafruit.com/products/5420/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)
### Lithium Ion Cylindrical Battery - 3.7v 2200mAh

[Lithium Ion Cylindrical Battery - 3.7v 2200mAh](https://www.adafruit.com/product/1781)
Need a big battery for your project? This lithium-ion battery contains a 2200mAh and a protection circuit that provides over-voltage, under-voltage, and over-current protection. Yet, it is slim and easy to fit into many project cases.  
  
This cell can provide 2 **C** of...

In Stock
[Buy Now](https://www.adafruit.com/product/1781)
[Related Guides to the Product](https://learn.adafruit.com/products/1781/guides)
### Adafruit IO+ Subscription Pass – One Year

[Adafruit IO+ Subscription Pass – One Year](https://www.adafruit.com/product/3792)
The all-in-one Internet of Things service from Adafruit you know and love is now _even better_ with IO+. The 'plus' stands for MORE STUFF! More feeds, dashboards, storage, speed. Power up your [Adafruit IO](https://io.adafruit.com/) with the $99 pass for 1 year of the...

In Stock
[Buy Now](https://www.adafruit.com/product/3792)
[Related Guides to the Product](https://learn.adafruit.com/products/3792/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### Multi-Colored Heat Shrink Pack - 3/32" + 1/8" + 3/16" Diameters

[Multi-Colored Heat Shrink Pack - 3/32" + 1/8" + 3/16" Diameters](https://www.adafruit.com/product/1649)
Heat shrink is the duct tape of electronics which I guess makes this heat shrink the colorful and exciting duct tape they sell&nbsp;at craft stores. &nbsp;This heat shrink comes in six different colors - red, blue, green, yellow, white and the traditional black.

Each pack contains ten...

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

## Related Guides

- [PIR Motion Sensor](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor.md)
- [Adafruit MEMENTO Camera Board](https://learn.adafruit.com/adafruit-memento-camera-board.md)
- [How to use Blockly for Actions on Adafruit IO](https://learn.adafruit.com/how-to-use-blockly-for-actions-on-adafruit-io.md)
- [Set up Web Workflow on the Adafruit MEMENTO](https://learn.adafruit.com/set-up-web-workflow-on-the-adafruit-memento.md)
- [No-Code DS18B20 Temperature Sensor with WipperSnapper](https://learn.adafruit.com/using-ds18b20-temperature-sensor-with-wippersnapper.md)
- [Pico W PiCowBell Case](https://learn.adafruit.com/pico-w-picowbell-case.md)
- [Welcome to Adafruit IO](https://learn.adafruit.com/welcome-to-adafruit-io.md)
- [Memento Photo Capture with itsaSNAP](https://learn.adafruit.com/memento-photo-capture-with-itsasnap.md)
- [No-Code Pool Party Notifier](https://learn.adafruit.com/pool-party-notification-device.md)
- [Integrating Color Sensors with itsaSNAP and HomeKit](https://learn.adafruit.com/integrating-color-sensors-with-itsasnap-and-homekit.md)
- [BLE Cat Thermal Printer with MEMENTO](https://learn.adafruit.com/ble-cat-thermal-printer-with-memento.md)
- [ePaper Camera](https://learn.adafruit.com/epaper-camera.md)
- [Adafruit IO Basics: Analog Output](https://learn.adafruit.com/adafruit-io-basics-analog-output.md)
- [No-Code IKEA Vindriktning Air Quality Sensor Hack with Adafruit IO](https://learn.adafruit.com/no-code-ikea-vindriktning-hack-with-qt-py-esp32-s3-and-adafruit-io.md)
- [Adafruit IO Basics: Dashboards](https://learn.adafruit.com/adafruit-io-basics-dashboards.md)
- [MEMENTO Wireless Remote with TouchOSC](https://learn.adafruit.com/memento-wireless-remote.md)
- [Adafruit IO Basics: Feeds](https://learn.adafruit.com/adafruit-io-basics-feeds.md)
