Wednesday, 22 April 2015

Motion triggered security camera using 1Sheeld connected via IFTTT and Dropbox

Recently a buddy of mine from Cytron Malaysia, send me a Arduino Uno variant board CT-Uno (made by Cytron in Malaysia :-) ) and asked me to come up with a project using it. Coincidently, I just bought my 1sheeld few weeks prior, and I thought to myself why not use both to come with something easy yet useful. So I decided to come with this project which uses few components you can find around for cheap !

For this project you will need the followings:

  • An old android smartphone with a camera ( I use my HTC Sensation which is not being use any more because of its cracked screen, but still works perfectly )
  •  1Sheeld and Arduino ( Of Course !)
  •  An Ultrasonic sensor ( can find one easily from ebay, or in  cytron.com.my or you can use any IR sensor )
  • An IFTTT account ( www.ifttt.com )
  • A Dropbox account ( www.dropbox.com )

This project was inspired from this site : https://learn.adafruit.com/wireless-security-camera-arduino-yun/introduction , however it uses the Arduino Yun and a bit more complicated compared to this project since you need to wrap your head around linux.

The following depicts the overview of this project.  An ultrasonic sensor (or IR sensor ) will be used to detect the presence of people walking. Once triggered,  our smartphone camera which is located/hidden somewhere, will capture the image of the person triggering the sensor. This is done via 1sheeld and CT-Uno. Once the image is captured , it is then sent to IFTTT service via email and the image will be stored in a dropbox account. If you have installed dropbox app in your other phone, or on a computer, you will receive  notification on these devices , anywhere in the world.

IFTTT Recipe

In order for this to work, first we need to create a recipe in IFTTT . Open up your IFTTT account and create the following recipe (you will also need to activate your dropbox account in IFTTT) :


Make sure that the email address that is being used matches the email address that is set in your 1Sheeld android app. Next set up the recipe's action to be as the following:



That's it were done with IFTTT settings. What this recipe does is, it will receive any email with image attachment and upload it into our dropbox account.

1Sheeld app settings

Open up your 1Sheeld android app, connect to 1Sheeld and choose Camera shield, Time Shield (for time-stamping purposes) and Email shield. Make sure that you set your email shield to use the email address that were already set in IFTTT account.



Hardware setup

Wiring the ultrasonic sensor to Arduino is straightforward, such as shown here: https://code.google.com/p/arduino-new-ping/.  Figure below shows the overall setup of my hardware. One cool thing of using CT-Uno is that it uses micro-usb instead of mini-usb, so you can directly connect your Arduino to any smartphone battery pack/power bank.

 

Noticed that my android phone is being held by a phone holder.  I can easily mount it on any smooth vertical surfaces with this setup.



Source code

Below is the source code for this project, upload it to your Arduino any you are ready to go.


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Motion Triggered Sscurity Cam via 1sheeld and IFTTT */
/* By Tarmizi Izzuddin */


#include <OneSheeld.h>
#include <NewPing.h>

#define TRIGGER_PIN  12
#define ECHO_PIN     11
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

String mailSubject,hourString,minuteString,time;
boolean isMailSent = false;

int hour,minute,second,day,month,year;

void setup() {
  //begin onesheeld
  OneSheeld.begin(); 
  
  Clock.begin();
}

void loop() {
  
 //get current date and time
  hour = Clock.getHours();
  minute = Clock.getMinutes();
  second = Clock.getSeconds();
  day = Clock.getDay();
  month = Clock.getMonth();
  year = Clock.getYear();
  
  int uS = sonar.ping();
  
 //construct Mail's Subject in the form CamFeed: xx-xx-xxxx xxxxhours
  mailSubject = "CamFeed: ";
  mailSubject += String(day);
  mailSubject += String("-");
  mailSubject += String(month);
  mailSubject += String("-");
  mailSubject += String(year);
  mailSubject += String(" ");
  mailSubject += String(hour);
  mailSubject += String(minute);
  mailSubject += String("hours");
  
  /* Ultrasonic Sensor detect less thn 20 CM */
  
 if(uS / US_ROUNDTRIP_CM < 50){
 
   //Camera.setFlash(ON);
   Camera.setQuality(MID_QUALITY);
   Camera.rearCapture();
   delay(35000); //more than ample time for image to be written on SD card
   
   //create trigger to IFTTT service while sending image as attachment
   Email.attachLastPicture("trigger@recipe.ifttt.com",mailSubject,"none");
  }
}




Friday, 25 October 2013

An useful tool for Arduino - PLX Daq

I just found about this useful tool for Arduino. A guy in Arduino Malaysia community posted on Facebook bout this, so i checked it out. Basically it`s just a data logger software for Parallax Microcontroller, however someone on the net had figured out how to use it on Arduino. Data is straightaway logged  in excel and i have tested on Excel 2010. Below is the picture of my Arduino sending sine wave data to be plotted in Excel. Pretty useful to log data from a sensor.


For more info be sure to check out these website:

  1. https://classic.parallax.com/tabid/393/Default.aspx
  2. http://robottini.altervista.org/arduino-and-real-time-charts-in-excel

Sunday, 13 January 2013

Controlling servo motors using hand movement (Visual Servoing)



Its been a while since my last entry. My attempts to update this blog more often are to no avail due to the laziness disease which infected me since birth , lack of ideas, and loss of courage, which flowed down the sinkhole. I have no idea what im saying ..really.

Anyway, life are as usual. My latest project i did was to trying to control two servo motors based on the gestures  position of my hand. I did this in order to help two of my student with their FYP. By this, i hope that their project scopes is narrowed, and with that they can start concentrating on other part of the project.

This project consists of using MATLAB as the image processing tools and Arduino UNO to control the movement of the servo.I used Adafruit's motor shield, however it is unnecessary as u can connect two servos directly to the Arduino board. For the webcam, i used Logitech C210 webcam to capture image. Hand position was tracked using simple Background Subtraction method which is quite similar to what i did for my diploma project years ago. In this method, a moving image frame is differentiated with the background image so that only the moving object is produced. The image was then converted from grayscale to a binary image and from there a tracking position of the hand is calculated by simply averaging the white pixels position on both the x-axis and y-axis of the image.This may not track the centroid of the moving object but will give a position near to it.From here the position of the hand is translated into pan-tilt rotation angle using a simple linear conversion and command is sent to the Arduino for servo rotation.

Below is the source code for Arduino:


and here is the source code for MATLAB for acquisition and image processing:



and here is the function required by the above`s source code to calculate the centroid position:



Some lessons learned from this project:

  1. USB can't source enough power to run two servos smoothly . I guess my servo used quite a lot of power. Arduino board keeps getting disconnected from the PC's  USB port every time the servos  make a sudden and fast move. I have to move my hands slowly so that Arduino wouldn't get disconnected. Future improvement: use a powered USB hub or external power supply.
  2. Using delay in Arduino to overcome this effect will worsen the tracking performance. Data from MATLAB will get accumulated in Arduino's buffer and will be read later after the delay.
  3. Different lighting conditions can effect the performance of the tracking system. I have to fiddle round the binary threshold to produce the desired tracking performance (smooth tracking, no noise in the binary image). I used 0.7 in a well lit environment and 0.5 in the opposite.
  4. In MATLAB , use fwrite() instead of fprintf() for serial communication. fprintf() only handle ASCII data 0 ~ 127, limiting  the movement of the servo rotation.


Saturday, 5 May 2012

Thesis writing..

1. Still haven't finish writing my thesis. Damn..this is probably the longest writing i've ever done. Hit the 50 page mark but my supervisor said the thesis needs to be somewhere 100 - 200 pages long.. arghh this thing is killing me!

2. The Avengers was a really good movie!. All of the superheroes were awesome, but Captain America was superb-awesomeness! it kind of reminds me of the game captain America i used to play during my childhood years..and Hulk.. yeaa..that green monster is in-fact indestructible..

3. okay thats it for now, gotta continue wif da thesis writing..

Thursday, 26 April 2012

Damn i need to start writing again..

1) This is the second time i started writing on this blog after a long break. Guess i have to write more often starting from now..present career requires me to do so.

2)Although its already been a month, but i'm married ..Syukur Alhamdullilah!.Married life couldn't be any better.Time to update the current status on this blog.

3)I still have the same old interest...Arduino, Electronics, Robotics , Control Bla..bla...but... i now have a deep interest in automotive technologies, especially automotive electronics.. need to find a project which uses arduino for automotive purposes...

thats it for now... need to write my damn thesis . Dunno when im gonna finish it...

Thursday, 20 January 2011

The Iphone controlled Arduino bot!

Actually, its been a while since i completed this project .Lately, I've been busy with work and study leave matters so i dont have time to upload this project on the net. Anyway, my Arduino robot is powered using Arduino Duemilanove ( i know it is a bit outdated), a wishield from Asynclabs and two toshiba's motorcontroller (TA7291p). Controlling the robot is done using my Iphone with TouchOSC app.




Communication between the iphone and the robot is done via a wifi router and using OSC ( Open Sound Controller ) protocol. All the tedious work of programming OSC protocol is simplified using the OSC library for wishield. Below is the video for this project:



Friday, 14 January 2011

Its been a while!!

Well its been a while now since my last post. Im gonna get this blog up and runnin again!