Introduction: Safety Box Using Arduino

Picture of Safety Box Using Arduino

Welcome guys ! Well this is my second Instructable. And I am pretty happy to publish another one. So now lets go on to the subject. Lets start with the intro. In this Instructable I am going to show you how to build a safety box (uses - hide your toffees which you took from your sister, Your toy car which you need to hide from your annoying brothers (I am not sure weather your 1 year only brother will be scared by a buzzer alarm) or hide your snacks ! ). Now what this box does is that it scares an intruder and scares him with a loud noise or at least wake you up. Well it is not super safe to put some money in it. But at least you can hide something in it and can sleep comfortably . The alarm gets on when some body tries to touch the lock or break it. Now you have to do a small job (don't worry it has nothing to do with studying). With out going to the next page look at the image above in the form of an intruder and try to find out a way to open the box (remember you are seeing it the first time) . If you find it out you are a smart. Now you don't want the intro to go too long, is it ? So on to the next step !

Step 1: Things You Need:

Picture of Things You Need:
  • Arduino x1
  • 10k resistor x1
  • breadboard x1
  • buzzer x1
  • LCD display(16x2)(white letters on blue display will look cool) x1
  • Jumper wire(don't worry of how much to buy extra is always handy)
  • potentiometer x1
  • ultrasonic sensor ( I'm using HC - SR04, works well!) x1
  • IR module x1
  • servo motor x1

Step 2: Playing With Sensors

Picture of Playing With Sensors

The first thing we are going through is to know how sensors and other things works. So lets start with the ultrasonic sensor. There is a trig pin on the ultrasonic sensor. It sends an ultrasonic sound(sound that has a frequency above 20000Hz ) to an obstacle. When the sound hits an objects it reflects the sound back and it falls on the eco pin. Then the sensor measures the amount of time take for the sounds to come back. then you can convert it into centimeters or inches using the code. The bat also use the same principle to navigate in the dark. But there is a weak point for a ultrasonic sensor. It is that it can't detect things that are too close to it. So it would be best that you use one more IR module to trigger the alarm. Well I didn't get one more for my project(my bad). Please refer the picture above to be more clear about how it works. So lets go on to the next sensor- IR module.

Now an IR module is a combination is a of an IR sender and IR receiver. IR sender sends an infrared light (yes the same thing you learnt in the physics class). It cannot be seen by our naked eye. But your camera can spot it. So the next time you are pressing your TV remote look it through your camera lens. So when the IR sender sends an IR ray it reflects back a certain amount of IR back to the IR receiver. The IR module sends only two signals high and low. If it is high it means there is something in front. If the received signal is low it means there is nothing in front.

Well since you were reading the principles of how different sensors work you must be seriously tired. Go and garb a chilled drink from the chiller !

Step 3: The Connection Business

Picture of The Connection Business

Please hold on to your seats and put your seatbelts because you are going for wild ride in the jungle of wires, sensors, and other stuff. Well so what are we waiting for let us start !

Well in this step let us discuss about the connections. You have the positive terminal of the buzzer connected to the digital pin 6. While connecting the LCD you don't want to connect four of the pins. The servo pin is connected to digital pin 10. The IR module's data pin is connected to the digital pin 7. The ultrasonic sensor's trigpin is connected to digital pin 8. The eco pin is connected to the digital pin 7. If you have any trouble look in the diagram above. I do hope it is not confusing.

Step 4: The Body Work

Picture of The Body Work

Well as you can see my connections looks seriously like a jungle. But that doesn't matter as long as it is working and as you are going to put it in a box.

FIND A BOX - Find a box of your convenience but make sure it is strong (well, almost).

THE LOCKING MECHANISM - In the locking mechanism you have a servo which is in 0 degree position.

PLACE YOUR SENSOR - Make a hole for your ultrasonic sensor to come out.

DISPLAY - for the display cut out the right amount cardboard to show the LCD display(make sure no body can put hands in it).

YOUR CARD SLOT - On the top right side of your box (image 4) make a narrow cut gut enough for your card to pass through.

MAKE A HOLE - Make a hole on the right side of your box(image 5 & 6). This is to make sure the IR will detect your card only. If there is no hole then the IR will detect the wall of the box as your card.

PLACE YOUR IR MODULE - Inside the box, place an IR module pointing toward the hole you just made. (image 8)

TAPE THE HOLE - Tape the hole with a black tape(make sure you tape it outside the hole). You should tape it with a black tape. We are using black tape because the IR rays emitted will be absorbed by the black color (yes, yes back to our physics class).so when the card is kept(the card should be of a light color) it will become an obstacle.(image 7).

Well I am not good a painter so..... my box looks like a pizza box which was eaten by ants. But I am sure yours will look cool.

Step 5: The Code !

Time to do some programing. now let me tell you what this code does - if any body tries to touch or break the lock the buzzer will start to ring. The lock will only open if you put in your card. Once the card is put and the lock is open you don't want to worry about the buzzer ringing when you touch the lock. The buzzer and the ultrasonic sensor will automatically disable itself. Now I will let you one tip. When you keep your box in your cupboard or in another place keep a black card below your box. If he notices the slot to put the card most probably he will search for a card in the same area. when he notice the black card he will try to put it in the black slot but the lock wont open. Then he will stop trying. Now for the code -

#include <Servo.h>

#include <LiquidCrystal.h>

LiquidCrystal LCD(12, 11, 5, 4, 3, 2); //name the liquidcrystal object as LCD

int buzzer = 6;//name pin 6 as buzzer

int trigpin = 8; //name pin 8 as trigpin

int ecopin = 9; //name pin 7 as ecopin

int irpin = 7; //name pin 7 as irpin

int servopin = 10;

int state; //create a variable named state

int value;

float pingTime; //time for ping to travel from sensor to target and return

float targetDistance; //Distance to Target in inches

float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.

Servo servo;//name our servo

void setup() {

// put your setup code here, to run once:

pinMode(buzzer, OUTPUT);//set buzzer as output

pinMode(irpin,INPUT);//set ir module as input

pinMode(trigpin, OUTPUT);//set trigpin as output

pinMode(ecopin, INPUT);//set ecopin as input

servo.attach(servopin); //attach the servo to pin 10

LCD.begin(16, 2);

digitalWrite(buzzer, LOW);//the initial state of the buzzer is low

}

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(trigpin,LOW); //activate the ultrasonic sensor

delayMicroseconds(2000); //activate the ultrasonic sensor

digitalWrite(trigpin,HIGH);//activate the ultrasonic sensor

delayMicroseconds(15); //activate the ultrasonic sensor

digitalWrite(trigpin,LOW);//activate the ultrasonic sensor

delayMicroseconds(10);//activate the ultrasonic sensor

pingTime = pulseIn(ecopin, HIGH); //pingTime is presented in microseconds

pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second) pingTime=pingTime/3600; //convert pingtime to hours by dividing by 3600 (seconds in an hour)

targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per hour targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.

targetDistance= targetDistance*63360; //Convert miles to inches by multiplying by 63360 (inches per mile)

state = digitalRead(irpin);

if (state == LOW && targetDistance <3)//if there is something in front and the card is not in the place

{

servo.write(0);//servo should not move

digitalWrite(buzzer, HIGH);//turn the buzzer on

LCD.setCursor(0,0);

LCD.print("WARNING ");//put some space after writing the text to make the sure that the text does not collide after the second loop

LCD.setCursor(0,1);

LCD.print(" ");//print blanks in the second row also

} else if //there isn't much difference between this and "if" statement

(state == HIGH && targetDistance > 3)//if the card is put and there is no body in front then

{

servo.write(90);//turn the lock

LCD.setCursor(0,0);

LCD.print("unlocked ");

LCD.setCursor(0,1);

LCD.print(" ");

}

else if

(targetDistance > 3 && state ==LOW)//if there is nobody in front and the cad is not put

{

LCD.setCursor(0,0);

LCD.print("please dont open ");//you don't need to print blanks here because this is the longest line LCD.setCursor(0,1);

LCD.print("the box");

digitalWrite(buzzer, LOW);//turn the buzzer off

} }


So this is the code. So best of luck guys ! Hope your toffee will stay in it, hey it is not ant safe(put it in an air tight bag)!



Comments

joshboye (author)2017-04-29

hey,

thanks

About This Instructable

666views

10favorites

License:

Bio: Just an ordinary 14 year old with interest in electronics.
More by joshboye:The Ghostly FrameHow to Build a Mouse Trap Using ArduinoSafety Box Using Arduino
Add instructable to: