Close
0%
0%

Nano Bike Alarm

An affordable RFID, motion-sensing, anti-theft alarm and GPS tracker for bicycles, e-bikes and other small vehicles. Based on Arduino

Similar projects worth following
A small Arduino based anti-theft system with motion-sensing, SMS alerts, GPS tracking and RFID keys for use on Bicycles, eBikes, motorcycles, RVs, etc. Designed to be build-able for under $100 and small enough to conceal inside a bike seat, pannier or battery box.

The design goal was to make it super-simple to use- To arm, remove the PICC key card from it's pocket. To disarm, replace the PICC in it's pocket. If it senses motion when armed, it sends you a text message, including GPS.

It uses the Arduino Pro Mini, the Adafruit FONA 808 GSM/GPS board, the MPU6050 accelerometer/gyro and the MFRC522 SPI Mifare RFID reader/writer.

[Update: 2015/08/15] -

I now consider this project complete and highly successful. I've been using it IRL for 2 months and its great! I'll likely print out a case for it (and add a project log of course) otherwise it's done.

Note

This project is not for beginners. It assumes some familiarity with Arduino and the Arduino IDE. Intermediate soldering skills are also required. Also we're pushing the limits of the Atmega328P RAM. So the we use a separate sketch to provision keys. (Note- I originally wrote it as one app and had the key provisioning data in EEPROM. But it was WAY too big to compile once the MPU and GPS parsing code was added. )

While this project is ongoing, its also quite stable. My biggest remaining challenges are to see-

  • how small can I make the finished hardware?
  • how many features can I fit into 32k RAM?
  • How low can I get the power consumption?

The current version uses the Arduino Pro Mini at 3.3V which eliminates the need for the boosting regulator that was in the original version. (The first prototype was built from parts I had lying around.) The alarm sits on the FONA like a shield and is about as small as I can make without busting out Kicad . If you wish to follow along and build one yourself, check out the 'Directions' section below.

Prerequisites

In addition to the Arduino IDE, this sketches use the following Arduino Libraries and will not compile without them-

Software

This project consists of 2 sketches- Bike-Alarm and newKey.

  • Bike-Alarm is (as you might imagine) the alarm sketch.
  • newKey provisions a new PICC card. In order for everything to work, the RFID encryption keys, sector number and token data MUST match in both sketches. It can also be used to unprovision or test PICCs.

(BTW - Please don't use the default key or token! It'll work. But it's like making your password 'password'.)

Usage

Once the system is installed and configured, to use you simply place the provisioned PICC (card) in it's 'pocket' within range of the RFID reader. Once the reader authenticates the PICC, the alarm emit beep three short beeps, indicating it's disarmed. Remove the PICC and the alarm arms, emitting one long beep.

When armed, the Arduino turns on the GPS, then scans the output from the MPU6050. If motion is sensed an SMS with the GPS coordinated, heading and speed of the bicycle are sent to the alert phone. SMS are sent by default every 4 minutes while motion continues or every 10 minutes until the alarm is disarmed. (This behavior can be altered in the config.) The alarm is silent and does not beep when triggered. However, you could also change that in the sketch, should you so desire... (or perhaps even take some other action, like have it voice dial your mobile and yell at the thief via speaker phone? ;-)

Troubleshooting

If you run into problems there is quite a bit of disabled debugging code in the sketch that can be used with the serial monitor to figure things out. But even enabling the DEBUG #ifdefs is unlikely to work because the sketch uses almost all of the Atmega328P's memory without any debugging enabled. So you'll probably need to enable the debug messages you need 'a la carte' by commenting out the #ifdef and #endif on either side of them. Most errors can be deduced by the beep. If you run into issues you can post your question here on the project page and I'll try to assist.

To prevent issues always power up with the PICC next to the reader. If the unit beeps continuously on power up there was an error initializing the hardware.

If the unit beeps continuously when arming then there is no GSM network available to the FONA - Check your antenna and SIM.

License (GPL v2) is available on the Github project page.

Bugs can be reported to info@boffinry.org.

This is a work in progress! This does NOT come with any warranty...

Read more »

  • 1 × Arduino Pro Mini 3.3V 8MHz (Original prototype used an Nano, New version is 3.3V
  • 1 × Adafruit FONA 808 GPRS+GPS Breakout Adafruit GSM mobile phone module with buitl-in GPS
  • 1 × MPU6050 breakout MPU6050 I2C sensor breakout
  • 1 × MFRC522 RFID reader SPI Mifare compatible RFID reader/writer
  • 1 × MiFare classic 1K RFID cards (PICC) You usually get a couple with the MFRC522 reader

View all 17 components

  • Version 2.0 Demo Video

    Alpha Charlie07/01/2015 at 02:23 0 comments

    This video shows a demonstration of version 2.0 of the Nano Bike Alarm which implements a beeps for user feedback. It shows arming and disarming with the RFID key and also shows the alarm being triggered.

    The text message received looks like this and has a Google Maps link of the GPS location and the current speed and heading.

  • Video Demo

    Alpha Charlie06/23/2015 at 00:32 0 comments

    heres a short functional demo of the prototype.

View all 2 project logs

  • 1
    Step 1

    Hardware

    [Update: 2015/07/01 - Added additional info for those connecting the Nano Alarm to higher voltage (24, 36, 48 VDC eBike) batteries. ]

    NOTE- Before you start soldering, it's a good idea to plug your Arduino into your PC via the FTDI adapter and verify that it works and that you can upload sketches. It sucks to find out you've got a bad one after all the soldering is complete...

    The hardware is fairly easy to assemble here. Each component uses a different bus and different pins. The only pins with multiple connections are the Vcc and Gnd pins. This makes it easy to wire point-to-point for the smallest device footprint. See the wiring diagram below for details.

    The circuit above shows the original 5V prototype. The newest version uses the Arduino Pro Mini at 3.3V and does not have the Boosting 5V regulator. Instead the Raw pin of the Arduino Mini is connected to the Bat pin of the FONA 808. Otherwise the wiring is pretty much the same.

    Original prototype (left) next to the much smaller v2 layout(right)

    To construct the Nano Bike Alarm First you'll want to get the MPU6050 mount set up. To do that, solder 2 male header pins to the A4 and A5 on the Arduino.

    Now solder some short jumper wires to the VCC, Gnd and Int pins on the MPU6050.

    Now Solder the wire from the Int pin to pin D2 on the Arduino (leave yourself a little extra wire for slack.) After that take 2 lengths of pin header and solder it to all the other pins on the top row of the Arduino (i.e. everything except D2). Now you can lay the MPU6050 upside-down on the Arduino so that the SDA and SCL pins on the MPU connect to A4 and A5. (Not as confusing as it sounds, see photo below). After that you can connect the Gnd and Vcc jumpers (don't solder the Vcc jumper yet though!)

    Now take another short jumper wire and connect it to the bottom of the Vcc pin on the Arduino and solder them both, then solder the Arduino to the proto-board as shown in the photo below.

    Next solder some female header on to the other half of the proto-board for the FONA. and connect jumper wires so that-

    • Bat on the FONA goes to Raw on the Arduino
    • Gnd on the FONA goes to Gnd on the Arduino
    • Vio on the FONA goes to Vcc on the Arduino
    • Rx on the FONA goes to pin D5 on the Arduino
    • Tx on the FONA goes to pin D6 on the Arduino
    • RST on the FONA goes to pin D7 on the arduino
    • Key on the FONA goes to Gnd on the Arduino

    Next solder the beeper to the proto-board and connect the + pin to D8 on the Arduino and the other pin to Gnd (using jumpers). You can also use a bit of Kaptan tape to insulate the different layers from each other.

    Next solder the RFID to the alarm so that-

    • 3.3V on the RFID goes to Vcc on the Arduino
    • Gnd goes to Gnd
    • Rst on the RFID goes to pin D9 on the Arduino
    • SDA on the RFID goes to Pin D10 on the Arduino
    • MOSI on the RFID goes to pin D11 on the Arduino
    • MISO on the RFID goes to pin D12 on the Arduino
    • SCK on the RFID goes to pin D13 on the Arduino.

    Congratulations! You are done building the hardware!


    The photo below shows the completed Nano Bike Alarm.

  • 2
    Step 2

    Software Configuration

    Once you have the hardware complete, extract the package and open the 'newKey' sketch.

    In the Arduino IDE, edit this sketch and change the hex values for the newA and newB keys and for the tokenBlockData array. The keys are 6 bytes long. The token block is 16 bytes. To generate random bytes for your key and tokn you can use https://www.random.org/bytes/ (though you'll probably have to add '0x' to bytes they give you....)

    Once you have customized your keys and token you can compile and run the newKey sketch. Once the sketch is running, connect to the Serial monitor in the Arduino IDE and follow the prompts to provision your PICC. At the end of the process if it's complete you will be given the UID of the PICC card. Write that down for the next step. (You can also unprovision PICC's or test the authentication with the newKey sketch as well.)

    Once that is complete open the Bike-Alarm sketch and scroll to the USER CONFIG section (show below). You don't have to mess with most of those options. All you really have to do to configure the Nano Alarm is-

    • Set your alarmKeyA to the key byte array you generated for key A of the newKey sketch
    • set your tokenBlockData to the values you used for the newKey sketch
    • place your key UID in one row of the keyUIDs array (make sure the number of rows matches the N_UIDS var or the sketch won't compile.
    • put your cell # in the alertphone variable
    // BEGIN USER CONFIG
    
    // the following values are user configurable. Key, keyUIDs and blockTokenData must match 
    //    what's in the newKey sketch for authentication to succeed.
    
    //the cell phone number to send alert SMS to
    char alertPhone[] = "8005551212"; // Change this to your cell #!!!!
    
    //alarm sensitivity in percentage
    byte alarmSensitivity = 60; //set sensitivity of alarm 1 = lowest 100 = highest
    
    //this is key A for our RFID (Note : DO NOT use the default key of FFFFFFFFFFFF or the one provided!!! Make up your own.)
    byte  alarmKeyA[6] = { 0x3b, 0x32, 0xa8, 0xc3, 0x3f, 0xf5 };
    
    //put the UIDs of your RFID PICCs here and define the number of keys...
    // this is the number of provisioned UIDs
    #define N_UIDS   3
    
    // These are the provisioned UIDs, one per row. You MUST add your key UIDs here after you provision.
    // MUST be one key per row and match the number of keys in N_UIDS above.
    byte keyUIDs[N_UIDS][4] =  {
        { 0x00, 0x00, 0x00, 0x00 }, //key 1 UID
        { 0x00, 0x00, 0x00, 0x00 }, //key 2 UID
        { 0x00, 0x00, 0x00, 0x00 }  //key 3 UID
    };
    
    //define the sector and blocks used by the application
    byte sector = 1;
    
    //this is the token block (i.e. THIS IS YOUR KEY!) Change it to something unique 
    byte tokenBlockData[16]    = {
        0x13, 0x52, 0xf2, 0x5b,
    	  0xc8, 0x8c, 0x2d, 0xb0,
    	  0x7a, 0xe7, 0xcd, 0x86,
    	  0xbc, 0xe9, 0xf2, 0x0f
    };
    
    byte settleTime = 15;  //time to let the MPU settle after arming. Increase if you get false positive alarm right after arming.
    
    //   Integrate some loop management to limit SMS and keep from TEXT BOMBING ourselves
    int messageDelay = 1200; //minimum delay between messages in loops  (one loop is around 200mS so 1200 = 1200 * 0.2 ~ 240 seconds
    int alertDelay = 6000; // delay for follow-up alerts once triggered.(in loops) Set to 0 to only send alerts if moving... 
    boolean pretend = false; // do not send text messages if true...
    
    //END USER CONFIG

    In the snippet above you can see the available configuration options. A brief Description follows:

    • alertPhone - The phone number to send SMS alerts to
    • alarmSensitivity - The sensitivity of the motion sensor. Needs to be between 1 and 100. HIgher = more sensitive to movement
    • alarmKeyA - The key to unlock the PICC. Must match key A in the newKey sketch!
    • N_UIDS - The number of provisioned PICCs (i.e. how many keys you have
    • keyUIDs - The UIDs of each provisioned key, one per line. Your key's UID must be here to disarm the alarm!
    • sector - which sector to use on the PICC may be any between 1 and 15. DO NOT use sector 0 as that contains the cardUID. Unless you are using the same PICC elsewhere, you can leave this alone.
    • tokenBlockData - This is a string of random bytes that serves as the 'secret' or in our authentication scheme. It must be the same in both this sketch and newKey for your keys to disarm the alarm!
    • settleTime - how long to allow the MPU readings to settle after arming. Set longer if you get false positive alerts right after arming.
    • messageDelay - The minimum allowed # of loops between text alerts. (each loop is around 0.2 sec). Keeps you from text-bombing yourself... Default of 1200 is around 4 minutes.
    • alertDelay - How long to wait before sending follow up location reports after the alarm is tripped. The default of 6000 is around 20 min. You can also set it to 0 to disable follow up messages and only send alerts when moving.
    • pretend - Don't send SMS, beep instead. (does a short-med-short beep if triggered) This option is allows you to prevent SMS from sending and just beep at you instead. It's useful if you need to adjust your sensitivity on the motion sensor.

    Note-> If you have problems uploading the sketch, unplug your FONA from the Nano Alarm and try without it. Also you will either have to connect the reset pin or manually reset the Arduino Pro Mini right when you upload the sketch. (See this- https://www.arduino.cc/en/Guide/ArduinoMini)

  • 3
    Step 3

    Vehicle Mounting

    Once it's set up, the last thing to do is install it on your bike. It can be hidden in the seat or for eBikes inside the battery box. (If your battery box is metal, you may need to futz with antenna and RFID reader placement to ensure you get a GPRS signal and GPS fix.)

    Wherever you install it, there should be a pocket or sleeve to hold the RFID card which is positioned near and parallel to the MRFC522 card reader. For aluminum battery boxes, you'll also have to think about antenna and RFID reader placement. Test your set-up regardless to verify GSM and GPS reception. If the location you install the alarm is not weatherproof, then you may want a small plastic case to enclose it. (Whereas if it's sewn into the seat of a bicycle then size will be paramount and you may just want to heat-shrink wrap the components. The vehicle will dictate the construction methods.)

    If you are installing into a motorcycle/ATV/snow machine, then you can use a 12VDC->5VDC converter to and have the vehicle recharge the alarm's battery. To do this simply connect the 5VDC out from the converter to the +5V (and Gnd) pin of the FONA.

    Another option if you're going to connect it to the vehicle's battery is to not use a battery at all for the FONA. The plus is that it's a simpler system. The minus is that if the thief disconnects the vehicle battery then the GPS quits phoning home. If you wish to power the FONA directly from the vehicle battery you need to use an adjustable step-down regulator and set the output voltage to 3.9VDC (instead of 5) then connect this output to the +Bat and Gnd of the FONA (or to the JST-PH). Do not connect the +5V of the FONA. (to anything)

    For eBike, connecting the Nano-Alarm to the bike's battery takes more planning. DC Adapters for vehicle mounting like the one below are available in 12VDC, 36VDC and 48VDC and offer an easy way to recharge the alarm. Output connections are the same as for other vehicles. But make sure that the converter is designed to handle the actual voltage of your system, not the 'on-paper' voltage of the battery. As an example, a 36V LiFePO4 battery has 12 cells with a fully charged voltage of 3.65V per cell. So our 36V battery is actually 43.8V when fully charged. A 48V LiFePO4 tops off at 58.4V!

    Also please test your DC->DC converter output to ensure that it is only delivering the desired voltage before plugging your alarm into it!**


    If you need to reduce the input voltage for your DC->DC converter just a few volts, you can connect some diodes in series with the DC->DC power supply. Below I used 1N5408 diodes which are rated for 3A and drop the voltage about a volt each. This gives the LM2596 board shown an extra 5V of headroom...

    You can use a larger/smaller battery than 2500mAh as well. Battery usage while armed is around 50-100mA assuming you have a decent GSM signal. (that's with the GPS on too!) So you can estimate how long a battery will last by dividing the battery capacity by 60. So for example a 5000mAh could stay armed for as long as 100 hours.) If it's eating a lot of battery, getting a better GPS and/or GSM antenna can help extend battery life dramatically simply by allowing the FONA to work less to amplify the radio signals it receives and transmits.

    **Note - a large number of the switching power supplies on fleaBay include counterfeit ICs. For any power supply you get online - Test it on your actual working voltage for several hours at least and ensure that it delivers only the stated voltage and does not get hot, smoke die, etc... Bad one's tend to short out within a few minutes, delivering the full input voltage to the 5V output. If that's going to happen then you want it to be before you plug your Nano-Alarm into it. (You can use a 12V incandescent light bulb or a sufficiently large resistor as a test load.)

View all 4 instructions

Enjoy this project?

Share

Discussions

thoughtscape wrote 09/06/2018 at 23:13 point

Awesome idea/project. Not sure if you are still monitoring this project but I'm just wondering if I swap out the close range RFID for something with about 1m range (so that it acts like a fob like in most cars), would that interfere with the programming/function of it?

Regards,

Mick

  Are you sure? yes | no

Durante wrote 09/30/2016 at 18:57 point

Hi, 
Great project!

But i am running into a problem uploading it.

I have this fault

'class Adafruit_FONA' has no member named 'getGPSlocation'


Any help would be great!

  Are you sure? yes | no

daniel foren wrote 05/12/2016 at 12:56 point

I LOVE your project! It so nice.

My plan is to integrate it into the led lamp, together with an accu wich is loaded by the dynamo.

But I allways search for cheaper variants. The problem is the Adafruit FONA 808 GPRS+GPS Breakout. I really need an cheaper but technical (by the main functions) same board. What do you think about this here: http://www.aliexpress.com/item/GSM-GPS-SIM808-Breakout-Board-SIM808-core-board-2-in-1-Quad-band-GSM-GPRS-Module/32435607442.html
By the way bluetooth could be great alternative authentification or?
If the board is not so good, could please tell us wich of this could be possible:
http://goo.gl/ptbJmc

I would be very thankfull!

Greetings by CheapMonk

  Are you sure? yes | no

mohammed.atta_elgammal wrote 04/03/2016 at 14:11 point

I really like your project. Well done. I am looking for the Adafruit FONA 808 GPRS+GPS Breakout, but it is out-of-stock at https://goo.gl/9NMeUq for a while now. Can you recommend me an alternative or tell me where you bought yours?

  Are you sure? yes | no

Scott McKinley wrote 02/14/2016 at 22:36 point

Hi - I don't know if this is poor etiquette on hackaday or not, but would you consider consulting on the production of a similarly spec'ed device, or even producing it?

  Are you sure? yes | no

guerrero92337 wrote 01/16/2016 at 03:42 point

Hello,

I am working on a similar project and i was wondering how you were to pass the gps coordinates to Google Maps and capture the url with the data?

thanks

  Are you sure? yes | no

Alpha Charlie wrote 01/16/2016 at 04:20 point

look at the bike alarm arduino sketch on github. The SendAlert() function is between lines 500(ish) and 600(ish) and parses the GPS data from the FONA into a format google maps can consume.

  Are you sure? yes | no

guerrero92337 wrote 01/22/2016 at 02:01 point

Thank you! That worked.

Another question .. we are using the same MCU and FONA that you are, but we are unable to send messages. Our program sends messages when using an Arduino Uno but not with the Pro Mini 3.3V. Did you have to do anything special to send messages with the Pro Mini? 

  Are you sure? yes | no

Alpha Charlie wrote 07/01/2015 at 16:54 point

@shreakergot mine from Adafruit. I don't know of another seller. (Nor of another cell phone that small with GPS) But luckily, they restock things pretty fast. 

[EDIT] eBay does have some sellers with SIM808 based boards for sale, but all of them are in China, so you're rolling the dice... (You will get much better support from Adafruit and the prices are around the same.)[/edit]

  Are you sure? yes | no

shreaker wrote 07/01/2015 at 18:07 point

Thank you for your fast reply.

  Are you sure? yes | no

shreaker wrote 07/01/2015 at 10:23 point

Hi,

I really like your project. Well done. I am looking for the Adafruit FONA 808 GPRS+GPS Breakout, but it is out-of-stock at adafruit.com for a while now. Can you recommend me an alternative or tell me where you bought yours?

Thanks.

Michael

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates