Ali Gamal
Published © LGPL

Security home with Twitter

An ultrasonic device that measures distance with Arduino and 1sheeld and Batsal with mobile and Perfa pictures on Twitter

BeginnerFull instructions provided2,398

Things used in this project

Custom parts and enclosures



19-09-2015 11-24-49 م.png


smart home scurtiy tiwiter.ino


Camera Shield Example

This example shows an application on 1Sheeld's camera shield.

By using this example, you can take a photo using your phone's
camera if the light sensor reads data above a certain threshold.


/* Include 1Sheeld library. */ 
#include <OneSheeld.h>

const int trigPin = 2;
const int echoPin = 4;

void setup()
  /* Start communication. */

void loop()
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
    // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
  /* Always get the value of the light sensor and make sure it is in a certain range. */
  if(cm < 100 && cm > 30)
    Terminal.println("Photo will be taken");
    /* Turn on the camera's flash while capturing. */
    /* Take a photo using the phone's rear camera. */
    /* Delay for 5 seconds. */
    String status = "status to be written to facebook along the picture";
    Twitter.tweetLastPicture(status , 0/1);


long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;



Ali Gamal

Ali Gamal

1 project • 0 followers