Introduction: Raspberry With Cam in Birdhouse

About: http://sebelectronique.canalblog.com

First of all, I'm French and I apologize for my bad English.

Before to start, I drew a plan for my birdhouse in order to build it.

First, you can see my youtube video here:

https://youtu.be/S3MB3YABeRU

After, I decided to add a camera to see the bird life and perhaps the baby birds.

I will describe how to add a raspberry and a camera in my birdhouse.

EDIT 1st October:

Good news, coming soon the temperature and humidity on the web page. Stay connected !

EDIT 5th October:

I have first visit one chickadee => https://youtu.be/stxVw7Cs5os

EDIT 12th October:
Temperature and humidity are available, go to step 8

Step 1: The Listing

You need:

  • 1 x Raspberry pi A+ (28$ / 25€)
  • 1 x camera board Pi NoIR (32,5$ / 29€)
  • 1 x microSD card class 10 (for me 64GB) (27,5$ / 25€)
  • 1 x dongle Wifi 802.11n 150Mbps (9,3$ / 8,3€)
  • 1 x DC-DC Buck Converter Step Down Module Power Supply (ebay 1,7$ / 1,5€)
  • 1 x Temperature and humidity sensor DHT22 + 1 resistor 4,7 K ohms (ebay ~5$ / 4,4€)
  • 4 x led IRs (ebay) + 4 resistors 160 ohms (but value depend of current) (from my stock or ebay ~2$ / 1,8€)
  • 4 x led whites (ebay) + 4 resistors 100 ohms (but value depend of current) (from my stock or ebay ~2$ / 1,8€)
  • 2 x transistor NPN (2N2222) + 2 resistors 1K ohms (from my stock or ebay ~1$ / 0,8€)
  • 1 x prototype pcb board (ebay) (from my stock or ebay ~1$ / 0,8€)
  • a soldering iron and solder (from me)

Total : ~ 113$ / 100€

with all these components, you are ready !

Step 2: Install and Configure Your Raspberry

Now, you should to install and configure your Raspberry.

You can visited my blog to start with a raspberry : here

or to find tuto on google ! (google is your fiend).

I made a special microSD card with Raspbian OS and Wifi already configurated for my home Wifi system.

For the RPI A+, you must to connect it:

  • download the Raspbian image on raspberrypi.org
  • put the Raspbian image on your microSD card
  • insert the microSD card into the RPI
  • connect your RPI at your TV by the HDMI cable
  • connect your one dongle for USB keyboard + mouse at your RPI
  • connect the 5V power supply at your RPI
  • The RPI start ! OMG !
  • configure with "raspi-config" : extend filesystem, enable camera, change password...
  • configure the Wifi
  • shutdown your RPI
  • disconnect your TV and dongle keyboard
  • connect Wifi dongle
  • power up your RPI
  • log in to your RPI by SSH through your wifi network

Your RPI is ready !

Step 3: Build a Mount for the Camera, the Leds and the Sensor

Take the prototype board and cut it in order to place the camera, the leds with resistors and the sensor.

For example of cabling, you look the fritzing picture.

For the white leds : I cut and smoothed the top of led (white) in order to have a wider angle and more diffusing light.

The plastic screws allow me to make an adjustement of the vision of the camera.

Step 4: Build a Board for the Supply Converter and the Control of Leds

Take the prototype board and cut it at the dimensions of RPI A+.

Make a hole in the board to let to spend the ribbon cable of camera.

Put the supply converter (12V->5V), the transistors NPN and the resistors. (cf fritzing picture on previous step).

Soldered on the RPI, the wires and connect it on the output of converter. On the input, there is 12V supply from my garage.

Why i chose a converter 12V-->5V ? Because, I do not have a power supply 5V.

Step 5: To Place the Camera, Light and Sensor Board

Take a house bird (my production) and to place the board on the top of the house bird.

Next, to place the RPI in the right direction of the ribbon cable of the camera to avoid to bend the ribbon cable.

And make a ribbon to connect the leds and sensor between the camera board and the control board

Step 6: Closed the Electronic Boards

Make a protection for the RPI.

Next, make a joint (such as the bathroom) all around the protection with a brush.

Make a hole in order to pass the wire from the power supply.

I used the Deutsch DTM connector (waterproof) between the house bird and my garage.

Step 7: Install in the Tree

Installed the house bird in the tree or other best place.

Connect the power supply and go to next step to write the code which control the leds.

Step 8: Install the Tools

Now, we will :

  • update the RPI
  • activate the camera (already done in step 2)
  • install Wiring Pi

Connect to RPI in SSH terminal (by default login:pi / password: raspberry):

Update the RPI:

sudo apt-get update
sudo apt-get upgrade => y
sudo apt-get dist-upgrade => y

Install Wiring Pi:source link

sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
cd wiringPi
./build

Next, you can test if the installation is ok :

gpio -v => check the version
gpio readall => check the gpio table

