Project showcase
Phone Call Indicator cum Panic Switch

Phone Call Indicator cum Panic Switch © LGPL

Bluetooth and Android-based call indicator with panic switch for calling a preset number.

  • 761 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

My father who is quite advanced in his years has issues with handling smartphones. In addition he has very limited hearing. So he is not able to figure out if the phone is ringing or not. I felt if there was a visual audio indicator once a call was received it would help him. While working on the project I also could modify the initial idea to include calling/messaging a preset number using the same switch which could be used as a panic switch if required.

I initially started with an arduino pro mini, HC05 Bluetooth Module etc. using a breadboard with LED and switches. Later I decided to move everything to PCBs designed created by me end to end and also create an acrylic enclosure.

Since I made everything myself - PCB, enclosure etc. I think it would serve as a good guide for individuals who want to try out a project end to end. It would save them efforts of finding the right items and maybe they would come up with better ways of doing things which are always welcome.

I will break this project into the smaller steps which would make it easier to follow and reproduce:

  • High level view
  • Android Bluetooth Communication
  • Arduino Serial Communication
  • Breadboard Assembly
  • Moving components to PCB
  • Enclosure (Acrylic)

High Level View:

Actually the basic principle is quite simple. A communication channel(serial communication) is established between the android device (the phone) and the Bluetooth module(which is connected to the arduino) via an android app. When a call is received by the android phone a particular text is transmitted to the BT device which is read by the arduino. Basis the message the arduino is programmed to execute certain steps. In this case sound the buzzer. A manual reset switch is also given to restore normalcy.

Red LED with Buzzer active when call received

In the reverse operation (panic switch mode) - when the switch is pressed the arduino transmits a given character sequence to the android app. The app on receiving the sequence calls a fixed number already stored in the app.

Android Phone calls a preset number when switch is pressed

Android Bluetooth Communication

There is this excellent article on Android - Arduino communication by Brian Wirsing which can be found here. I have used the code suggested extensively. Another series of tutorials, which focus more on Android to Android Bluetooth Communication is available as a four part tutorial on you tube. The link to the first part is here.

It is also important to understand the concept of threads and handlers in android. Essentially all code related activities that hold up the user-interface must be put in a separate thread where they can do their work in the background. A handler on the other hand is used to ferry messages between different threads and also interact with the main user interface.

For HC-05 to communicate with an android phone it is necessary that the two be paired and that the HC-05 be the only device that is paired. If your phone has multiple devices paired then unpair all other devices.

Communication between two devices involves :

  • setting up a communication path (a.k.a interface)
  • Transmitting from one device and receiving in second and vice-versa.

In this project the communication path is set between the Android and the bluetooth device (HC-05 module) . There is also a serial interface between the HC-05 and the Arduino. So in essence the transmission from Android is received by the arduino via the HC-05.

For Android to communicate with the HC-05 the steps involved are:

  • Get the BT Adapter - this will also check if blue tooth is supported or not. The getDefaultAdapter() method will return an object of the type BTAdapter if available and supported.

Line 83 of MainActivity.java checks if the adapter is available:

btAdapter = BluetoothAdapter.getDefaultAdapter();
  • Get the BT Device - The object BTAdapter has a property getBondedDevices() which will list out all the devices paired with the android phone . If successfully paired our HC-05 module is the first device (remember not to pair any other devices).

Lines 191 and 192 of MainActivity.java return the BTDevice:

btDevice = (BluetoothDevice) (btAdapter.getBondedDevices().toArray())[0];
               btAdapter.getRemoteDevice(String.valueOf(btDevice));
  • Open a BT Socket - Once the BTDevice object has been created and the BTAdapter set to the address of the remote device(in our case the HC-05 module), a BT socket is opened between the two (android and BT device). To create a socket we require the UUID () of the remote device.
  • HC-05 is a BT device of type SPP (Serial Port Profile) and has a pre-fixed UUID -"00001101-0000-1000-8000-00805F9B34FB". Line 54 of MainActivity.java converts this string to type UUID :
private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

