Smart Birdhouse

by VictorVanHoecke in Outside > Backyard

540 Views, 5 Favorites, 0 Comments

Smart Birdhouse

IMG_20230617_153815518.jpg
IMG_20230611_191124100.jpg

A smart bird house, where the birds automatically get food, a place to nest where the temperature is monitored. Also a camera with a night filter that takes a photo when the motion sensor spots movement. Also a little bit of lighting outside for when it gets too dark.


The project is aimed at bird lovers or anyone who wants to attract and care for birds in their backyard. It can also be beneficial for the birds themselves, as they have a reliable place to build a nest and have food regularly.


You can keep track of the temperature and light level via the web app, if the motion sensor detects movement you can see this via the web app. Here you can also view the photo that the camera takes when there is movement, turn on the LEDs and also turn on the small fan to help control the temperature.

Supplies

For the electrical side of this project you will need the following supplies:


  • Raspberry Pi 4 (I used the 2gb ram version and had some trouble when too much memory was being used)
  • Breadboard power supply (3.3V, 5V) or batteries
  • MCP3008
  • LCD 2x16
  • TMP36
  • Light dependent resistor
  • 2 PIR motion sensors
  • Servo motor
  • 12v DC fan
  • 2 LEDs (I used White LEDs)
  • RPi Noir camera (You could use the normal RPi camera)



For the housing of the project you can use the following materials:


  • (Repurposed) wood
  • Wood glue
  • Materials for cutting the wood to the appropriate sizes
  • A (clear) tube/bottle and cover (the cover connects to the servo, when moved food can dispense from the tube)
  • Water resistant paint or clear coat

Connecting the Electronics

For the connection of the electronics i will be using a breadboard and a breadboard power supply on 5 and 3.3V. To read the values of my Light Dependent Resistor and Temperature sensor i used the MCP3008 to convert the analog signals to digital ones so i could read these signals via the PI. Connecting the MCP to the PI and the sensors to the MCP is shown in the documents.

The LCD will be useful for seeing the IP address on which the site is running so we can connect to it easier. Connecting the LCD screen can be done in some different ways but is chose to use all the wires. In the documents it is shown how you can connect the LCD.

The 2 motion sensors are connected via normal GPIO pins since these sensors only give 0 (no motion) or 1 (motion detected). Now that we have connected the sensors we can now connect the actuators. The LEDs are simple, just connect the positive leg to any GPIO pin and the negative leg to the ground of the breadboard. For the Power button it is the same, connect is to the ground and a GPIO pin.

For the servo motor you connect the positive leg to 5V, the negative to ground and the PWM wire to a GPIO pin, we can than control the servo using Pulse Width Modulation. For the fan i used a transistor since mine did not have a PWM wire, you connect the transistor by connecting the base to a GPIO pin, the emitter to the ground (using a resistor (470 ohm)) of the breadboard and the collector to the positive wire(s) of the fan. Then connect the ground wire of the fan to the ground of the breadboard. We can now control the current the transistor gives the fan and so we control the speed of said fan.

Last but not least connect the PI camera via the dedicated slot on the PI for a camera. I am using the RPI Noir camera which records better when it's dark but you can use any camera that can connect to the PI. If legacy camera support is enabled on the PI be sure to turn this off when using libcamera, it can only detect the camera if legacy support is turned off.

Building the Birdhouse

IMG_20230605_130937072.jpg
IMG_20230605_154333125.jpg
IMG_20230605_154327425.jpg
IMG_20230605_154322594.jpg
IMG_20230605_150734651.jpg

First I measured how big the pieces needed to be and then drew templates on the wood so that i could easily cut out the pieces in the correct size. You can use the tools you like, I used a handsaw, and file to cut and sand the wood and to connect the pieces I used wood glue and nails.

Make sure the components u will use fit inside the designated places, don't forget the wires for the components also need to be guided through the birdhouse. For this I made a small opening on the left panel on the birdhouse itself, under the fan.

Integrating the Electronics

IMG_20230611_191213783.jpg
IMG_20230611_191205711.jpg
IMG_20230611_191154073.jpg
IMG_20230611_191143047.jpg
IMG_20230611_191137983.jpg
IMG_20230611_191124100.jpg
IMG_20230611_191223326.jpg
IMG_20230611_191228081.jpg
IMG_20230611_191231979.jpg
IMG_20230617_153815518.jpg

When connecting the electronics, I made sure to have a compartment where i could house the pi and most of the cables and components. The camera will be mounted at the top and inside the birdhouse itself you will find the motion sensor for the camera and the temperature sensor. The LCD, power button and LDR are found at the front. The servo motor is controlled with the motion sensor next to it and will dispense food. For finishing this project and making it pretty/usable, you can paint the Birdhouse like I did or just cover it using a water-resistant clear coat.

Database for Code

EER model.png
Sensors.png
SensorsMetingen.png
Actuators.png
Actuatorsstatus.png

For this project I created a database in MySQL Workbench. I will be storing my sensors, actuators, sensor measurements and actuator status. Above you see my ERD model of the relationships of the database and examples of what is stored in the database.

Code for Birdhouse and Site

To have this birdhouse functional you don't need a site because you could just run it in automatic mode. For our purposes we will be making a site for the birdhouse which will have several pages: The homepage, sensors page, controls page, history page and camera page.

  • The homepage will give information about the project, who it's meant for and what it does.
  • The sensors page will show us the current value of each sensor and give us the option to change the minimum for the temperature sensor.
  • The controls page will allow us to run it in automatic mode or manual. Using manual will make it so that you can turn on/off the LEDs and fan but also allow you to dispense the food yourself when pressing the button.
  • The history page will show us the history of the LDR and TMP36.
  • The camera page will show us the last taken photo of the camera and allow us to take a photo ourselves.

Then there are some pages not listed in the menu:

  • The edit minimum TMP page, on which you can edit the minimum value which says when the fan should be powered
  • The edit minimum LDR page, on which you can edit the minimum value which says when the LEDs should be powered


Now comes the part where we make the Birdhouse smart, using Visual Studio code which is connected to the pi via SSH we can run a script (app.py). I won't go over all the code, but you can find the eventual code via this link: https://github.com/howest-mct/2022-2023-projectone-victor-van-hoecke.git