[vc_row][vc_column width=”1/1″][vc_column_text]Original: http://www.oneassetplace.com/pages/motion_camera_mega
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts and Supplies Needed” tab_id=”1389320781-1-28″][vc_column_text]You will need the following:
- Arduino Mega 2560 R3 (SF: DEV-11061)
- Arduino Ethernet Shield (SF: DEV-09026)
- LinkSprite JPEG Color Camera TTL Interface – Infrared (SF: SEN-11610)
- Zilog e-PIR Zmotion Detection module (SF: SEN-09587)
- Micro SD card (8Gb or other size)
- (Recommended) Some sort of enclosure
- (Misc.) Jumper wire, breadboard kit for testing
- We are assuming you have an Ethernet network already setup and ready to go
All of the steps outlined in this tutorial were on a Mac. Linux steps should be almost identical. Not sure about Windows.[/vc_column_text][/vc_tab][vc_tab title=”Useful Libraries and Tutorials” tab_id=”1389320781-2-35″][vc_column_text]
Useful Libraries and Tutorials
Although not the exact camera we are using, the AdaFruit TTL Serial Camera tutorial is a good source of information on hooking up cameras to an Arduino. ThisBildr tutorial walks you through using an Arduino as a web client.[/vc_column_text][/vc_tab][vc_tab title=”Before You Begin” tab_id=”1389322522234-2-0″][vc_column_text]
At this point we are assuming that you’ve gotten the basic Arduino “Hello World” (blinking LED) circuit and software working. If not, please view those tutorials and return when you’ve gotten that far. We are also assuming that you know how to monitor the serial output of your Arduino. If you haven’t reached that level yet, please go to the excellent Getting Started With Arduino page.
We are also assuming you have some basic soldering and breadboarding skills. Other than that, this tutorial will teach you everything you need to know![/vc_column_text][/vc_tab][vc_tab title=”Build Process” tab_id=”1389322572766-3-9″][vc_column_text]
Step: Prepare the Ethernet Shield
- Mount the Ethernet Shield onto the Arduino
- Plug an Ethernet (LAN) cable into the sheild (other end into your router or switch)
- Plug the USB cable from the Arduino into your PC.
At this point we are ready to see if we can communicate with the Ethernet shield:
- Inside of your Arduino IDE, choose File | Examples | Ethernet | DnsWebClient
- Run the program and then open your serial monitor. After a few seconds you should see a ton of text – the results of hitting Google from your Arduino.
If you see a response containing a ton of Google HTML response text, congratulations! Your Arduino is talking to the Internet!
Troubleshooting at this point:
If you are unable to reach Google, check your Internet connection. You should see link lights blinking on your Arduino’s Ethernet shield.
Step: Building the circuit
This circuit is a bit complex, but don’t despair! The entire schematic is posted at this Fritzing site. For your convenience, we have reproduced the breadboard diagram here:
Note that we are using the motion detector in “Hardware Interface Mode”. If your motion detection needs are more complex, you could use the Motion detector in Serial mode, but you’ll have to spend more time communicating with the motion detector.
- Build the circuit as outlined (there is also a text description of the circuit in the source code)
- Triple check all of your connections before powering on! Most importantly please realize that this circuit makes use of both the 5 volt (camera) and 3.3 volt (motion detector) feeds from the Arduino – don’t get them mixed up.
Step: Setting Up a Camera Sensor in One Asset Place
Now we need to get this board configured for our purposes, which is to wake up every few seconds, see if motion is detected, take a picture, save the picture to the SD card, then send the picture to One Asset Place so you can see it on your dashboard.
To do this, we need to get the Arduino to send an HTTP “POST”. Note that this is different from all of the examples in the manual (and most online tutorials) which are sending an HTTP “GET”. Since we are developing this to interface with One Asset Place, we want a new “sensor reading” to be placed into our dashboard.
Luckly, One Asset Place will give you the exact information you need to send to it for your particular sensor! So, lets setup your first sensor (you can skip these steps if you have already done this):
- On the left-hand navigation bar in One Asset Place, select the Locations bar then choose Locations
- One Asset Place will create a default location for you. Feel free to edit this so that the name is more appealing to you. You may also want to update the time zone… If you don’t all One Asset Place date/time stamps you see will be in Universal Coordinated Time (UTC or “zulu” for the pilots out there)
- On the left-hand navigation bar in One Asset Place, select the Sensors bar, then choose Private Sensors
- One Asset Place will create a default sensor for you. Feel free to edit the name of the sensor so that it makes sense for your application
- Finally, we setup the Sensor Input. The camera sensor is a one-input sensor:
- On the left-hand navigation bar, select Sensors, then choose Sensor Inputs
- Click “Add Sensor Input” to bring up the screen where you setup a new Sensor Input
- Here you tell One Asset Place the type of sensor input. Name the Sensor Input whatever you like, but be sure to choose “Motion Camera” as the Sensor Input Type
Step: Saving Memory by using the Arduino’s EPROM
The program for the camera is pretty large – too large to fit in the memory available on an Arduino Uno (hence the need for the MEGA in this project). In order to allow us to have liberal use of debugging strings, we opted to move many of the HTTP post strings into the Arduino’s EEPROM. This gives us a one-time need to write the values to the EEPROM. We’ve written the program for you that will do this, you’ll just have to update it with some values that are unique to your sensor:
- Download the OAP_Setup_EEPROM.ino program from github. This should be saved in a \OAP_Setup_EEPROM subdirectory of your Arduino project
- There are two lines in the program that you’ll have to change. They are in the section that starts at line 35:
char* stringsToWrite[] = { "POST /readings HTTP/1.1", "Content-Type: multipart/form-data; boundary=", "----------------------------283499ce49c6", "Host: www.oneassetplace.com", "Content-Length: ", "Content-Disposition: form-data; name=\"", "reading[sensor_id]\"", "sensor[key]\"", "517c070d8xxxxxxxxxxxxxxxxxxxe801b424d27", "reading[raw]\"", "{\"5\":\"image\"}", "reading[image]\"; filename=\"", "Content-Type: image/jpeg", "Connection: close" };
- The line after sensor[key] needs to be replaced with your One Asset Place sensor key. You can find your sensor key (and copy it) from One Asset Place by choosing Sensors | My Private Sensors
- In the line that currently reads \”5\” : \”image\”, you need to replace the “5” with your Sensor Input Seq (sequence). That will probably be 1 for you… Whatever you used when you setup your Sensor Input.
- Run the program on your Arduino and it will “burn” these values to your EEPROM. it will then output all of them to the screen if you are running your serial monitor.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.