public void run() {
           try {
               mmSocket = btDevice.createInsecureRfcommSocketToServiceRecord(MY_UUID);
               mmSocket.connect();
           } catch (IOException e) {
               cont = false;
               Message message = Message.obtain();
               message.what = SOCKET_NOT_CONNECTED;
               handler.sendMessage(message);
               e.printStackTrace();
           }
           if ((mmSocket != null) && (cont)) {
               Message message = Message.obtain();
               message.what = SOCKET_OPENED;
               handler.sendMessage(message);
               socket = mmSocket;
           }
       }
   }
  • Read and Write using the BT Socket

Code

MainActivity.javaJava
This is the main activity for the android app (called myapplication)
package com.ratnadeep.myapplication;

import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;


public class MainActivity extends AppCompatActivity {
    Button btnSend, BtnArm, BtnReset;
    ToggleButton tglBtnConnect, tglBtnTest;
    TextView tvStatus, ETReceivedTxt;
    EditText etMsgBox;
    BluetoothAdapter btAdapter;
    BluetoothDevice btDevice;
    public BluetoothSocket socket;
    Set<BluetoothDevice> mPairedDevices;
    OutputStream outputStream;
    InputStream inputStream;
    SendRecieve sendRecieve;
    private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
    private final int MESSAGE_SENT = 10;
    private final int BLUE_TOOTH_OFF = 11;
    private final int MESSAGE_RECEIVED = 12;
    private final int SOCKET_NOT_CONNECTED = 13;
    private final int SOCKET_OPENED = 1;
    public static boolean cont = false;
    int MY_APP_PERMISSION_CALL_PHONE;
    Boolean canCall = false; // cannot call without permissions
    SharedPreferences sharedPreferences ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewbyIDs();
        RequestPermission();



