SunFounder 37 Modules Sensor Kit V2.0 for Raspberry PI 2: Using relay to activate IR – floodlight and take pictures at night

20151115_ir_photoAnother interesting item in the SunFounder 37 modules sensor kit is the relay module. This can be used to control electrical devices that cannot be connected directly to the Raspberry Pi because of higher voltage or current. In this example the relay will activate a floodlight built with 32 infrared LEDs to take a photo in the dark using the Raspberry Pi NoIr camera.

20151115_ir_cameraThe NoIr camera module for Raspberry Pi does not have an infrared filter like normal cameras. So it can be used for taking photos in the dark together with a floodlight built with infrared leds. This light is not visible and so it’s possible to take photos of animals without disturbing them. The IR floodlight used for this example is built out of 32 infrared LEDs. The voltage needed for this is 9V what is much too high for the Raspberry Pi and also the current needed for this light is more than then Raspberry PI can deliver. So we will use the relay module and a set of own batteries for this.

Again we will use the python bottle framework to build a simple web interface containing a button for taking a picture and the result as an image.

#!/usr/bin/env python
from bottle import route, run, template,static_file
import RPi.GPIO as GPIO
import picamera
import time

# Pin for relay connected to IR floodlight

# init GPIO and switch relay off
def setup():

# cleanup
def destroy():

# the main interface
def index():
        return template('index')

# serving static files (the photo in this case)
def server_static(filename):
    return static_file(filename, root='./static/')

# switches on the floodlight and takes a picutre
def photo():
        camera = picamera.PiCamera()

if __name__ == '__main__':
                run(host="", port=8080)

The photos will be stored in the folder named „static“, so it needs to be created:

mkdir static

We also need a template again, stored in „views“


<title>Dual color LED control</title>
<script src=""></script>
<script type="text/javascript">
function reloadPicture() {
  d = new Date();
  $("#photo").attr("src", "/static/photo.jpg?"+d.getTime());
<h1>Camera control</h1>
<img id="photo" src='static/photo.jpg'/><br/>
<button type="button" onclick="$.get('/photo', function(){reloadPicture()})" name = "photo" value = "photo">take photo</button>

When the button „take photo“ is pressed, the IR floodlight will be switched on, then a photo is taken and stored in static/photo.jpg and the floodlight will be switched off again. After that the picutre is reloaded so that the current picture is shown.

2 Gedanken zu „SunFounder 37 Modules Sensor Kit V2.0 for Raspberry PI 2: Using relay to activate IR – floodlight and take pictures at night

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.