ARDU-BYKE SHIELD
ARDU-BYKE-SHIELD
Introduction
Everyone in this world wants to protect the things which they like the most or their valuable belongings. Some people like to secure their cars and some want to secure their toys. This project is one of my attempts to secure my bike(MTB).
The question: How to secure it?
How exactly and by which means?
The questions stated above laid the foundation of my project, which ultimately led me to ARDU-BYKE SHIELD.I have used Arduino Nano for this project.This idea revolves around a small concept of shocks and vibrations.
There exist a sensor in the world known as a shock sensor. This sensor senses the vibes and converts them into electrical signals and sends them to the reader(Arduino nano in this case).One can do more research on this ,but that’s not the topic here.
Here we assume that if someone touches a bike/safe/door , it may be unintentional but if the touch/teases continues then there must be something wrong and the gadget should warn us. After a delay of 7 seconds,
if the gadget continues to receive vibrations, it will produce a high-pitched
alarm and warn the user at the same time.
I HAVE USED IR REMOTE HERE IN THE PROJECT ,AS IN INDIA (MAYBE IN SOME OTHER COUNTRIES ALSO) STUDENTS ARE NOT ALLOWED TO BRING MOBILES OR ANY OTHER GADGET IN THE SCHOOLS.SO IR REMOTE WILL DO.
This project is inexpensive and made using easily available materials for students to do .
Let's start,
Gather Your Materials!
The materials required are :
1. Arduino NANO(any arduino can work but due to small size factor I have used nano)
2. Shock sensor
3. PVC pipe of 1.5 inches(diameter) length (7 inches)
and pipe caps
4. IR receiver (TSOP1738 Sensor)
5. IR remote(any will work)
6. Rechargeable batteries
7. Charge controller circuit/ power bank will do
8. Mounting screws
9. Aluminum strip
10. Duct tap
11. 4 ohms 5 watt speaker
12. Amplifier circuit(5volts)
13. Wire connector
14. Dc barrel jack for charging
15. Dc jack adaptor (5 volts 1 amp)
Connections and Circuit Diagram
ARDUINO TO CORRESPONDING PINS
D12 ----->>>>>>>>>>> IR PIN1
D2 ----->>>>>>>>>>> SIGNAL PIN Of shock sensor
D3 ---->>>>>>>>>>> BUZZER (+)PIN
D9 ----->>>>>>>>>>> TRANSISTOR PIN2
OTHER CONNECTIONS
TSOP+ pin(3)--------->>> VCC
TSOP- pin(2) -------->>>>GND
BATT+ ----->>>>>>>>>> CHARGER VCC
BATT- ----->>>>>>>>>> CHAGER GND
SENS GND ----->>>>>>> GND
SENS GND ----->>>>>> VCC
CIRCUIT OUT+ ----->>> ICSP VCC
CIRCUIT OUT- ----->>> ICSP GND
Code Design
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////PRIYANSHU UCHAT////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////priyanshu.uc507@gmail.com///////////////////////////////////////////////////////////
#include
String pass = "007"; //Password to unlock.set as per your wish
int chances = 3; //Chances before 1 will start to buzz continuously.
bool afterChances = true;
int BUZZER = 12;// integer for defining buzzer
int RECV_PIN = 9;// reciveing signal from pin 1 of TSOP
String btn1 = "1fe50af"; //Your button 1 IR HEX code (in lower case). eg.: ff63ad
String btn2 = "1fed827"; //Your button 2 IR HEX code (in lower case).
String btn3 = "1fef807"; //Your button 3 IR HEX code (in lower case).
String btn4 = "1fe30cf"; //Your button 4 IR HEX code (in lower case).
String btn5 = "1feb04f"; //Your button 5 IR HEX code (in lower case).
String btn6 = "1fe708f"; //Your button 6 IR HEX code (in lower case).
String btn7 = "1fe00ff"; //Your button 7 IR HEX code (in lower case).
String btn8 = "1fef00f"; //Your button 8 IR HEX code (in lower case).
String btn9 = "1fe9867"; //Your button 9 IR HEX code (in lower case).
String btn0 = "1fee01f"; //Your button 0 IR HEX code (in lower case).
String btnReset = "1fe906f"; //Your button REPEAT OR RESET BUTTON IR HEX code (in lower case).
bool locked = true;
bool shouldBeep = true;
bool unlockSound = true;
String cPass = "";
int chance = 0;
String cmp = "----PRIYANSHU UCHAT-----\n";
String str2 = "AT-----\n";
void setup() {
pinMode(9, INPUT);
pinMode(12, INPUT); //set EP input for measurment
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);//init serial 9600
Serial.print(cmp);
}
void loop() {
if (cmp.endsWith(str2) == false)
Serial.print("Error!");
else {
if (irrecv.decode(&results)) {
if (String(results.value, HEX) == btn1) {
Serial.print("1");
updatePass("1");
}
else if (String(results.value, HEX) == btn2) {
Serial.print("2");
updatePass("2");
}
else if (String(results.value, HEX) == btn3) {
Serial.print("3");
updatePass("3");
}
else if (String(results.value, HEX) == btn4) {
Serial.print("4");
updatePass("4");
}
else if (String(results.value, HEX) == btn5) {
Serial.print("5");
updatePass("5");
}
else if (String(results.value, HEX) == btn6) {
Serial.print("6");
updatePass("6");
}
else if (String(results.value, HEX) == btn7) {
Serial.print("7");
updatePass("7");
}
else if (String(results.value, HEX) == btn8) {
Serial.print("8");
updatePass("8");
}
else if (String(results.value, HEX) == btn9) {
Serial.print("9");
updatePass("9");
}
else if (String(results.value, HEX) == btn0) {
Serial.print("0");
updatePass("0");
}
else if (String(results.value, HEX) == btnReset) {
resetPass();
Serial.println("\nRESET");
}
irrecv.resume(); // Receive the next value
}
if (locked == true) {
MAIN();
}
else {
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool updatePass(String ch) {
if (locked == false)
return false;
beep();
if (updatable() == true) {
cPass += ch;
if (cPass.length() < pass.length()) {
}
else {
if (pass == cPass) {
locked = false;
chance = 0;
digitalWrite(4, LOW);
digitalWrite(2, LOW);
for (int k = 1000; k < 4000; k = k + 200)
{
tone(4, k, 300);
delay(70);
}
Serial.println("\nUNLOCKED");
if (unlockSound == true) {
beep();
}
}
else {
cPass = "";
chance += 1;
for (int k = 300; k < 1000; k = k + 100)
{
tone(4, k, 300);
delay(100);
}
Serial.println("\nWRONG PASSWORD!");
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool updatable() {
if (chance <= chances)
return true;
return afterChances;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void resetPass() {
cPass = "";
locked = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void beep() {
if (shouldBeep == true) {
for (int k = 0; k < 4000; k = k + 500)
{
tone(4, k, 300);
delay(70);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////1
void MAIN() {
if (locked == true) {
digitalWrite(2, HIGH);
long measurement = TP_init();
delay(10 );
if (measurement > 100) {
Serial.println(measurement );
digitalWrite(4, HIGH);
for (int k = 3000; k < 4000; k = k + 200)
{
tone(4, k, 300);
delay(70);
}
delay(1000);
digitalWrite(4, LOW);
measurement == 0;
delay(7000);
long measurement = TP_init();
delay(10);
Serial.println(measurement);
if (measurement > 100) {
Serial.println(measurement);
for (int p = 0; p < 120; p++)
{
for (int j = 3000 ; j < 5000 ; j = j + 200)
{
tone(4, j, 400);
delay(70);
irrecv.resume();
}
delay(100);
if ((irrecv.decode(&results)) == true)
{
if (String(results.value) = btnReset)
{
Serial.println("\nRESET");
digitalWrite(4 , LOW);
digitalWrite(2, LOW);
irrecv.resume();
break;
}
}
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
long TP_init() {
delay(10);
long measurement = pulseIn (12, LOW);
return measurement;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
How This Code Functions?
HOW THIS CODE FUNCTIONS:
The code receives digital signals from the SHOCK Sensor. It checks the vibration values received from the sensor continuously. If it detects any vibration more than prescribed value , it will beep once (as warning considering it an unintentional touch ).
But if someone continuously try to move the VEHICLE/ DOOR/SAFE where this gadget is installed for more than prescribed time (7 seconds in the instant case ), it will sound a high-pitched alarm continuously until stopped by the user with help of IR remote control by pressing a designated button . But this will only reset the alarm, a designated passcode(through IR remote) is required to be entered to switch off the alarm.
When a number button is pressed by the user for entering the passcode, the gadget will acknowledge the same by beeping a tone. If entered passcode is correct , a confirmation long tone will be played and system will enter in unguarded mode for using the vehicle or open door or safe. If wrong passcode is entered then it will play a short tune to acknowledge the same.
#include <EEPROMex.h> #include <IRremote.h> int count; int df ; int pinsCount = 5; // declaring the integer variable pinsCount int pins[] = {A1, A2, A3, A4, A5}; String pass ; int de; String cdePass; String pass1 = "444"; //Password to unlock.set as per your wish int chances = 3; //Chances before 1 will start to buzz continuously. bool afterChances = false; bool afterChances1 = false; int greenLed = 7 ; //Green LED pin. int redLed = 8; //Red Led pin. int p = 0; int RECV_PIN = 9; bool GET_OUT_TO_LOOP = false; String btn1 = "1fe50af"; //Your button 1 IR HEX code (in lower case). eg.: ff63ad String btn2 = "1fed827"; //Your button 2 IR HEX code (in lower case). String btn3 = "1fef807"; String btn4 = "1fe30cf"; String btn5 = "1feb04f"; String btn6 = "1fe708f"; String btn7 = "1fe00ff"; String btn8 = "1fef00f"; String btn9 = "1fe9867"; String btn0 = "1fee01f"; String btnReset = "1fe906f"; String btneset = "1fe58a7"; String btnMUTE = "1fe7887"; bool locked = true; bool shouldBeep = true; bool unlockSound = true; String cPass = ""; int chance = 0; String cdPass = ""; int chance1 = 0; int chances1 = 4; int addressCharArray; uint8_t EEPROMaddress = 132; int LED1 = A1; int LED2 = A2; int LED3 = A3; int LED4 = A4; int LED5 = A5; int t = 0; IRrecv irrecv(RECV_PIN); decode_results results; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void setup() { for (int i = 0; i < pinsCount; i = i + 1) { // counting the variable i from 0 to 9 pinMode(pins[i], OUTPUT); // initialising the pin at index i of the array of pins as OUTPUT } pass = EEPROM.readLong(EEPROMaddress); String thisString = String(pass); Serial.begin(9600); Serial.print(thisString); pinMode(9, INPUT); pinMode(12, INPUT); //set EP input for measurment pinMode( LED1, OUTPUT); pinMode( LED2, OUTPUT); pinMode( LED3, OUTPUT); pinMode( LED4, OUTPUT); pinMode( LED5, OUTPUT); irrecv.enableIRIn(); // Start the receiver pinMode(2, OUTPUT); pinMode(4, OUTPUT);//init serial 9600 for (int i = 0; i < pinsCount; i = i + 1) { // chasing right digitalWrite(pins[i], HIGH); // switching the LED at index i on delay(300); // stopping the program for 100 milliseconds digitalWrite(pins[i], LOW); // switching the LED at index i off } for (int i = 0; i < pinsCount; i = i + 1) { // chasing right digitalWrite(pins[i], HIGH); // switching the LED at index i on delay(300); // stopping the program for 100 milliseconds digitalWrite(pins[i], LOW); // switching the LED at index i off } for (int i = 0; i < pinsCount; i = i + 1) { // chasing right digitalWrite(pins[i], HIGH); // switching the LED at index i on delay(300); // stopping the program for 100 milliseconds digitalWrite(pins[i], LOW); // switching the LED at index i off } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void loop() { GET_OUT_TO_LOOP = false; if (irrecv.decode(&results)) { if (String(results.value, HEX) == btn1) { Serial.print("1"); updatePass("1"); } else if (String(results.value, HEX) == btn2) { Serial.print("2"); updatePass("2"); } else if (String(results.value, HEX) == btn3) { Serial.print("3"); updatePass("3"); } else if (String(results.value, HEX) == btn4) { Serial.print("4"); updatePass("4"); } else if (String(results.value, HEX) == btn5) { Serial.print("5"); updatePass("5"); } else if (String(results.value, HEX) == btn6) { Serial.print("6"); updatePass("6"); } else if (String(results.value, HEX) == btn7) { Serial.print("7"); updatePass("7"); } else if (String(results.value, HEX) == btn8) { Serial.print("8"); updatePass("8"); } else if (String(results.value, HEX) == btn9) { Serial.print("9"); updatePass("9"); } else if (String(results.value, HEX) == btn0) { Serial.print("0"); updatePass("0"); } else if (String(results.value, HEX) == btnReset) { resetPass(); Serial.println("\nRESET"); } else if (String(results.value, HEX) == btneset) { Serial.println("Reset PassCode "); for (int k = 1000; k < 6000; k = k + 600) { tone(4, k, 300); delay(70); } writeAndReadCharArray(); } irrecv.resume(); // Receive the next value } if (locked == true) { MAIN(); digitalWrite(redLed, HIGH); digitalWrite(greenLed, LOW); } else { digitalWrite(redLed, LOW); digitalWrite(greenLed, HIGH); } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void ThePJbeep() { for (int k = 200; k < 1500; k = k + 300) { tone(4, k, 300); delay(100); } } void ThePJBLINK() { for (int k = 200; k < 1500; k = k + 300) { tone(4, k, 300); delay(100); } } void ThePJbeep1() { for (int i = 0; i < pinsCount; i = i + 2) { // chasing right digitalWrite(pins[i], HIGH); // switching the LED at index i on delay(200); // stopping the program for 100 milliseconds digitalWrite(pins[i], LOW); // switching the LED at index i off } } bool updatePass(String ch) { if (locked == false) return false; beep(); t = t + 1; digitalWrite(pins[t], HIGH); if (updatable() == true) { cPass += ch; if (cPass.length() < pass.length()) { } else { if (pass == cPass) { locked = false; chance = 0; digitalWrite(4, LOW); for (int k = 1000; k < 4000; k = k + 200) { tone(4, k, 300); delay(70); } digitalWrite(greenLed, HIGH); Serial.println("\nUNLOCKED"); digitalWrite(13, LOW); for (int p = 0; p < 5; p = p + 1) { digitalWrite(pins[p], LOW); delay(100); } if (unlockSound == true) { beep(); } } else { cPass = ""; chance += 1; for (int k = 300; k < 1000; k = k + 100) { tone(4, k, 300); delay(100); } digitalWrite(LED4, HIGH); delay(1000); digitalWrite(LED4, LOW); Serial.println("\nWRONG PASSWORD!"); } } } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool updatable() { if (chance <= chances) { return true; return afterChances; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool updatable1() { if (chance1 <= chances1) return true; return afterChances1; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void resetPass() { cPass = ""; locked = true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void beep() { if (shouldBeep == true) { for (int k = 0; k < 4000; k = k + 500) { tone(4, k, 300); delay(70); } } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// long TP_init() { delay(100); long measurement = pulseIn (12, HIGH); //wait for the pin to get HIGH and returns measurement return measurement; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void MAIN() { if (locked == true) { digitalWrite(13, HIGH); long measurement = TP_init(); delay(10 ); //Serial.print("measurment = "); //Serial.println(measurement ); if (measurement > 100) { Serial.println(measurement ); digitalWrite(4, HIGH); for (int k = 3000; k < 4000; k = k + 200) { tone(4, k, 300); delay(70); } delay(1000); digitalWrite(4, LOW); measurement == 0; delay(7000); long measurement = TP_init(); delay(10); Serial.println(measurement); if (measurement > 12) { Serial.println(measurement); for (int p = 0; p < 1200; p++) { for (int i = 500; i < 800; i = i + 20) { tone(4, i, 30); delay(10); } for (int i = 1000; i > 500; i = i - 20) { tone(4, i, 30); delay(10); } irrecv.resume(); delay(100); if ((irrecv.decode(&results)) == true) { if (String(results.value) = btnReset) { Serial.println("\nRESET"); digitalWrite(4 , LOW); digitalWrite(2, LOW); irrecv.resume(); break; } // delay(100); } // irrecv.resume(); } } } } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void writeAndReadCharArray() { if (GET_OUT_TO_LOOP == true) { return; } //Serial.print("i am here"); if (locked == false) { digitalWrite(redLed, HIGH); digitalWrite(greenLed, HIGH); { for (int p = 0; p < 10000 ; p++) { delay(1000); if (irrecv.decode(&results)) { if (GET_OUT_TO_LOOP == true) { return; } if (String(results.value, HEX) == btn1) { Serial.print("1"); updatepassarray("1"); } else if (String(results.value, HEX) == btn2) { Serial.print("2"); updatepassarray("2"); } else if (String(results.value, HEX) == btn3) { Serial.print("3"); updatepassarray("3"); } else if (String(results.value, HEX) == btn4) { Serial.print("4"); updatepassarray("4"); } else if (String(results.value, HEX) == btn5) { Serial.print("5"); updatepassarray("5"); } else if (String(results.value, HEX) == btn6) { Serial.print("6"); updatepassarray("6"); } else if (String(results.value, HEX) == btn7) { updatepassarray("7"); Serial.print("7"); } else if (String(results.value, HEX) == btn8) { Serial.print("8"); updatepassarray("8"); } else if (String(results.value, HEX) == btn9) { updatepassarray("9"); Serial.print("9"); } else if (String(results.value, HEX) == btn0) { updatepassarray("0"); Serial.print("0"); } else if (String(results.value, HEX) == btnMUTE) { Serial.print("I AM in writeAndReadCharArray function"); GET_OUT_TO_LOOP = true; } else if (String(results.value, HEX) == btnReset) { Serial.println("Reset PassCode "); delay(500);// ThePJbeep(); PJRESET(); } irrecv.resume(); // Receive the next value } } } } else { Serial.println("please enter passcode first"); digitalWrite(redLed, HIGH); ThePJBLINK(); ThePJbeep1(); ThePJBLINK(); resetPass(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool updatepassarray(String c) { if (GET_OUT_TO_LOOP == true) { return; } if (locked == false) beep(); if (updatable1() == true) { cdPass += c; if (cdPass.length() < pass1.length()) { } else if (cdPass.length() == pass1.length()) { beep(); pass1 = cdPass ; df = cdPass.toInt(); Serial.print("\nAGAIN PLS!= "); RESETPT2(); exit; } } else {} } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void RESETPT2() { //Serial.print("i am here"); irrecv.resume(); for (int p = 0; p < 10000 ; p++) { delay(1000); if (irrecv.decode(&results)) { if (GET_OUT_TO_LOOP == true) { return; } else if (String(results.value, HEX) == btn1) { Serial.print("1"); updatepassarray1("1"); } else if (String(results.value, HEX) == btn2) { Serial.print("2"); updatepassarray1("2"); } else if (String(results.value, HEX) == btn3) { Serial.print("3"); updatepassarray1("3"); } else if (String(results.value, HEX) == btn4) { Serial.print("4"); updatepassarray1("4"); } else if (String(results.value, HEX) == btn5) { Serial.print("5"); updatepassarray1("5"); } else if (String(results.value, HEX) == btn6) { Serial.print("6"); updatepassarray1("6"); } else if (String(results.value, HEX) == btn7) { updatepassarray1("7"); Serial.print("7"); } else if (String(results.value, HEX) == btn8) { Serial.print("8"); updatepassarray1("8"); } else if (String(results.value, HEX) == btn9) { updatepassarray1("9"); Serial.print("9"); } else if (String(results.value, HEX) == btn0) { updatepassarray1("0"); Serial.print("0"); } else if (String(results.value, HEX) == btnMUTE) { Serial.print("I AM OUT"); return; } else if (String(results.value, HEX) == btneset) { Serial.println("Reset PassCode "); ThePJbeep(); PJRESET(); } irrecv.resume(); // Receive the next value } } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool updatepassarray1(String d) { if (GET_OUT_TO_LOOP == true) { return; } beep(); if (updatable1() == true) { cdePass += d; if (cdePass.length() < cdPass.length()) { } else if (cdePass.length() == cdPass.length()) { beep(); pass1 = cdPass ; de = cdePass.toInt(); Serial.println(de); if (df == de) { int f = EEPROM.writeLong(EEPROMaddress, df); Serial.print("\nThis is the new pass = "); Serial.println(pass1); String thisString = String(f); Serial.print("\ncount = "); Serial.println(thisString); digitalWrite(redLed, LOW); digitalWrite(greenLed, LOW); delay(1000); pass = pass1; locked = false; GET_OUT_TO_LOOP = true; return; } else { ThePJbeep1(); Serial.print("sorry pass wrong "); } } } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void PJRESET() { cdPass = ""; locked = false; irrecv.resume(); Serial.print("I AM in PJRESET"); writeAndReadCharArray(); } ///////////////////////////////////////////////////////// void PJBEEP2() { for (int i = 500; i < 800; i = i + 15) { tone(4, i, 1); delay(10); } for (int i = 200; i > 00; i = i - 15) { tone(4, i, 1); delay(10); } }
Assemble the Components
First drill a 3 holes through pipe cap ,first at center ,second at the boundaries and attach the ir receiver jack and strip as shown above.
Second, arrange all the components with the help of double sided tape as per convenience .So that fixes into the pipe properly.
third, drill some hole in the pipe(bottom side) .Here i have attached it on a bottle holder space . Do as per your requirement.
Fourth,drill some holes on other side of the pipe for speaker and some for screws attaching to the body with cap.
Fifth,now pass the strip after attaching on appropriate place and and connect with connector the speaker wires through connectors as i have done .
Now put on the screws to attach the pipe cap to the pipe body.
CRUDE MODEL SHOWN ABOVE ATTACHED ON MY MTB
NOTE: PLEASE COVER THE ALUMINIUM STRIP WITH DUCT TAPE TO AVOID CONDUCTION OF ELECTRICITY.
ARDU-BYKE SHIELD IS NOW READY! (FINAL GADGET)
THE FINAL GADGET AFTER ASSEMBLY
ARDU-BYKE SHIELD
HOPE YOU ENJOYED IT!!
THANKS FOR READING/VIEWING.
BE SAFE.BE SECURE.