Introduction: Android Automate With Arduino Using Audio Serial for Automation

Android is a very powerful and flexible platform and Automate is a great app that allows you to create workflows and automate things in your android device, it allows you to do things like creating a workflow so that the app automatically takes pictures every certain amount of time and sends them to your email and much more. I thought it would be a good idea to use it in conjunction with Arduino to automate some devices at home. It is not easy to use Bluetooth communication with a Serial Bluetooth app and Automate, you can refer to another instructable that deals with this issue here https://www.instructables.com/id/Bluetooth-Bridge-Between-Android-and-Arduino-Btspp/ . So I decided to use serial communication between the Android device and the Arduino, using another powerful app called audio serial and available at the Google Play Store https://play.google.com/store/apps/details?id=re.serialout&hl=en by the awesome team of Robots Everywhere. You can check their wiki with the source code and schematics to make the cable required to use the device audio jack as a serial port here https://robots-everywhere.com/re_wiki/pub/web/Cookbook.AudioSerial.html or you can also buy the cable they sell to support their work.

Supplies

Arduino UNO with USB cable to program available below

https://www.amazon.com/gp/product/B07R1H4BKK/ref=a...

Arduino IDE available from the Arduino website

Android device with audio jack

Serial Audio (free) from the Google Store

https://play.google.com/store/apps/details?id=re.serialout&hl=en

Automate app (free version) from Google store

https://play.google.com/store/apps/details?id=com.llamalab.automate&hl=en

Op Amp LM327 or similar

1 4.7 uF capacitor

1 4.7K ohms resistor

1 1K ohms resistor

1 100 ohms resistor

audio jack for the Android Device

Step 1: Making the Audio Circuit (optional)

If you didn't buy the cable from Robots Everywhere available here: https://robots-everywhere.com/re_wiki/pub/web/Cook..., you can make it yourself by buying the parts. I attached the diagram available at their page which I use to create my own circuit, I made it with an LM324N, but you can use another similar OP AMP, it is acting as a voltage comparator and I think I still need to adjust mine a bit, since I'm using the inverting input connected to the audio signal and probably would be better to use the non inverting input so that I don't need to invert the signal on the app (I wasn't sure how it was going to work out). I also connected the non inverting input to ground and sometimes the signal is noisy, that's why I send the character in the Arduino sketch several times.

If you have some knowledge of electronics you can certainly build a voltage comparator and tweak it, but if you don't you can buy the already made cable from the guys that developed the app, that way you will be supporting them and they will create more awesome stuff.

Step 2: Arduino Programming

Now its time to program the Arduino, in this case, I will be using the serial input by default located at pins 0-1 but since the Arduino won't send any data back to the Android device, I will only connect the output of the audio circuit to the RX pin (pin 0) as shown in the diagram.

This is the sketch I created, you can improve it and share it, certainly it's not the best way to do it but you are free to modify it or make any suggestions

void setup() {

Serial.begin(2400); //set the baud rate to 2400

pinMode(13,OUTPUT); /*set the pin 13 as digital output (you would connect a relay to this pin to control a device )*/

}

char buf[5]; //buffer to place characters read

bool read_a; //did you read an a?

bool read_z; //did you read a z?

void loop() {

if(Serial.available() > 0){ //standard stuff

int len = Serial.readBytes(buf,5);

if (len > 0){

for(int i=0; i < len; i++){

if(buf[i] == 'a'){

read_a = true;

}else if(buf[i] == 'z'){

read_z = true;

}

}

if(read_a){

digitalWrite(13,HIGH);

read_a = false;

}

if(read_z){

digitalWrite(13,LOW);

read_z = false;

}

}

}

}

Step 3: Creating the Automate Workflow

With automate, you are able to interact with other apps using their Graphical User Interface, that way you can click on buttons, set text on text fields and others, but the result is not always as expected and this needed several blocks to be implemented, fortunately with the source code and documentation of the audio serial app I was able to integrate it easily using the Output activity. So, you just need to set the specific conditions when you want to run your automation workflow, in my case I set it to run everyday of the week at 7 am to turn on the grow lights for my plants and at 7 pm to turn them off. As you can see in the image you just need to pass the parameters to the app using the "Extras" field and you need to pass them in a dictionary "DATA" for the data we want to send to the Arduino, "BAUD" for the baud rate, "INV" set to "1" if you want to invert the signal, and "CHD" for character delay. That's all, this circuit and the program make the LED on port 13 go on and off, but you can connect a simple relay with the driving circuit or buy a module and you should be able to control a device using all kinds of conditions and workflows! have fun! and special thanks to the guys of Robots Everywhere that provided me with the source code and schematics of the Audio Serial app and were always willing to help.