Physical Android Notifier

ebeed6e64537e23072bf1f6b83fbde6b_MD5.jpg

I wanted to create a simple notifier for my Android phone. Something that would blink whenever I have a missed call, or sms or whatsapp notification.

The hardware part was easy:

  1. Funduino Mini Pro
  2. Common Anode RGB LED
  3. Switch
  4. Bluetooth Breakout Board

Schematic:

bdf0e72dfb1130e05f2eef06e3b2c26a_MD5

The Arduino software was also easy:

/*

  ClickButton: https://code.google.com/p/clickbutton/
  SerialCommand: https://github.com/kroimon/Arduino-SerialCommand

*/

#include 
#include 
#include 

#define IDLE 0
#define REDLED 11
#define GREENLED 10
#define BLUELED 9
#define SWITCHPIN 12

SerialCommand sCmd;     // The SerialCommand object
ClickButton button1(SWITCHPIN, LOW, CLICKBTN_PULLUP);
boolean wa, sms, missed, ledState;
Color cur_color = Color(1,1,1);
float hue = 0;

void setup()  
{
  Serial.begin(9600); 
  // Setup callbacks for SerialCommand commands
  sCmd.addCommand("MISSED", missedCall);
  sCmd.addCommand("SMS", smsOn);
  sCmd.addCommand("WHATSAPP", whatsapp);
  sCmd.addCommand("MISSEDOFF", missedOff);
  sCmd.addCommand("SMSOFF", smsOff);
  sCmd.addCommand("WAOFF", waOff);
  pinMode(REDLED, OUTPUT);
  digitalWrite(REDLED, HIGH);
  pinMode(BLUELED, OUTPUT);
  digitalWrite(BLUELED, HIGH);
  pinMode(GREENLED, OUTPUT);
  digitalWrite(GREENLED, HIGH);
  wa = 0;
  sms = 0;
  missed = 0;
  ledState = 0;
}

void loop()
{
  sCmd.readSerial();
  button1.Update();
  if(button1.clicks >= 1) ledState = !ledState;
  if(ledState) rainbow();
  if(!ledState) {
  for(int i=0;i<missed;i++){
    digitalWrite(REDLED,LOW);
    delay(300);
    digitalWrite(REDLED,HIGH);
    delay(300);
  }
  for(int i=0;i<sms;i++){
    digitalWrite(GREENLED,LOW);
    delay(300);
    digitalWrite(GREENLED,HIGH);
    delay(300);
  }
  for(int i=0;i<wa;i++){
     digitalWrite(BLUELED,LOW);
     delay(300);
     digitalWrite(BLUELED,HIGH);
     delay(300);
   }
   }
 }
void missedCall() {     missed += 1; } 
void smsOn() {     sms += 1; } 
void whatsapp() {     wa += 1; } 
void missedOff() {     missed = 0; } 
void smsOff() {    sms = 0; } 
void waOff() {     wa = 0; } 

void rainbow(){   hue += 0.06;   if ( hue >=1 ) hue = 0;
  float sat = 1.0;
  float val = 0.4;
  cur_color.convert_hcl_to_rgb(hue,sat,val);
  display_color(cur_color);
  delay(20);
}

void display_color(Color c){
  analogWrite(REDLED, 255-c.red);
  analogWrite(GREENLED, 255-c.green);
  analogWrite(BLUELED, 255-c.blue);
  delay(100);
}

It was the Android part that simply killed me… I wanted a simple application, that would send a serial command to the arduino whenever there was a missed call. Thought of writing an android app (how hard could it be)… realised very soon that “very” if you don’t know how…

Then tried looking for existing apps which could help, helpful people suggested Amarino, however I couldn’t get it to work on my mobile – it kept crashing. Long story short – landed up on a google groups page where Jonathan Ulmer talked about SL4A and Tasker – he had also provided code for the same. This looked like the easiest option for a beginner programmer like me.

There were a few hiccups here as my phone did not support IPv6 and the default version of SL4A uses IPv6; again google came to my rescue and I was able to install the correct version – it’s called sl4a_r6x

The next step was to install python through sl4a and load the following python code:

#!/usr/bin/python
# coding=utf-8

import android
import time

droid = android.Android()

uuid='00001101-0000-1000-8000-00805F9B34FB' #couldn't get bluetooth to work without this uuid..
mac='20:13:05:xx:xx:xx' #enter your bluetooth module mac address

connId=droid.bluetoothConnect(uuid,mac).result #connect to bluetooth module mac specified above
command = droid.getIntent().result[u'extras'][u'%ARDUINO']
print command
droid.bluetoothWrite(command)
droid.bluetoothWrite('\n')

You need to place the file with the python code in the \sdcard\sl4a folder

Next is to setup Tasker – please read through a few tutorials if you’re not familiar with tasker. The basic steps for this are:

  1. Add profile -> Event -> Phone -> missed call
  2. Add Action:
    1. Net -> Bluetooth -> On
    2. Variable Set -> %ARDUINO to MISSED
    3. Script -> Run Sl4A Script -> arduino1.py; pass variable %ARDUINO
  3. Add profile -> Application -> Phone
  4. Add Action:
    1. Net -> Bluetooth -> On
    2. Variable Set -> %ARDUINO to MISSEDOFF
    3. Script -> Run Sl4A Script -> arduino1.py; pass variable %ARDUINO

Now if only someone with Android programming experience would make a tasker plugin that sends a serial command to the bluetooth module – we can get rid of the entire scripting layer and make the work easier (hint hint)

The final product:

ebeed6e64537e23072bf1f6b83fbde6b_MD5

Latest Posts