Mahmoud Labib
Published

Control your windows and Bust burglars

Using a slider on your smartphone you could open or close your windows also using a sensor your smartphone buzzes in case of a thief.

IntermediateFull instructions provided2 hours4,106
Control your windows and Bust burglars

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
1Sheeld
1Sheeld
×1
Servos (Tower Pro MG996R)
×1
ultrasonic sensor
×1

Story

Read more

Schematics

Schematic

Fritzing schematic of the circuit

Code

Code

Arduino
It is used to launch a buzzer on your smartphone whenever there is someone within a 10 cm range from your front door and control your windows using the slider in the 1Sheeld app.
#include <OneSheeld.h>
#include<Servo.h>
const int trig = 7;
const int echo = 6;
const int windowServoPin=9;
Servo windowServo;



void setup() {
  // initialize serial communication:
  OneSheeld.begin();
  Serial.begin(9600);
  windowServo.attach(windowServoPin);
  }
  
void loop() {
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trig, OUTPUT);
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(5);
  digitalWrite(trig, LOW);

  // The same pin is used to read the signal from the PING))): 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(echo, INPUT);
  duration = pulseIn(echo, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);

  Terminal.print(cm);
  Terminal.print(" cm");
  Terminal.println();
  if (cm <= 10 & ToggleButton.getStatus()==1) {
    Buzzer.buzzOn();
  }
  else {
    Buzzer.buzzOff();
  }
  
   int value = Slider.getValue();
  value = map(value,0,255,0,180);
  windowServo.write(value);
}
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;
}

Credits

Mahmoud Labib

Mahmoud Labib

1 project • 5 followers
I am an amateur enthusiastic engineer who loves to fiddle with micro-controllers.

Comments