Things used in this project

Hardware components:
Compare particleelectron
Particle Electron
×1
Solar panel
Must have a USB output
×1
Gus 1719
C.H.I.P. Approved 3.7 V LiPo Battery
×1
1434509556 android phone color
Android device
×1
Fairchild semiconductor pn2222abu. image
General Purpose Transistor NPN
×3
11026 02
Jumper wires (generic)
×9
Software apps and online services:
Android Studio
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Schematics

Breadboard schematic
Use this image to wire your own board together.
Key fob breadboard bb qvor1cbgvm

Code

Particle Electron codeC/C++
Input this into build.particle.io
/* App to replace 2002 Ford Fairlane Key Fob
*/
void setup() {
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(D4, OUTPUT);
    Particle.function("lock", lock);
    Particle.function("unlock", unlock);
    Particle.function("boot", boot);
} 

int lock(String command) {
    digitalWrite(D3, HIGH);
    delay(100);
    digitalWrite(D3, LOW);
    digitalWrite(D7, HIGH);
    delay(500);
    digitalWrite(D7, LOW);
    return 1;
}

int unlock(String command) {
    digitalWrite(D4, HIGH);
    delay(100);
    digitalWrite(D4, LOW);
    delay(100);
    digitalWrite(D4, HIGH);
    delay(100);
    digitalWrite(D4, LOW);
    digitalWrite(D7, HIGH);
    delay(500);
    digitalWrite(D7, LOW);
    return 1;
}

int boot(String command) {
    digitalWrite(D2, HIGH);
    delay(100);
    digitalWrite(D2, LOW);
    digitalWrite(D7, HIGH);
    delay(500);
    digitalWrite(D7, LOW);
    return 1;
}

void loop() {

}
Main Activity for Android appJava
Use in your MainActivity.java
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import io.particle.android.sdk.devicesetup.ParticleDeviceSetupLibrary;

public class MainActivity extends AppCompatActivity {

    public static String function;
    private static Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = getApplicationContext();

        ParticleDeviceSetupLibrary.init(this.getApplicationContext(), MainActivity.class);

        // Declare and assign our buttons and text
        Button lockButton = (Button) findViewById(R.id.lockButton);

        View.OnClickListener lock = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Locking...", Toast.LENGTH_LONG).show();
                function = "lock";
                HelperThread thread = new HelperThread();
                thread.setName("HelperThread");
                thread.start();
            }
        };
        lockButton.setOnClickListener(lock);

        // Declare and assign our buttons and text
        Button unlockButton = (Button) findViewById(R.id.unlockButton);

        View.OnClickListener unlock = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Unlocking...", Toast.LENGTH_LONG).show();
                function = "unlock";
                HelperThread thread = new HelperThread();
                thread.setName("HelperThread");
                thread.start();
            }
        };
        unlockButton.setOnClickListener(unlock);

        // Declare and assign our buttons and text
        Button bootButton = (Button) findViewById(R.id.bootButton);

        View.OnClickListener boot = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Booting...", Toast.LENGTH_LONG).show();
                function = "boot";
                HelperThread thread = new HelperThread();
                thread.setName("HelperThread");
                thread.start();
            }
        };
        bootButton.setOnClickListener(boot);

    }
    public void showConfirmation(int i, String function) {
        switch(i) {
            case 0:
                if (function == "lock"){
                    Toast.makeText(MainActivity.mContext, "Unable to lock.", Toast.LENGTH_LONG).show();
                } else if (function == "unlock") {
                    Toast.makeText(MainActivity.mContext, "Unable to unlock.", Toast.LENGTH_LONG).show();
                } else if (function == "boot") {
                    Toast.makeText(MainActivity.mContext, "Unable to open boot.", Toast.LENGTH_LONG).show();
                } else {
                    Log.e("Error", "Error");
                }
                break;
            case 1:
                if (function == "lock"){
                    Toast.makeText(MainActivity.mContext, "Locked.", Toast.LENGTH_LONG).show();
                } else if (function == "unlock") {
                    Toast.makeText(MainActivity.mContext, "Unlocked.", Toast.LENGTH_LONG).show();
                } else if (function == "boot") {
                    Toast.makeText(MainActivity.mContext, "Boot Opened.", Toast.LENGTH_LONG).show();
                } else {
                    Log.e("Error", "Error");
                }
                break;
            default:
                Toast.makeText(MainActivity.mContext, "Unknown outcome", Toast.LENGTH_LONG).show();
        }

    }
}
Helper ThreadJava
This handles the asynchronous function POST method for communicating with the Particle cloud service.
You will need to enter the device name or ID number of your own device.
import android.support.annotation.NonNull;
import android.util.Log;

import java.io.IOException;

import io.particle.android.sdk.cloud.ParticleCloudException;
import io.particle.android.sdk.cloud.ParticleCloudSDK;
import io.particle.android.sdk.cloud.ParticleDevice;
import io.particle.android.sdk.utils.Async;

public class HelperThread extends Thread {

    public static int resultCode;
    public static int resultCode2;

    public void run() {
        ParticleDevice myDevice = null;
        resultCode = 0;
        resultCode2 = 0;
        try {
            myDevice = ParticleCloudSDK.getCloud().getDevice("YOUR DEVICE HERE");
            getValue(myDevice, MainActivity.function);
        } catch (ParticleCloudException | IOException | ParticleDevice.VariableDoesNotExistException e) {
            e.printStackTrace();
        }
    }

    public int getValue(ParticleDevice myDevice, final String function) throws ParticleCloudException, IOException, ParticleDevice.VariableDoesNotExistException {


        Async.executeAsync(myDevice, new Async.ApiWork<ParticleDevice, Integer>() {

            public Integer callApi(@NonNull ParticleDevice myDevice)
                    throws ParticleCloudException, IOException {
                try {
                    resultCode = myDevice.callFunction(function);
                } catch (ParticleDevice.FunctionDoesNotExistException e) {
                    e.printStackTrace();
                }
                return resultCode;
            }

            @Override
            public void onSuccess(@NonNull Integer s) {
                MainActivity confirmation = new MainActivity();
                confirmation.showConfirmation(resultCode, function);
            }

            @Override
            public void onFailure(@NonNull ParticleCloudException e) {
                Log.e("Result", "Something went wrong making an SDK call: ", e);
            }
        });

        return resultCode;
    }
}
Layout file for the buttonsXML
Use this file to organise your on-screen buttons for the Android app. Wrapping the layout in a FrameLayout prevents the app from freezing during operation (allows it to keep receiving commands).
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/activity_main"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        >

        <Button android:id="@+id/lockButton"
                android:text="Lock"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_gravity="center_horizontal"
                android:textSize="@dimen/textSize"
                style="@style/Widget.AppCompat.Button.Colored"/>

        <Button android:id="@+id/unlockButton"
                android:text="Unlock"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_gravity="center_horizontal"
                android:textSize="@dimen/textSize"
                style="@style/Widget.AppCompat.Button.Borderless.Colored"/>

        <Button android:id="@+id/bootButton"
            android:text="Boot"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:textSize="@dimen/textSize"
            style="@style/Widget.AppCompat.Button.Colored"/>

    </LinearLayout>
</FrameLayout>
String constants fileXML
Enter OAuth information using: https://docs.particle.io/guide/how-to-build-a-product/authentication/#oauth and https://docs.particle.io/reference/android/#oauth-client-configuration
<string name="oauth_client_id">(client ID string goes here)</string>
<string name="oauth_client_secret">(client secret 40-char hex string goes here)</string>
Dimens fileXML
Used for colours and text sizes
<dimen name="textSize">72sp</dimen>

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Blynk GPS Tracker
Intermediate
  • 41
  • 2

Full instructions

Simple GPS tracker using a Particle Photon (or Electron) and an EM406 GPS module with location visible on Blynk app map.

Pool Buddy
Intermediate
  • 1,619
  • 11

Work in progress

Monitor and log water quality (pH & ORP) and temperature from everywhere.

IoT Thermometer Using Python
Intermediate
  • 986
  • 8

Full instructions

How to develop a simple but powerful IoT thermometer using a Zerynth-powered single-board MCU and the Zerynth App.

Particle Photon Flip Dot Clock
Intermediate
  • 2,162
  • 31

Full instructions

The flip dot display uses an electromechanical dot matrix that spin from black to yellow to display text, numbers and more!

Patriot iOS App
Intermediate
  • 547
  • 9

Use an old iPhone device to control and display the status of your Patriot IoT devices.

Patriot iOS App

Team Patriot

What To Wear LCD
Intermediate
  • 48
  • 1

Ever wondered what to wear due to unpredictable weather??? Wonder no longer!

Add projectSign up / Login