Monitor Camera and Relay Control Over Internet

Introduction: Monitor Camera and Relay Control Over Internet

Many of us have smartphones, iPads or netbooks that we take with us and it would be great to check in on the place, in a coffee shop or while traveling. Now we use the raspberry pi 2 for monitoring camera and control relay over internet. Everything is explain for the 11 step.

In addition to basic relay control you have many configuration options. For example, you can configure the units to close the contacts for a preset time and then open again, or toggle the relays whenever a voltage is applied or you can even write a custom script to close the relay five times in a certain sequence.

Step 1: Basic Equiment

1. Raspberry Pi 2 + Case

2. Micro Usb Charger 5V

3. Mouse and Keyboard

4. Cable and Screwdriver

5. Relay Module

6. 2 pcs Usb Camera

7. Micro SD card 8Gb

8. LCD monitor, Driver, HDMI cable and Power Supply 12v

Step 2: SD Card Setup With Windows XP

  1. Download your preferred Operating System (OS) you wish to run from the Raspberry Pi website:
  2. You will need to use a program such as Win32DiskImager (search from google). This program will write the image structure required for the Raspberry Pi to boot from the SD card.

  3. Open Win32DiskImager, Load image file “Raspbian” OS to your SD card device, then click write

  4. Eject SD card, insert to your Raspberry Pi 2

Step 3: Resize Partitions

  1. Insert SD card to your Raspberry Pi 2, power up and wait until display the raspberry pi software configuration tool (raspi-config)
  2. Choose number 1 ( Expand Filesystem ), press enter, then choose finish, raspberry will reboot

Step 4: First Boot

  1. Login your raspberry pi 2
    • Raspberrypi login : pi
    • Password : raspberry
  2. Write “startx” and press enter

Step 5: Remove Border on Your Display Lcd ( If Not Full Screen )

  1. Find and open LXTerminal write “sudo nano /boot/config.txt”
  2. Uncomment ( Remove # ) disable_overscan=1

  3. Uncomment ( Remove # ) the following to adjust overscan, change to zero

  4. Press Ctrl-X, write “Y” and press enter to change the config.txt

  5. Write “sudo reboot”

  6. Wait and the border will remove

Step 6: Solving Error “ . . . “

  1. Open LXTerminal, type lxsession-edit to open Desktop Session Setting
  2. Uncheck LXPolKit
  3. Reboot your Raspberry Pi 2

Step 7: Install Motion on Raspberry Pi 2

  1. Open LXTerminal and write

    • sudo apt-get update

    • sudo apt-get upgrade

    • sudo apt-get install motion

  2. Enable motion daemon

    • sudo nano /etc/default/motion

      • change line to start_motion_daemon=yes

      • Ctrl-X, save modified buffer Y, and press enter

  3. Motion configuration

    • sudo nano /etc/motion/motion.conf

      • daemon = OFF to ON

      • webcam_localhost = ON to OFF

  4. Check usb camera

    • Plug your 2 usb camera to your raspberry pi 2

    • Check on LXTerminal

      • ls /dev/vid*

  5. Start / Stop Motion

    • sudo service motion start

    • sudo service motion stop

  6. Test your usb camera

    • Make new folder “camera” on home/pi/camera

    • Go to LXTerminal write “cd camera”

      • write “sudo nano cam1.conf”

        • videodevice /dev/video0

        • webcam_port 8081

      • write “sudo nano cam2.conf”

        • videodevice /dev/video1
        • webcam_port 8082

    • add following line to /etc/motion/motion.conf

      • thread /home/pi/camera/cam1.conf

      • thread /home/pi/camera/cam2.conf

    • Check your Dynamic IP using LXTerminal

Step 8: Download and Install Last Release Webiopi

  1. Download file webiopi on and adapt x.y.z with the version you download. Put the file to /home/pi
  2. Open LXTerminal and write the step
    • $tar xvzf WebIOPi-x.y.z.tar.gz
    • $cd WebIOPi-x.y.z
  3. For only Raspberry pi 2, must change the following step
    • Python/native/cpuinfo.c change 'BCM2708' to 'BCM2709'
    • Python/native/gpio.c '#define BCM2708_PERI_BASE 0x20000000' to '#define BCM2708_PERI_BASE 0x3f000000'
  4. Then install webiopi
    • $sudo ./
    • Setup may take a moment
  5. Run your webiopi
    • $sudo webiopi -d-c /etc/webiopi/config
    • You are done, and ready to enjoy WebIOPi! But the server and GPIO state will be lost when you'll stop the script (CTRL-C) or close the terminal
  6. Start/Stop WebIOPi
    • $sudo /etc/init.d/webiopi start
    • $sudo /etc/init.d/webiopi stop
  7. Access WebIOPi over local nettwork
    • If your Raspberry Pi is connected to your network, you can open a browser to http://raspberrypi:8000/ with any device of your network. Replace raspberrypi by its IP
    • Default user is 'webiopi' and password is 'raspberry'
  8. Begin the script
    • Create a folder somewhere on your P, for instance /home/pi/myproject. This is main folder
    • Create another python folder in the previously created. I will store Python script file here
    • Create another html folder next to python. We will store HTML and other resources here
  9. Configuration
    • Edit /etc/webiopi/config
      • Script
        • myproject =/home/pi/myproject/python/
      • Http
        • doc-root=/home/pi/myproject/html
    • Remember to start your WebIOPi
      • $sudo /etc/init.d/webiopi start

Step 9: Python Script, Html File and Connection Raspberry Pi and Relay Module

  1. Inside file

  2. inside html file

  3. Connection Raspberry Pi and relay module
    • Raspberry pi PIN 02 (DC 5v) to relay module (VCC)
    • Raspberry pi PIN 06 (Ground) to relay module (GND)
    • Raspberry pi PIN 03 (GPIO 02) to relay module (IN1)
    • Raspberry pi PIN 05 (GPIO 03) to relay module (IN2)

Step 10: Test Connection Over

There are two camera online at, two relay that can be energize by press the button. User name is 'webiopi' password 'raspberry'

Step 11: Access Over Internet the Two Camera and Relay Module

  1. Register on the Weaved developper portal
  2. Download Weaved for Raspberry pi
  3. Install Weaved
    • chmod +x weaved-nixinstaller_1.2.13.bin
    • ./weaved-nixinstaller_1.2.13.bin
    • Choose Yes for raspberry pi 2 arm7
    • Protocol Selection Menu, choose number 3 (Webiopi on default port 8000)
    • Enter register email on weaved portal
    • Provide device name, I use 'raspberry pi 2'
  4. Test your setup
    • Login to
    • Device 'Raspberry pi 2' will appear
    • Klik on the device 'Raspberry pi 2'
  5. Open your browser on your Raspberry or your Phone, Camera and relay online over internet
Raspberry Pi Contest

Participated in the
Raspberry Pi Contest

Be the First to Share


    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge



    Question 1 year ago

    Hey Man It's very good project. And i did it all ready
    But can you tell me somthing
    Wen it's starting, relay turn on automatic
    But i needit relay be off after start
    Default position relay, i need off
    I try to do this, i change
    # Setup GPIOs
    GPIO.setFunction(L1, GPIO.OUT)
    GPIO.setFunction(L2, GPIO.OUT)

    I try to use GPIO.setFunction(L1, GPIO.LOW)
    But if i do this i can't turn on/off it's all time off (((
    Help me please


    3 years ago

    I can't connect to 8082 port.
    What is the reason?