Timer not working with Bluetooth

I am currently using an Arduino Nano with an HC-05 with controls a server. Everything works except for the timer (Android side). I haven’t seen any notes about the timer being incompatible with Bluetooth devices, so I am confused. Just to be clear, V0 is being used with a toggle button on the Android device to disable and enable the Arduino. This is accompanied with the pin 13 LED changing states to reflect whether the device is active. This works without a problem. V1 is used to control the actual lighting, moving a servo to different states to flick a switch. When V1 is controlled via a timer, nothing happens. It is as if V1 is not toggled at all. If I use a button to manipulate V1, then it works as expected. Please help.

code:

#define BLYNK_PRINT Serial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(11, 10); // RX, TX
     
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include <Servo.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "something";

SoftwareSerial SerialBLE(11, 10); // RX, TX

Servo lightControl;

const int neutral = 115;
const int on = 80;
const int off = 128;

bool active = false;

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
  int input = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();

  if (input == 1 && active)
   {
      lightControl.write(off);
      delay(500);
      lightControl.write(neutral);
    }
    if (input == 2  && active)
    {
      lightControl.write(on);
      delay(500);
      lightControl.write(neutral);
    }
}

BLYNK_WRITE(V0)
{
  active = (param.asInt() != 0);
  if (active)
  {
    digitalWrite(13, HIGH);
  }
  else
  {
    digitalWrite(13, LOW);
  }
}

 void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  pinMode(13, OUTPUT);
  lightControl.attach(9);
}

void loop()
{
  Blynk.run();
}

http://docs.blynk.cc/#widgets-controllers-timer
NOTE: The timer widget rely on the server time and not your phone time. Sometimes the phone time may not match the server time.

The key note here is that this widget uses Server time, however when using BT/BLE, the only use of the Server is for the App login… the App and MCU are directly linked via the BT/BLE connection… so no Widgets that require a Server connection will function in that mode of connection.

PS, I fixed your code formatting… no need for > if done properly

Thanks. So much for that project.

@codeToad enter the time with Terminal or sliders and then use millis(). Your project is now back on track.

1 Like