Note : the pin 2, 3 and 4 of BCM correspond to 8, 9 and 7 of WiringPi table.

For test, you can to control of leds by these below commands: described here

gpio mode 8 out (to set the pin 8 in out mode)
gpio write 8 0 (to set the pin 8 at OFF)
gpio write 8 1 (to set the pin 8 at ON)

Init the GPIO at each starting of RPI :

  • Create a script to init the GPIO:
 cd /etc/init.d/
 sudo nano init_gpio.sh
**********************************************************************
#! /bin/bash
#Initialisation GPIO pin in out mode and set to 0
#GPIO 8 in out mode and set to 0 (OFF): for white leds (or like you want)
/usr/local/bin/gpio mode 8 out
/usr/local/bin/gpio write 8 0
#GPIO 9 in out mode and set to 1 (ON): for IR leds (or like you want)
/usr/local/bin/gpio mode 9 out
/usr/local/bin/gpio write 9 1
***********************************************************************

Ctrl + X => Y (yes) => Enter

  • Add a line in rc.local file (starting file):
sudo nano /etc/rc.local
***********************************************************************
 .....
 # By default this script does nothing.
 #Init GPIO 
 sudo bash /etc/init.d/init_gpio.sh
 ....
 exit 0
************************************************************************

Now, after each rebooting of RPI, the leds will be initialised according to your choice.

To have the temperature and humidity : EDIT 12th October

cd wiringPi/examples
sudo nano rht03.c
************************************************************************
=> add library
#include <time.h>

=> change the pin
#define RHT03_PIN       7

=> declare variable
int mesure=0;
struct tm*t ;
time_t tim ;
FILE *fichier_log = NULL ;

=> start : modify the loop in do{}while
do
{

=> change delay
delay(500);
...

=> init time variable
tim = time(NULL) ;
t = localtime(&tim) ;
...

=> write date in log.csv file
fichier_log = fopen("/var/www/log.csv","w"); //open log file
fprintf(fichier_log,"%02d/%02d/%04d;%02d:%02d;%2.1f;%2.1f\n",t->tm_mday,t->tm_mon+1,t->tm_year+1900,t->tm_hour,t->tm_min,temp/10.0,rh/10.0); //write date;time;temperature;humidity
fclose(fichier_log); //close log file
printf ("Temp:%5.1f;Hum:%5.1f\n", temp / 10.0, rh / 10.0) ;
mesure=1; //measure ok
...
=> end : modify the loop in do{}while
}while(mesure==0); //go out loop
...
*************************************************************************

Ctrl + x => Y (yes) => Enter

make rht03

$[CC] rht03.c
$[link]

sudo ./rht03

$Temp:  16.4, RH:  63.6

Create a script:

sudo nano temp_hum.sh

#!/bin/sh
/home/pi/wiringPi/examples/rht03

Change permission :

sudo chmod 775 temp.hum.sh

Add a script in crontab to execute the script all 15 minutes (as you want) :

sudo crontab -e

end add line :

with temp_hum.log file for degug
0,15,30,45 * * * * /home/pi/temp_hum.sh >> /home/pi/temp_hum.log 2>&1
or
without temp_hum.log file
0,15,30,45 * * * * /home/pi/temp_hum.sh
Next...

Step 9: Install RPI Cam Web Interface

Now, we will install RPI Cam Web Interface :

It's the easiest solution and it's ready to use :following the basic installation !

We can explore the different options that proposed by the interface :

- record video

- record image

- timelapse record

- motion dectection record

-....

Step 10: To Integrate the Control of Led

Finally, I will created my own php page with embeded live preview and led control and temperature and humidity ! Waouh !

The example to embed the live-preview is here.

Go to www path :

cd /var/www

Rename index.php to parameters.php :

sudo mv index.php parameters.php

Create a php page :

sudo nano index.php

=>copy/paste the example from the RPI cam website to putty windows

Ctrl + x => Y (yes) => Enter

Create a js file :

sudo nano script_min.js

=>copy/paste the examples from the RPI cam website to putty windows

Ctrl + x => Y (yes) => Enter

Test on web browser http://your_RPI_IP/index.php => OMG !

Now, we will integrated 2 boutons to control the leds :

sudo nano index.php

=> to see the attach files : index.php and scrip_min.js

For the moment, i don't have yet succeed to integrate the temperature and humidity on the web page.

Good news, now I succeed to integrate the temperature and humidity on the php page.

Step 11: Final

After 10 steps, I can connect on my own web page with :

  • RPI cam live preview
  • ON/OFF buttons to control led white
  • ON/OFF buttons to control led IR
  • Time of last measure
  • Temperature
  • Humidity
  • one button to access the parameter

All step in video : https://youtu.be/dum1xwGsyec

Now I will to wait the birds....first visite => https://youtu.be/stxVw7Cs5os

If you have to like my "instructable", please

VOTE FOR ME => Awesome I won a second prize !

THANK YOU