Multipurpose Relay Project With Open Source Android App

About the project

Control many different relay boards with your Particle devices from your phone, open source Ionic Android app included!

Items used in this project

Hardware components

Particle Relay Shield Particle Relay Shield x 1
Particle Photon Particle Photon x 1

Software apps and online services

myRelays myRelays
Ionic Framework Ionic Framework

Story

This project contains a firmware and an Ionic app to control one or more relays from an Android device.

If you need to control a lamp, open your garage or control your sprinkler valve to water your lawn, this project offers a way to do that from your phone with an easy to use app provided.

Few years back I got hooked in the world of hybrid apps and specifically the Ionic Framework.

It took me a while to ramp up and be able to do something interesting with it. Understanding the concepts involved in asynchronous JavaScript/Typescript apps (web or anything else) was a bit different to what I was used to, let alone dealing with promises and observables in Angular.

Anyway, I decided to create this firmware and an Ionic app that goes along. And what better time to share it with everyone than now that the new Particle Mesh devices are out!

The app

While it deserves a write up on its own, in the meantime know that it's built with Angular, HTML and CSS. All those things get combined beautifully in Ionic.

The app can run on your Android device (phone or tablet) and it looks like this:

;

;

1 / 3Controlling 4 relays

To control your relays, swipe your finger left on top of the relay you want to control to expose the buttons menu, and hit the on, off or pulse buttons.

Hitting the pulse button will turn on the relay for a number of milliseconds. This can be changed in the firmware.

Animations

The app contains a couple of animations made with Lottie.

You can create great animations with Lottie

What is Lottie? From their page:

Lottie is an iOS, Android, and React Native library that renders After Effects animations in real time, allowing apps to use animations as easily as they use static images.

Another definition:

Lottie is a mobile library for Web, and iOS that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile!

Thanks to an Angular library called ng-lottie, we can use them on our Ionic apps.

And after many hours in Adobe After Effects, the results can be pretty cool.

Boards tested

These are the boards tested:

;

;

1 / 6some of the boards supported by this project

Boards supported

Theoretically, there is a large number of boards one can use with this project:

Project setup

STEP 1: Assemble your relay board. Depending on the one you choose you may have some soldering to do.

STEP 2: Customise the firmware. You can grab the myRelays.ino firmware from the git repo or import it in Particle Build with this link.

If you are using an NCD relay board, please configure the firmware to have the following lines like this:

#define USE_NCD_BOARD
// #define USE_PARTICLE_RELAY_SHIELD
// #define USE_SINGLE_RELAY

In the case of a Particle relay shield:

//#define USE_NCD_BOARD
#define USE_PARTICLE_RELAY_SHIELD
//#define USE_SINGLE_RELAY

Or if you are using a simple relay connected to any digital output of your Particle device, they should look like this:

//#define USE_NCD_BOARD
// #define USE_PARTICLE_RELAY_SHIELD
#define USE_SINGLE_RELAY

You can connect the simple relay to the digital output specified by this line in the firmware:

#define MY_RELAY D0

Tip: You can configure D7 in that line above to play with the on-board led!

Note: remember that the relay you connect to your device must be a 3.3 volts input relay. A 5 volts relay may not work at all.

STEP 3: Flash the firmware on your device.

STEP 4: Install the app on your Android device. While I get it through the Google Play process of publishing an app, you can enjoy it right away from this link on My Google Drive.

https://drive.google.com/open?id=1gDtPCCMrsC1XqkncBsZ6TSnjZ-_HVhx-

Or this one:

https://drive.google.com/open?id=1PzttxUgnq6oM-B_5HgqcN997liEv6tLa

I have tested this apk on a Nexus 5 and a Pixel 2.

Note: there is some sort of magic with these apk files that I'm trying to figure out. Leave me a note below if you run intro trouble while installing it.

UPDATE: the app is live now and you can find it here:

https://play.google.com/store/apps/details?id=io.gusgonnet&rdid=io.gusgonnet

STEP 5: configure your Particle Access Token and Device ID in the app Settings:

STEP 6: Hit the Done button at the bottom and go back to the Relays screen. Your relays status should refresh automatically!

Final notes

Since the app stores the Particle Access Token on the Android device in order to communicate with the Particle Cloud and your Particle device, it is recommended that this app is only used on Android devices you own.

Need help?

If you require professional help with your projects, don't hesitate to write me a line about your needs at gusgonnet@gmail.com. Thank you!

Check the rest of my projects here!

Code

Main repo

Credits

Photo of gusgonnet

gusgonnet

If you need professional help with a project, contact me at gusgonnet@gmail.com

   

Leave your feedback...