Skip to content

Commit fd69d3d

Browse files
committed
Dev: added sonar for automatic close
1 parent e8b564a commit fd69d3d

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

AVP.png

59.2 KB
Loading

LCD_Keypad_Vault/LCD_Keypad_Vault/LCD_Keypad_Vault.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
#include "Buzzer.h"
1111
#include "IICLCD.h"
1212

13+
#include "NewPing.h"
14+
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
15+
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
16+
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
17+
18+
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // Creating the NewPing Object.
19+
unsigned long initial_distance = 0;
20+
1321
#include <Bounce2.h>
1422
#define OPEN_BUTTON 5
1523
Bounce open_button = Bounce(); // Instantiate a Bounce object
@@ -146,6 +154,9 @@ void setup() {
146154

147155
open_button.attach(OPEN_BUTTON,INPUT_PULLUP); // Attach the open_button to a pin with INPUT_PULLUP mode
148156
open_button.interval(25); // Use a debounce interval of 25 milliseconds
157+
158+
initial_distance = sonar.ping_in();
159+
delay(1000);
149160

150161
}
151162

@@ -208,6 +219,16 @@ void loop() {
208219
led_red->Off();
209220
lock_servo->Open();
210221
buzzer->Off();
222+
223+
while (true)
224+
{
225+
unsigned long value = sonar.ping_cm();
226+
227+
if (value >= initial_distance || value == 0)
228+
break;
229+
}
230+
231+
211232
delay(5000);
212233

213234
lcd->clearLCD();
@@ -218,6 +239,7 @@ void loop() {
218239

219240
case S_TIMEOUT:
220241
lcd->printWaitForTimeout(TIMEOUT_RANGE);
242+
led_red->On();
221243
delay(3000);
222244
while (1)
223245
{

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [**Servo.h**: _This library allows an Arduino board to control RC (hobby) servo motors_](https://github.com/arduino-libraries/Servo)
1818
* [**LiquidCrystal_I2C.h**: _The library allows to control I2C displays with functions extremely similar to LiquidCrystal library_](https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library)
1919
* [**Bounce2.h**: _Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with contributions from: Eric Lowry, Jim Schimpf, Tom Harkaway, Joachim Krüger and MrGradgrind._](https://github.com/thomasfredericks/Bounce2)
20-
20+
* [**NewPing.h**: _Works with many different ultrasonic sensor models: SR04, SRF05, SRF06, DYP-ME007 & Parallax PING_](https://playground.arduino.cc/Code/NewPing/)
2121
#### `Pins`
2222

2323

@@ -47,6 +47,10 @@
4747
* C3 51
4848
* C4 53
4949

50+
//Sonar
51+
* ECHO 11
52+
* TRIG 12
53+
5054
Check the code and find this line
5155
//Select only one keypad type
5256
#define KEYPAD_4x4
@@ -62,3 +66,4 @@ Check the code and find this line
6266
* [**Keypad**: _Interface 4×3 & 4×4 Membrane Keypad with Arduino_](https://lastminuteengineers.com/arduino-keypad-tutorial/)
6367
* [**Servo**: _How to control servo motor_](https://www.intorobotics.com/tutorial-how-to-control-the-tower-pro-sg90-servo-with-arduino-uno/)
6468
* [**LiquidCrystal_I2C**: _How to Use I2C Serial LCD 20X4_](https://www.instructables.com/id/How-to-Use-I2C-Serial-LCD-20X4-Yellow-Backlight/)
69+
* [**NewPing**: _Arduino HC-SR04 (with LCD)_](https://www.instructables.com/id/Arduino-HC-SR04-with-LCD/)

frtizing/AVP.fzz

3.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)