        if (ContextCompat.checkSelfPermission(MainActivity.this,
                Manifest.permission.READ_PHONE_STATE)!= PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this,
                    new String[] {Manifest.permission.READ_PHONE_STATE},1);
        }

        tglBtnConnect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    tvStatus.setText("Connecting...");
                    btAdapter = BluetoothAdapter.getDefaultAdapter();
                    if (btAdapter != null) {
                        Connect myconnect = new Connect();
                        if (cont) {
                            myconnect.start();
                        }
                    } else {
                        Toast.makeText(MainActivity.this, "Check if Bluetooth is on",
                                Toast.LENGTH_SHORT).show();
                        //tglBtnConnect.setChecked(false);
                    }

                }
                else {
                    btAdapter = null;
                    socket = null;
                    cont = false;
                    tvStatus.setText("Remote Device Disconnected");
                    ETReceivedTxt.setText("");
                    BtnArm.setBackgroundResource(android.R.drawable.btn_default);
                }

            }
        });
        tglBtnTest.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(cont){
                        sendRecieve.SendMessage("P");
                    }
                    else{
                        tvStatus.setText("Caannot Continue, Check status");
                        tglBtnTest.setChecked(false);

                    }
                }
                else {
                    if(cont) {
                        sendRecieve.SendMessage("R");

                    }
                }
            }
        });





        BtnArm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                TelephonyManager tmgr =
                        (TelephonyManager) MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
                if (socket != null) {

                    //Create new Receiver and register it
                    myReceiver myNewReceiver = new myReceiver();
                    IntentFilter filter = new IntentFilter();
                    filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
                    registerReceiver(myNewReceiver,filter);

                    BtnArm.setBackgroundColor(Color.RED);
                } else {
                    Toast.makeText(MainActivity.this, "No Socket",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        BtnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String strMsg = "R" + "\n";
                //SendRecieve sendRecieve = new SendRecieve(socket);
                sendRecieve.SendMessage(strMsg);


            }
        });


        sharedPreferences = this.getSharedPreferences(getString(R.string.file_name),MODE_PRIVATE);
    }



    private void findViewbyIDs() {
        tglBtnConnect = (ToggleButton) findViewById(R.id.btnCnnct);
        btnSend = (Button) findViewById(R.id.btnSend);
        tvStatus = (TextView) findViewById(R.id.tvStatus);
       // etMsgBox = (EditText) findViewById(R.id.MsgBox);
        BtnArm = (Button) findViewById(R.id.btnArm);
        tglBtnTest = (ToggleButton)findViewById(R.id.tglTestReset);
        BtnReset = (Button) findViewById(R.id.btnReset);
        ETReceivedTxt = (TextView) findViewById(R.id.etReceivedText);

    }

    private class Connect extends Thread {
        private BluetoothSocket mmSocket;

        public Connect() {
            btAdapter = BluetoothAdapter.getDefaultAdapter();
            if (btAdapter.isEnabled()) {
                btDevice = (BluetoothDevice) (btAdapter.getBondedDevices().toArray())[0];
                btAdapter.getRemoteDevice(String.valueOf(btDevice));
                cont = true;
            } else {
                Message message = Message.obtain();
                message.what = BLUE_TOOTH_OFF;
                handler.sendMessage(message);

            }

        }

        public void run() {
            try {
                mmSocket = btDevice.createInsecureRfcommSocketToServiceRecord(MY_UUID);
                mmSocket.connect();
            } catch (IOException e) {
                cont = false;
                Message message = Message.obtain();
                message.what = SOCKET_NOT_CONNECTED;
                handler.sendMessage(message);
                e.printStackTrace();
            }
            if ((mmSocket != null) && (cont)) {
                Message message = Message.obtain();
                message.what = SOCKET_OPENED;
                handler.sendMessage(message);
                socket = mmSocket;
            }
        }
    }

    public class SendRecieve extends Thread {

        private OutputStream outputStream;
        private InputStream inputStream;
        int inByte;
        byte[] buffer = new byte[512];
        byte[] newBuffer = new byte[1024];
        int bytes, availableBytes;
        String bufferMessage = "";
        char Ascii;

        public SendRecieve(BluetoothSocket mySocket) {
            try {
                outputStream = mySocket.getOutputStream();
                inputStream = mySocket.getInputStream();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        public void run() {
            bytes = 0;

            while (true) {
                try {

                    //bytes = inputStream.read(buffer,0,buffer.length);
                    inByte = inputStream.read();
                    if (inByte != -1) Ascii = (char) inByte;
                    if ((inByte != 42) && (inByte != -1)) {
                        bufferMessage += (char) inByte;

                        Log.e("Char REceived", String.valueOf((char) inByte));
                    } else {
                        handler.obtainMessage(MESSAGE_RECEIVED, bufferMessage.length(), -1, bufferMessage).sendToTarget();
                        bufferMessage = "";

                    }

                    //Log.e("REceived Buffer Length",String.valueOf(bytes));

                } catch (IOException e) {
                    e.printStackTrace();
                }

            }


        }

        public void SendMessage(String msg) {
            try {
                outputStream.write(msg.getBytes());
                Message message = Message.obtain();
                message.what = MESSAGE_SENT;
                handler.sendMessage(message);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



    public class myReceiver extends BroadcastReceiver{


        public myReceiver(){


        }

        @Override
        public void onReceive(Context context, Intent intent) {

        try {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            if (state.equals("RINGING")) {
                Toast.makeText(context, state, Toast.LENGTH_SHORT).show();
                sendRecieve.SendMessage("P" + "\n");
            }
        } catch (Exception e) {
            Log.e("Error", e.toString());
        }
    }



        }




    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case (SOCKET_OPENED):
                    tvStatus.setText("Socket is open");
                    sendRecieve = new SendRecieve(socket);
                    sendRecieve.start();
                    break;
                case (MESSAGE_SENT):
                    Toast.makeText(MainActivity.this, "Message Sent",
                            Toast.LENGTH_SHORT).show();
//                    etMsgBox.setText("");
                    break;
                case (BLUE_TOOTH_OFF):
                    Toast.makeText(MainActivity.this, "No Bluetooth",
                            Toast.LENGTH_SHORT).show();
                    tglBtnConnect.setChecked(false);
                    tvStatus.setText("Bluetooth not connected");
                    break;
                case (MESSAGE_RECEIVED):
                    //byte[] readBuff = (byte[])msg.obj;
                    String readBuff = (String) msg.obj;
                    if (readBuff.equals("Call")) {

                        CallNumber(sharedPreferences.getString("myNumber",""));
                    }
                    if (readBuff.equals("Reset")){
                        tglBtnTest.setChecked(false);
                        tvStatus.setText("Reset from Device");
                    }
                    ETReceivedTxt.setText(readBuff);

                    break;
                case (SOCKET_NOT_CONNECTED):
                    tvStatus.setText("Socket not Connected. Check Remote Device");
                    tglBtnConnect.setChecked(false);


            }
            return false;
        }
    });

    public void CallNumber(String varNumber) {
       //
        // Toast.makeText(this,varNumber,Toast.LENGTH_SHORT).show();

        if (canCall) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:"+ varNumber));
            try {
                this.startActivity(callIntent);
            } catch (SecurityException e) {
                Toast.makeText(MainActivity.this,
                       "Check Permissions", Toast.LENGTH_SHORT).show();
            }
            catch (Exception e){
                Log.d ("CallNumber",e.toString());
            }

        }

    }

    public void RequestPermission() {
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) !=
                PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CALL_PHONE},
                    MY_APP_PERMISSION_CALL_PHONE);
        } else { // if permission already exists

            canCall = true;
        }


    }
    @Override
    public boolean onCreateOptionsMenu (Menu menu){

        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.main_menu,menu);


        return true;

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem){
        Intent intent;

        switch(menuItem.getItemId()){

            case(R.id.AddPhone):
                intent = new Intent(this,AddPhone.class);
                startActivity(intent);
                break;
            case(R.id.About):
                intent = new Intent(this,About.class);
                startActivity(intent);
                break;
            case(R.id.CloseApp):
                ///this.finish();
                System.exit(0);
                break;

        }

        return true;
    }
}
App ManifestXML
This is the manifest file for the application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ratnadeep.myapplication">

    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />



    <application
        android:allowBackup="true"
        android:icon="@mipmap/rjoshi_ic_launcher1"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/rjoshi_ic_launcher1"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".About"></activity>
        <activity
            android:name=".AddPhone"
            android:label="@string/title_activity_add_phone"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".MainActivity"
            android:launchMode="singleTop" android:configChanges="orientation|screenSize">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>
AddPhone.javaJava
This is an activity called by MainActivity to add a phone number
package com.ratnadeep.myapplication;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddPhone extends AppCompatActivity {
    EditText PhoneNo;
    //PreferenceEditor preferenceEditor = new PreferenceEditor(this);
    Button SaveBtn,CancelBtn;
    SharedPreferences sharedPreferences;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_phone);
        PhoneNo = (EditText)findViewById(R.id.etPhoneNo);
        SaveBtn = (Button)findViewById(R.id.btnSave);
        CancelBtn = (Button)findViewById(R.id.btnCancel);
        sharedPreferences = this.getSharedPreferences(getString(R.string.file_name),MODE_PRIVATE);

        PhoneNo.setText(sharedPreferences.getString("myNumber",""));
        SaveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString("myNumber",PhoneNo.getText().toString());
                editor.commit();
                finish();
            }
        });
        CancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}
activity_main.xmlXML
layout for the MainActivity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tvStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Not Connected"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ToggleButton
        android:id="@+id/btnCnnct"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:textOff="Connect"
        android:textOn="Disconnect"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="32dp"
        android:text="Test"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btnCnnct" />

    <!--<EditText
        android:id="@+id/MsgBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btnCnnct" />-->

    <Button
        android:id="@+id/btnArm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Arm"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnReset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="32dp"
        android:text="Reset"
        app:layout_constraintStart_toEndOf="@+id/btnSend"
        app:layout_constraintTop_toBottomOf="@+id/btnArm" />

    <TextView
        android:id="@+id/etReceivedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvStatus" />

    <ToggleButton
        android:id="@+id/tglTestReset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:textOff="Test"
        android:textOn="Reset"
        app:layout_constraintStart_toEndOf="@+id/btnCnnct"
        app:layout_constraintTop_toTopOf="parent" />

    <!--<ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="104dp"
        android:layout_marginLeft="104dp"
        android:layout_marginTop="8dp"
        android:text="ToggleButton"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btnCnnct" />-->

</android.support.constraint.ConstraintLayout>
HC05_04_withBuzzer_OneSwitch.inoArduino
Arduino Code for the project
#include <SoftwareSerial.h>
const int RX_PIN = 2;
const int TX_PIN = 3;
const int BuzzerPin = 8;
const int ManualReset = 11;
const int CallPin = 10;
SoftwareSerial mySerial(RX_PIN,TX_PIN);
char CommandChar;
String message;
int Lock;

void setup() {
  // put your setup code here, to run once:

  mySerial.begin(9600);
  Serial.begin(9600);
  pinMode(13,OUTPUT); //Red LED incoming Call
  pinMode(12,OUTPUT); //Yellow LED Normal
  pinMode(BuzzerPin,OUTPUT);
  digitalWrite(BuzzerPin,LOW);
  pinMode(ManualReset,INPUT);
  pinMode(CallPin,INPUT);
  //                                                                            noTone(BuzzerPin);
  Lock = 0;

}

void loop() {
  // put your main code here, to run repeatedly:

if(mySerial.available())
{
 //delay(10);
   CommandChar = (char)mySerial.read();
   if(CommandChar != "\n")
   {
    Serial.print(CommandChar);
    if ((String)CommandChar == "P")
    {
      Lock = 1;
       pinMode(BuzzerPin,OUTPUT);
      digitalWrite(12,LOW);
      digitalWrite(13,HIGH);
      digitalWrite(BuzzerPin,HIGH);
      //Serial.println("Received P");
    }
    if (((String)CommandChar =="R") )
    {
      Lock = 0;
      digitalWrite(13, LOW);
      digitalWrite(12,HIGH);
      digitalWrite(BuzzerPin,LOW);
         }
     if ((String)CommandChar == "C")
     {
      mySerial.print("Call*");
     }
    }
  else
    {
    Serial.println(CommandChar);
     }
}//End of mySerial loop

if ((digitalRead(ManualReset) == 1) && (digitalRead(12)==HIGH))
{
//      Lock = 0;
//      digitalWrite(13, LOW);
//      digitalWrite(12,HIGH);
//      pinMode(BuzzerPin,INPUT);
        mySerial.print("Call*");
        Serial.println("called from box");
}

if ((digitalRead(ManualReset) == 1) && (digitalRead(12)==LOW))
{
      Lock = 0;
      digitalWrite(13, LOW);
      digitalWrite(12,HIGH);
      pinMode(BuzzerPin,INPUT);
        mySerial.print("Reset*");
        Serial.println("Reset from box");
}

if (digitalRead(CallPin) ==1)
{
  mySerial.print("Call*");
}

if (Lock == 1)
  {
    digitalWrite(13,HIGH);
    digitalWrite(BuzzerPin,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    digitalWrite(BuzzerPin,LOW);
   // noTone(BuzzerPin);
    delay(300);
  }
  

if (Lock == 0)
{
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  pinMode(BuzzerPin,INPUT);
}
Serial.println(digitalRead(ManualReset));
mySerial.print("Hello*");
//mySerial.println();

delay(2000);

}

      


 

Schematics

Basic Sketch
Basic sketch bb leohoirgzv

Comments

Similar projects you might like

Bluetooth Controlled Light Switch

Project showcase by Team The Instrumentation Crustaceans

  • 23,398 views
  • 4 comments
  • 26 respects

Convert Your Old Phone to a Remote Switch

Project tutorial by Vishwas Navada

  • 11,575 views
  • 5 comments
  • 40 respects

Smart Switch

Project in progress by Sameer

  • 48,714 views
  • 6 comments
  • 109 respects

Smart Blind Assistant

Project in progress by Chandru S

  • 3,922 views
  • 1 comment
  • 6 respects

Otto DIY+ Arduino Bluetooth Robot Easy to 3D Print

Project tutorial by Team Otto builders

  • 58,415 views
  • 122 comments
  • 188 respects
Add projectSign up / Login