Hey, guys. Due to our tight schedule, we weren't able to post any Raspberry Pi video in our channel. So, sorry for that. :(
Finally, we are back with a project based on Raspberry Pi and IoT. We have done quite a few projects based on IoT. If you haven't seen any of then do watch those videos whose links are given below. Now, coming back to this tutorial. We will be making a kind of surveillance camera with some pretty useful features.
The camera set up will be attached to a pan-tilt arrangement that will be controlled by two metal gear servos. Now those servos will be controlled wirelessly over the internet. So IoT or Internet Of Things concept will be playing a part here.
Similar to our previous home security video, this project will be based on an IoT platform named Cayenne. The video feed will be transmitted over internet or Local network to your display, whether it is a laptop, desktop, or your smartphone. So now you can monitor the condition of your house from anywhere in the world using the internet.If you people are guessing that the video feed will be accessible by cayenne and can go to the wrong hands, that's not gonna happen as we will be making a webcam server and will configure it to broadcast the video in a predefined port that will be known to you only.
Before we start, here are some mentions you might be interested in. We have made many tutorials about the basics of a Raspberry Pi project like how to install OS, how to start your first project in raspberry pi etc. Do watch those videos if you are not aware of these things beforehand.
- How to Install Raspbian OS in Raspberry Pi - https://www.instructables.com/id/HOW-TO-INSTALL-R...
- How to Use Android Devices as Raspberry Pi Screen - https://goo.gl/GMCDhz
- How to Use Linux Devices as Raspberry Pi Monitors - https://goo.gl/8mQiEc
- How to Use Windows Machine as Raspberry Pi Monitors - https://goo.gl/wPBKHb
- How to Use IOS Devices as a Screen for Raspberry Pi - https://goo.gl/qzjQvU
- Your First Raspberry Pi Project (LED Blinking) - https://goo.gl/3kueaP
- IoTBased Home Security Project ( Setup Cayenne ) - https://goo.gl/J2bEsU
I will try to make this project as elaborate as possible, but if you don't want to read all these stuff, then look at the video that is given below. All the steps are shown with some footage and diagram. Hope you will like it. If you like our tutorial whether it's the Instructables or our video, do follow and subscribe to our channel.
Channel Link - www.youtube.com/c/being_engineers1
Website - www.being-engineers.com
Video link -
I think you have got a clear idea about what we will be doing. So let's start. :)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Gather the Components
- Raspberry Pi 3
- USB camera
- Servo brackets
- 12V DC supply
- Buck converter
- Servo driver
The following are the hardware:
- Drill machine
- Drill bits
- Nuts, bolts, screws, range, screw driver
- Wire stripper
- Both side tape
- Pen knife
Jumpers, electrical wires, crocodile clips, Ethernet cable (why Ethernet and why not WiFi is explained in the video)!
Step 2: Install Motion and Create Webcam Server
In order to understand this step, you need to watch this video tutorial where we have shown you in detail how to use motion package to create a USB Webcam Server for LAN using Raspberry Pi.
Step 3: Configure Your Raspberry Pi With Cayenne
In order to understand this, watch this tutorial.
Instructable link: IoT based Home Security
Step 4: Make the Hardware Structure
Now after the primary things have been done, it's time to build the servo Pan-Tilt arrangement. These are the different servo brackets that I used. You can also find the images attached.
- 2 X Large U Beam Servo Bracket
- 2 X Long U Servo Bracket
- 2 X Multipurpose Servo Mounts
Follow the pictures carefully and build the structure as robust as possible. As the whole arrangement will be moving in 2 dimensions with some sudden movement, if the structure is not stable the video feed will be very jerky. Tighten all the screws and add something heavy at the base to prevent it from tipping over.
Step 5: Attach the Camera and Adjust the Orientation
Cut a piece of both side tape and paste it at the camera. Then peel off the other protector and mount the camera to the upper servo bracket. Here you can use some nut,bolts and screws to make the arrangement permanent. But for demonstration purpose it will work fine for normal use. After you have attached the camera adjust the camera head to horizontal position so that we can get clear view of the room at the time of tilting.
Step 6: Make the Electrical Connections
Here in the following link, I have provided a diagram where the interconnection among the components is shown in clear.
Link - https://goo.gl/bp7GcP
Now you have to understand one thing. I am using a 12V 10A DC power supply. Then I am using a Buck converter to pull down the 12V DC to 5.5V DC because the servos I am using in this project are the TowerPro MG950 which can work in between 5-6V DC. These servos can also draw more than 1A current in stall case. So you can pretty well guess that you don't need 12V 10A supply.
If you can arrange a 6V 2A supply, then it will be best because in that case you don't need to use a Buck Converter. I will be using 12V because I don't have ready-made 6V 2A DC supply.
Follow the circuit diagram and connect the components correctly. Be sure about the polarity as this is a high current project a little mistake can damage your products event though all modern electronics components has a reverse voltage protection.
I will be using Ethernet not Wi-Fi. But if you use Wi-Fi then don't need to connect the RJ-45 Cable to the Ethernet jack.
Keep in mind that PCA9685 Servo driver runs on 3.3V.
PCA9685 ----> Raspberry Pi
SDA -- Pin 3, SCL -- Pin 5, VCC -- Pin 1 ( 3.3 V ), GND -- Pin 6 ( GND )
Step 7: Modify Cayenne Dashboard
In this step, the Cayenne dashboard has to be modified to meet our need. Follow these steps carefully -
- Sign in to Cayenne with your email id and password. Raspberry Pi should be turned on and connected to the internet.
- Click on Add New, and then click on Device/Widgets.
- Go to extension and select PWM.
- Select PCA9685.
- From the side menu select Device as Raspberry Pi and slave as ' I2C Slave Address 0x40'. Add extension. New extension tab will appear on the dashboard.
- Again go to Add New, Device/Widgets, then search for Servo. Click on Servo Motor.
- Now for 1st servo i.e. Pan Servo, put Widget name as Pan Servo, device as Raspberry Pi, connectivity as PCA9685, channel as channel 0, widget as a slider. Now the min and max position will depend on your choice. This is the angle in which the camera will move horizontally. So for me -60 degree to 60 degrees is fine. A total of 120 Degree field of view is good enough. Max field of view will be -90 to 90 degree.
- Do same for Tilt servo. Change the widget name, the channel should be 1, min and max will be -30 to 30 ( will give 60-degree vertical view). Don't put such angle like -60 to 60, or more. As the brackets will be there it will obstruct the servo movement causing damage to the servo.
That's all you have to do in cayenne. Now you can see two tiles named pan servo or tilt servo in the dashboard of Raspberry Pi. These sliders will be used to control the servos.
Step 8: Start Your Webcam Server
All set now. Open putty. Log in into your pi using correct user name and password. Type in the command "sudo motion" and press enter. This will start your webcam server.
Now go to any browser and type in the address of Raspberry Pi with the port in this format - x.x.x.x:y, y is the port. By default, it is 8081.
You will be able to see your webcam feed on your desktop, tablet, laptop etc. But the device should be in the same network with Raspberry Pi. So till now, you can view your webcam feed only on LAN. But if you do some port forwarding and make a virtual server then you can view your webcam feed over the internet also. Port forwarding is very easy but the method differs from brand to brand. So just google it and you can do it on your own.
Step 9: It's Done!!
That's it, guys. We are done. Now as an application, you can monitor your home through the internet when you are outside using the Cayenne app easily. Not only that, sitting from your room, you can have an eye on the other sections i.e. rooms of your house as well.
So that's it for today guys. I hope you have enjoyed this tutorial. We would really appreciate if you can understand the time and work we are putting behind making all these tutorials. So kindly SUBSCRIBE to our YouTube channel. It really motivates us to make more cool videos for all of you.
We reached 1000 subs on March 5 after a year since our first video and 2000 on July 5. So quickly go to this link and be a part of our family. :)
Subscribe now: Being Engineers
See you later. Peace.
Participated in the
Home Improvement Contest 2017