Never Lose Your Phone Again

2,034

25

8

Introduction: Never Lose Your Phone Again

Who hasn't ever left his phone on a spot and realised they had lost it too late? Anonimoconhache present you the solution: Don't Lose Me.

With this amazing gadget you will never lose your phone again. Whenever you are too far away from your phone Don't Lose Me will start to blink and whistle, as well as your phone will reproduce an annoying sound (or a song it is up to you).

Supplies

  • Materials:
    • 1 Arduino Nano
    • 1 HC05 Bt module
    • 1 Buzzer
    • 1 5mm diameter led
    • 1 push button
    • 1 push button NC
    • 0,5 mm diameter springs
    • Copper thread
    • 2 3mm diameter screws
    • PLA
  • Tools:
    • 3d Printer
    • Soldering iron
    • Computer
    • Glue

Step 1: Idea

Between your phone and the Don't Lose Me a Bluetooth connection is established. Your phone is constantly sending data to the Arduino. When the connection is broken it can mean 2 things: whether you are too far away from your phone or that you have forced a breakdown on the connection (pushing the red button). In both cases the result is the same. Arduino does not receive data and start to blink and whistle, your phone detects that the data that it is is sending has no receiver so it will reproduce an alarm.

I am leaving 2 flow chart. The left one correspond to the Arduino code and the right one to the app code

Step 2: DEP to Version 1

I have been working in these project up to 4 months and I wanted to show you how it started so you can appreciate the development of the project.

The problem with the version 1 was that apart from being too difficult to assemble and messy, the battery holder didn't work sometimes.

Step 3: Configurating the HC05

Let's get started making a Don't Lose Me.

The first thing you will have to do is configure the HC-05. Upload this code to the Arduino Nano with the bt module connected (look at the image of the circuit below). It is important that meanwhile you are uploading the code, you push the button on the module.

Then enter the serial monitor and configure the HC05:

  • AT+NAME= Don't Lose Me //Give your module a name
  • AT+ROLE= 0 //1=master/0=slave
  • AT+PSWD= 1234 //password to your module

Step 4: Code of Arduino

Step 5: Android Studio App

I developed an app with android studio, I am leaving it below. I am also leaving all the code I used you in case you want to make any change.

In case you want to program it by yourself, remember you must have a background image.

If you download the app, you won't have to do nothing like this :)

