element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Send email with photo on movement - The smart entrance - Internet of Holiday Lights RoadTest
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: matfur92
  • Date Created: 23 Jan 2015 1:36 AM Date Created
  • Views 561 views
  • Likes 0 likes
  • Comments 2 comments
  • RoadTest
  • enchanted_rc
  • holiday
  • iot_holidaylights
  • smart_entrance
  • christmas
  • iot
  • arduino
Related
Recommended

Send email with photo on movement - The smart entrance - Internet of Holiday Lights RoadTest

matfur92
matfur92
23 Jan 2015

(prev. post is Get a working webcam on Arduino Yun - The smart entrance - Internet of Holiday Lights RoadTest read this to have a working webcam on Arduino Yun)


In this post I will explain how to start a python script or possibly any other program / bash by our Arduino sketch Yun.
In particular, I am going to explain the procedure to have a motion detector (using a HC RS04 ultrasound sensor) that allows to send a photo by email in case it detects a change of distance of at least 2cm in two successive measurements in 'arc of about 60ms.

 

So let's see what are the steps necessary to accomplish this purpose.

 

Get a working python with support to HTTPS/SSL doing in SSH :

opkg update                      #updates the available packages list
opkg install distribute          #it contains the easy_install command line tool
opkg install python-openssl      #adds ssl support to python

 

I have positioned the sendemail.py (download it from attached file) in the /www/cgi-bin with FileZilla. [sendemail.py taken from http://dev.mikamai.com/post/76945627390/you-cant-touch-this-an-evil-arduino-based]

The sendmail.py was edited with my email ad login parameters of gmail.

IMPORTANT : go to https://www.google.com/settings/security/lesssecureapps and enable this option to have a working script!!

 

This is the script that I have loaded in my Arduino Yun that send an email when the distance have a delta > 2cm.

#include <Bridge.h>
#include <Wire.h>

//HC RS04 ultrasound sensor
int triggerPort = 4;
int echoPort = 2;

Process p;

void setup() {
    Wire.begin();
    Bridge.begin();
    Serial.begin(115200);

    //ultrasound sensor
    pinMode( triggerPort, OUTPUT );
    pinMode( echoPort, INPUT );

}

void commandGetImage(int n){
  p.runShellCommand("fswebcam --device /dev/video0 --resolution 640x480 --jpeg 95 --save /www/"+String(n)+".jpg --palette MJPEG --no-banner"); //takes the picture
  while(p.running()); //wait till the process ends
}

float getDistance(){
  digitalWrite( triggerPort, LOW );

  //send one impulse of 10microsec on trigger
  digitalWrite( triggerPort, HIGH );
  delayMicroseconds( 10 );
  digitalWrite( triggerPort, LOW );

  float duration = pulseIn( echoPort, HIGH );
  float centimeter = 0.034 * duration / 2;

  if( duration > 58000 ){
    duration=-1;
    centimeter=-1;
  }

  if (centimeter==0){
    Serial.println("ERROR - 0 cm - get again the distance");
    delay(10);
    centimeter=getDistance();
  }

  return centimeter;
}

void loop() {
    float d,prev=getDistance();
    float delta=0;

    while (true){
        delta=0;
        //get the first distance
        prev=getDistance();
        //get the image
        commandGetImage(0);//0.jpg is the image file taken
        //wait 50ms
        delay(50);
        //get the second distance
        d=getDistance();
        //calculate the delta
        delta=abs(d-prev);
        //if the delta is big send email - a movement is recognised!
        if(delta>2){
           Serial.print(" delta= "+String(delta) + "["+String(prev)+"cm,"+String(d)+"cm]");
           Serial.print("\nSENDING...");
          p.runShellCommand("python /www/cgi-bin/sendemail.py /www/" +String(0)+".jpg"); //sends the picture via email
          while(p.running()); //wait till the process ends
          Serial.println("E-MAIL SENDED");
        }else{
          Serial.print(".");
          delay(50);     
        }
    }
}

Attachments:
sendemail.py.zip
  • Sign in to reply
  • matfur92
    matfur92 over 10 years ago in reply to ipv1

    Thanks for the suggestion, but I was already awareimage I did not deliberately used that guidance, it was not my purpose.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ipv1
    ipv1 over 10 years ago

    You might also find it useful to visit this link

    https://www.google.co.in/url?sa=t&source=web&rct=j&ei=GrLBVOTxA4mX8QWmv4DwBA&url=https://learn.adafruit.com/wireless-security-camera-arduino-yun/introduction&ved=0CBsQFjAA&usg=AFQjCNFb4adPdqBLyjRCqHoeOeUQJA4gdg&sig2=tALnE2seGhbCnhNcfDKN9w

    Its an Adafruit tutorial on using temboo to send images to drop box. Its actually pretty simple.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube