Make timer state ON and timer state OFF Android to Arduino via bluetooth

Who help me code example for:
Make timer state ON and timer state OFF Android to Arduino via bluetooth

Hi,

Can you be more descriptive about the intent of your project? What is it for? What does it mean for a timer to have an ON/OFF state? Do you already have a setup / code to show us?

Also for the Arduino to be connected by bluetooth, you need to have a bluetooth module and a library to receive/send messages to your computer running Processing.

Doing a simple research on Internet give me those results :

That’s why giving a simple code example is complicated :wink:

Also if it’s a homework assignment, please read the FAQ.

Have fun!

i made this

import ketai.net.bluetooth.*;
import controlP5.*;
import android.os.Bundle;

ControlP5 cP5a;
ControlP5 cP5b;

String device_name = "HC-05";
//String device_mac = "40:45:DA:00:25:05";

KetaiBluetooth bt;

void setup() { 
  cP5a = new ControlP5(this);
  cP5a.addSlider("CYCLE_TIME", 999, 1999,999, 10, 10, 255, 35);
  cP5b = new ControlP5(this);
  cP5b.addSlider("PULSE", 55, 455, 55, 10, 55, 255, 35);
  bt.getPairedDeviceNames();
  bt.start();
  //bt.connectDevice("40:45:DA:00:25:05");
  bt.connectToDeviceByName(device_name);
}

void draw() {
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isController()) {
    print("control event from : "+theEvent.getController().getName());
    println(", value : "+theEvent.getController().getValue());
    if (theEvent.getController().getName()=="CYCLE_TIME") {
      int val1 = int(theEvent.getController().getValue());
      send("a" + val1+"\n");
    }
    if (theEvent.getController().getName()=="PULSE") {
      int val2 = int(theEvent.getController().getValue());
      send("b" + val2+"\n");
    }
  }
}

void send(String str) {
  byte[] data = str.getBytes();
  //bt.write(device_mac, data);
  bt.writeToDeviceName(device_name, data);
  //OscMessage m = new OscMessage(str);
  //bt.broadcast(m.getBytes());
}

void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  bt = new KetaiBluetooth(this);
}

this is arduino side

void loop() {  
    if (Serial.available() >= 2)
   {
    int value2;
    char command = Serial.read();
    switch (command)
    {
    case 'a': value2 = Serial.parseInt();
     d = value2;
       } 
      break;

    case 'b': value2 = Serial.parseInt();
     f = value2;
         }
       break;
 }

you can use the d and f values as you want

and you can change the 2 sliders with buttons

1 Like

Good evening
Thanks for the pricey information
I made a timer with lcd on arduino
I would like to do it on android as a graphic part and via bluetooth communicate with arduino
this is the link of the timer I made
Thank you!!!

1 Like

Jafal
Tankyou for code
But decise i try to compile whit APDE but give me error:

Initializing build sequence…
Deleted old build folder
No library found for ketai.net.bluetooth
No library found for controlP5
Injected log broadcaster
Detected architecture armeabi-v7a

Packaging resources with AAPT…
Compiling with ECJ…

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 8)
    import ketai.net.bluetooth.*;
    ^^^^^
    The import ketai cannot be resolved

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 9)
    import controlP5.*;
    ^^^^^^^^^
    The import controlP5 cannot be resolved

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 27)
    ControlP5 cP5a;
    ^^^^^^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 28)
    ControlP5 cP5b;
    ^^^^^^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 33)
    KetaiBluetooth bt;
    ^^^^^^^^^^^^^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 36)
    cP5a = new ControlP5(this);
    ^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 36)
    cP5a = new ControlP5(this);
    ^^^^^^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 37)
    cP5a.addSlider(“CYCLE_TIME”, 999, 1999,999, 10, 10, 255, 35);
    ^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 38)
    cP5b = new ControlP5(this);
    ^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 38)
    cP5b = new ControlP5(this);
    ^^^^^^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 39)
    cP5b.addSlider(“PULSE”, 55, 455, 55, 10, 55, 255, 35);
    ^^^^
    ControlP5 cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 40)
    bt.getPairedDeviceNames();
    ^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 41)
    bt.start();
    ^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 43)
    bt.connectToDeviceByName(device_name);
    ^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 49)
    public void controlEvent(ControlEvent theEvent) {
    ^^^^^^^^^^^^
    ControlEvent cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 67)
    bt.writeToDeviceName(device_name, data);
    ^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 74)
    bt = new KetaiBluetooth(this);
    ^^
    KetaiBluetooth cannot be resolved to a type

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20210202a/sketch_20210202a.java (at line 74)
    bt = new KetaiBluetooth(this);
    ^^^^^^^^^^^^^^
    KetaiBluetooth cannot be resolved to a type

18 problems (18 errors)
Compiling with ECJ failed

download ketai controlP5 libraries to your
sketchbook

yes i download .
is possible have one timer HH:MM:SS
?
tnx

one timer where you mean ?

immagine_2021-03-22_225816

@r0x15

i am same as you learning but i can help you how to communicate via Buletooth and the best for you is to make the android view the timer lcd and control the arduino sw

Tankyou !! i need learning

where do we start from ?

read noal’s topics about arduino and BT he made very good explanation

Ok
I now i need code for timer when state on and timer when state off in form : HH:MM:SS
where i possible set example 00:00:05 set state on
And 00:00:10 set state off
Visita link:https://youtube.com/watch?v=53BYdbbe5rg&feature=share

The Arduino is automatic does the code you want. It is easiest for you to display the result using the process sketch.

You can transfer this part of the Arduino code through Bluetooth and display the results on Android

lcd.setCursor(4,1);
if(time_h<=9){lcd.print("0");}
lcd.print(time_h);
lcd.print(":");
if(time_m<=9){lcd.print("0");}
lcd.print(time_m);
lcd.print(":");
if(time_s<=9){lcd.print("0");}
lcd.print(time_s);
lcd.print("   ");

read this and make it when you can communicate with bluetooth then you can move to upper level

request

and this

jafal
sorry but I did not understand from the post de code of the answer and the meaning you had given me
now I’ll try
give me more info to be able to manage your code from arduino that I will see on android
thank you