Graphics:

  • Bt Disnable:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="4dp"<br>        android:color="#FFF" /><br>    <corners android:radius="10dp" /><br><br><br>    <solid android:color="#000" /><br></shape>
  • Bt Enable:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="4dp"<br>        android:color="#000" /><br>    <corners android:radius="10dp" /><br><br><br>    <solid android:color="#FFF" /><br></shape>
  • Conected:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="4dp"<br>        android:color="#649D50 " /><br>    <corners android:radius="10dp" /><br><br><br>    <solid android:color="#18D708" /><br></shape>
  • Disconected:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="4dp"<br>        android:color="#9F6C6C" /><br>    <corners android:radius="10dp" /><br><br><br>    <solid android:color="#EC1313"<br>        /><br></shape>
  • List View:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="1dp"<br>        android:color="#000" /><br>    <corners android:radius="10dp" /><br><br>    <solid android:color="#FFF" /><br></shape>
  • Stop:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="5dp"<br>        android:color="#C11814" /><br>    <corners android:radius="100dp" /><br><br>    <padding<br>        android:bottom="20dp"<br>        android:left="20dp"<br>        android:right="20dp"<br>        android:top="20dp" /><br><br>    <solid android:color="#ECEA0A" /><br></shape>
  • Welcome:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><shape xmlns:android="http://schemas.android.com/apk/res/android"><br>    <stroke<br>        android:width="4dp"<br>        android:color="#58A8A1" /><br>    <corners android:radius="10dp" /><br><br><br>    <solid android:color="#1180C2"<br>        /><br></shape>
  • Activity Main:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br>    xmlns:app="http://schemas.android.com/apk/res-auto"<br>    xmlns:tools="http://schemas.android.com/tools"<br>    android:layout_width="wrap_content"<br>    android:layout_height="wrap_content"<br>    android:orientation="vertical"<br>    tools:context=".MainActivity"<br>    android:background="#CC85D5FB"<br>    ><br><br>    <ListView<br>        android:id="@android:id/list"<br>        android:layout_width="match_parent"<br>        android:layout_height="164dp"<br>        android:layout_above="@+id/restart"<br>        android:layout_below="@+id/text"<br>        android:layout_marginTop="30dp"<br>        android:layout_marginBottom="14dp"<br>        android:gravity="center"<br>        android:layout_margin="10dp"<br>        android:background="@drawable/listview"<br>        android:divider="@android:color/black"<br>        android:dividerHeight="1dp"<br>        android:fontFamily="casual"<br>        /><br><br>    <TextView<br>        android:id="@+id/text"<br>        android:layout_width="match_parent"<br>        android:layout_height="83dp"<br>        android:layout_below="@+id/btsituation"<br>        android:layout_alignParentEnd="true"<br>        android:layout_marginLeft="10dp"<br>        android:layout_marginTop="10dp"<br>        android:layout_marginRight="10dp"<br>        android:layout_marginBottom="20dp"<br>        android:background="@drawable/welcome"<br>        android:fontFamily="casual"<br>        android:gravity="center"<br>        android:textColor="#FFF"<br>        android:text="WELCOME"<br>        android:textSize="50dp"<br>        android:textStyle="bold" /><br><br>    <Button<br>        android:id="@+id/restart"<br>        android:layout_width="match_parent"<br>        android:layout_height="184dp"<br>        android:layout_above="@+id/author"<br>        android:layout_marginTop="15dp"<br>        android:layout_marginBottom="20dp"<br>        android:layout_marginLeft="10dp"<br>        android:layout_marginRight="10dp"<br>        android:gravity="center"<br>        android:text="STOP"<br>        android:textSize="100dp"<br>        android:fontFamily="casual"<br>        android:textStyle="bold"<br>        android:textColor="#FD3710"<br>        android:background="@drawable/stop"<br>        /><br><br>    <TextView<br>        android:id="@+id/title"<br>        android:layout_width="match_parent"<br>        android:layout_height="wrap_content"<br>        android:layout_marginTop="0dp"<br>        android:layout_marginBottom="5dp"<br>        android:gravity="center"<br>        android:textSize="15dp"<br>        android:fontFamily="casual"<br>        android:textStyle="bold"<br>        android:text="DO NOT LOSE YOUR PHONE"<br>        android:background="#FFF"<br>        android:alpha="0.5"<br>        android:textColor="#0A3988"<br>        /><br><br>    <TextView<br>        android:id="@+id/btsituation"<br>        android:layout_width="wrap_content"<br>        android:layout_height="65dp"<br>        android:layout_below="@+id/title"<br>        android:layout_alignParentStart="true"<br>        android:layout_alignParentEnd="true"<br>        android:layout_marginStart="74dp"<br>        android:layout_marginTop="13dp"<br>        android:layout_marginEnd="74dp"<br>        android:layout_marginBottom="10dp"<br>        android:background="@drawable/bt_enable"<br>        android:fontFamily="casual"<br>        android:gravity="center"<br>        android:text="BT ENABLE"<br>        android:textColor="#000"<br>        android:textSize="35dp"<br>        android:textStyle="bold" /><br><br>    <TextView<br>        android:id="@+id/author"<br>        android:layout_width="match_parent"<br>        android:layout_height="30dp"<br>        android:layout_alignParentBottom="true"<br>        android:layout_marginTop="8dp"<br>        android:layout_marginBottom="0dp"<br>        android:gravity="center"<br>        android:fontFamily="casual"<br>        android:textStyle="bold"<br>        android:text="ANONIMO CON HACHE"<br>        android:background="#FFF"<br>        android:textColor="#0A3988"<br>        android:alpha="0.5"/><br></RelativeLayout>

Android Manifest:

<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;"><?xml version="1.0" encoding="utf-8"?><br><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br>    package="com.anonimoconhache.dontloseme"><br><uses-permission android:name="android.permission.BLUETOOTH"/><br>    <application<br>        android:allowBackup="true"<br>        android:icon="@mipmap/ic_launcher"<br>        android:label="@string/app_name"<br>        android:roundIcon="@mipmap/ic_launcher_round"<br>        android:supportsRtl="true"<br>        android:theme="@style/AppTheme"><br>        <activity android:name=".MainActivity"><br>            <intent-filter><br>                <action android:name="android.intent.action.MAIN" /><br><br>                <category android:name="android.intent.category.LAUNCHER" /><br>            </intent-filter><br>        </activity><br><br>        <service android:name=".audio" /><br>    </application><br><br></manifest>

Main Activity:

<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9,0pt;">package com.anonimoconhache.dontloseme;<br><br>import android.annotation.SuppressLint;<br>import android.app.AlarmManager;<br>import android.app.ListActivity;<br><br>import android.app.PendingIntent;<br>import android.bluetooth.BluetoothAdapter;<br>import android.bluetooth.BluetoothDevice;<br>import android.bluetooth.BluetoothSocket;<br><br>import android.content.Context;<br>import android.content.Intent;<br>import android.view.View;<br>import android.graphics.Color;<br>import android.media.MediaPlayer;<br>import android.nfc.Tag;<br>import android.os.AsyncTask;<br>import android.os.Bundle;<br><br>import android.util.Log;<br>import android.view.View;<br>import android.widget.ArrayAdapter;<br>import android.widget.Button;<br><br>import android.widget.ListView;<br>import android.widget.Switch;<br>import android.widget.TextView;<br>import android.widget.Toast;<br><br>import androidx.annotation.NonNull;<br>import androidx.annotation.Nullable;<br><br>import java.io.IOException;<br>import java.io.OutputStream;<br>import java.util.ArrayList;<br><br>import java.util.Set;<br>import java.util.UUID;<br><br>public class MainActivity extends ListActivity{<br>    private ArrayAdapter<String> mArrayAdapter;<br>    private BluetoothAdapter mBluetoothAdapter;<br>    private BluetoothSocket btSocket;<br>    private ArrayList<BluetoothDevice> btDeviceArray = new ArrayList<BluetoothDevice>();<br>    private ConnectAsyncTask connectAsyncTask;<br>    private BluetoothAdapter mBTAdapter;<br>    private Context thiscontext=this;<br>    private MediaPlayer mediaPlayer;<br>    private Button restar;<br><br>    static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");<br><br>    TextView text, btsituation, title;<br>    Intent HabilitarBT;<br>    int requestCodeBT;<br>    int stop; // variable<br>    int music;// variable<br>    int musicon;<br><br>    @Override<br>    protected void onActivityResult(int requestCode, int resultCode, Intent data) { // IF : PEDIR PERMISO DE BT<br>        if(requestCode==requestCodeBT){<br>            if(resultCode==RESULT_OK){ //SI SE ACEPTA BT<br>                Toast.makeText(thiscontext, "BT habilitado", Toast.LENGTH_SHORT).show();<br>                reset();<br>            }<br>            else{ // SI NO SE ACEPTA BT<br>                Toast.makeText(this, "Habilita bluetooth para abrir la app", Toast.LENGTH_SHORT).show();<br>                finish();<br>            }<br>        }<br>    }<br><br>    @Override<br>    protected void onCreate(final Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);<br><br>        mBTAdapter = BluetoothAdapter.getDefaultAdapter();<br>        mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);<br>        setListAdapter(mArrayAdapter);<br>        connectAsyncTask = new ConnectAsyncTask();<br>        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();<br>        requestCodeBT=1;<br>        music=0;<br>        stop=0;<br>        musicon=0;<br><br>        text = (TextView)findViewById(R.id.text);<br>        restar = (Button)findViewById(R.id.restart);<br>        btsituation= (TextView) findViewById(R.id.btsituation);<br>        title=(TextView)findViewById(R.id.title);<br><br>        bluetoothrequest();<br>        play();<br><br>        sto();<br><br>        Set<BluetoothDevice> pariedDevices = mBluetoothAdapter.getBondedDevices();<br>        if (pariedDevices.size() > 0) { // SI SE ENCUENTRAN DISPOSITIVOS BT<br>            for (BluetoothDevice device : pariedDevices) {<br>                mArrayAdapter.add(device.getName() + "\n" + device.getAddress());<br>                btDeviceArray.add(device);<br>            }<br>        }<br>    }<br>    private void sto() { // SI SE PULSA STOP<br>        restar.setOnClickListener(new View.OnClickListener() { //SI PULSO STOP<br>            @Override<br>            public void onClick(View view) { //SI PULSAN STOP<br>                if(stop==1) {<br>                    mediaPlayer.stop();<br>                    finish();<br>                    startActivity(getIntent());<br>                }<br>                else if (stop==0){<br>                    Toast.makeText(thiscontext, "No music on", Toast.LENGTH_SHORT).show();<br><br>                }<br>            }<br>        });<br>    }<br><br>    public void stomusic(){<br>        mediaPlayer.stop();<br>    }<br><br>    private void bluetoothrequest() {<br>        if (mBluetoothAdapter == null) { //SI NO HAY ADAPTADOR BT<br>            Toast.makeText(this, "Tu dispositivo no acepta bluetooth", Toast.LENGTH_SHORT).show();<br>            btsituation.setText("Tu dispositivo no acepta bluetooth");<br>            btsituation.setTextColor(Color.RED);<br>            finish();<br>        } else {<br>            if (!mBluetoothAdapter.isEnabled()) { //SI NO ESTA BT HABILITADO<br>                HabilitarBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);<br>                startActivityForResult(HabilitarBT, requestCodeBT);<br>                btsituation.setText("BT DISABLE");<br>                btsituation.setTextColor(Color.BLACK);<br>                btsituation.setBackgroundResource(R.drawable.bt_enable);<br>            } else {  // SI SE ACEPTA<br>                btsituation.setText("BT ENABLE");<br>                btsituation.setTextColor(Color.WHITE);<br>                btsituation.setBackgroundResource(R.drawable.bt_disable);<br>            }<br>        }<br>    }<br><br>    @Override<br>    protected void onListItemClick(ListView l, View v, int position, long id) { // SI SE CLICA EN ALGUN ELEMENTO DE LA LISTA<br>        if(music==0){<br>            if(mBluetoothAdapter.isEnabled()){ //SI ESTÁ ACTIVADO BT<br>                BluetoothDevice device = btDeviceArray.get(position);<br>                connectAsyncTask.execute(device);<br>            }<br>            else {<br>                bluetoothrequest();<br>            }<br>        }<br>        else if(music==1){ // SI NO ESTÁ ACTIVADO BT<br>            Toast.makeText(this, "Pulsa STOP", Toast.LENGTH_SHORT).show();<br>        }<br>    }<br><br>    private class ConnectAsyncTask extends AsyncTask<BluetoothDevice, Integer, BluetoothSocket>{ // CONECTARSE BT<br>        private BluetoothSocket mmSocket;<br>        private BluetoothDevice mmDevice;<br>        @SuppressLint("WrongThread")<br>        @Override<br>        protected BluetoothSocket doInBackground(BluetoothDevice... device) {<br>            mmDevice = device[0];<br>            try {<br>                String mmUUID = "00001101-0000-1000-8000-00805F9B34FB";<br>                mmSocket = mmDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString(mmUUID));<br>                try {<br>                    mmSocket.connect();<br>                    text.setText("CONECTED");<br>                    text.setTextColor(Color.parseColor("#FFFFFF"));<br>                    text.setBackgroundResource(R.drawable.conected);<br>                    stomusic();<br>                }<br>                catch (Exception e){ }<br>            }<br>            catch (Exception e) {}<br>            return mmSocket;<br>        }<br><br>        @Override<br>        protected void onPostExecute(BluetoothSocket result) {<br>            btSocket = result;<br>            OutputStream mmOutStream = null;<br>            try {<br>                if (btSocket.isConnected()) { //MIENTRAS ESTE CONECTADO A ALGUN DISPOSITIVO BT<br>                    while (btSocket.isConnected()) {<br>                        mmOutStream = btSocket.getOutputStream();<br>                        mmOutStream.write(new String("1").getBytes()); //MANDAR DATO<br>                        music();<br>                    }<br>                }<br>            }<br>            catch (IOException e) { // CUANDO NO ESTE CONECTADO A UN DISPOSITIVO BT<br>                Toast.makeText(getBaseContext(), "Do not lose me", Toast.LENGTH_LONG).show();<br>                text.setText("DISCONECTED");<br>                text.setTextColor(Color.parseColor("#FFFFFF"));<br>                text.setBackgroundResource(R.drawable.disconected);<br>                play();<br><br>            }<br>        }<br>    }<br><br>    private void reset() {<br>        stomusic();<br>        finish();<br>        startActivity(getIntent());<br><br>    }<br>    public void play(){ // SONIDO EN LOOP<br>        mediaPlayer= MediaPlayer.create(this, R.raw.song);<br>        mediaPlayer.setLooping(true);<br>        mediaPlayer.start();<br>    }<br>    public void musicasonando(){<br>        musicon=1;<br><br>    }<br>public void music(){<br>        music=1;<br>    stop=1;<br><br>}<br>}<br>

Step 6: Add the Music

Again, if you download, you don't have to do nothing.

Download the song/ sound you want and add it to the raw carpet as shown in the image. I am leaving the alarm sound I used in the video.

Step 7: Circuit Diagram

Step 8: Designing & Printing

I used 360 fusion to design the device.

Apart from the .stl files I am leaving you a link to download it from Thingiverse:

https://www.thingiverse.com/thing:4795446

Attachments

Step 9: Soldering

This may be the most difficult step of your making, so be patient and try not to freak out.

Step 10: Battery Holder

The spring must go on the negative pole of the battery.

Step 11: Done

That it is it!

Thanks for reading, I hope you have enjoyed reading the same I enjoyed doing the first but not last Don't Lose Me.

These have been the most complex project I have ever done, so please don't forget to give me a like if you enjoyed it.

:)

Microcontroller Contest

Participated in the
Microcontroller Contest

2 People Made This Project!

Recommendations

  • Space Contest

    Space Contest
  • Home Cooked Speed Challenge

    Home Cooked Speed Challenge
  • Pumpkins & Gourds Speed Challenge

    Pumpkins & Gourds Speed Challenge

8 Comments

0
chchu
chchu

Question 6 months ago

Is there a way to change the music in the app?

0
secajanle
secajanle

Answer 6 months ago

Yes of course, but you will have to modify the app using android studio. It is explained it the step 6.
Thank you so much for making it and posting it. Muchas Gracias :)

0
chchu
chchu

6 months ago



I made a few changes but it worked!!!

0
MuhammedOruc
MuhammedOruc

6 months ago

What happens if you lose the remote? 🤣

Excellent project by the way

0
anonimoconhache
anonimoconhache

Reply 6 months ago

If you lose the remote, your phone will reproduce the alarm and the remote will start to blink and whistle (if the sound is on)
Thanks :)

0
MuhammedOruc
MuhammedOruc

Reply 6 months ago

Great project

0
Darwin43
Darwin43

7 months ago

That IS amazing!!!