Percent timer by using arduino

Hello there.

I'm trying to make percent timer by using arduino. But can't find any example code on internet. I will control percentage by Blynk slider. Can anyone help me please?

Thanks in advance.

#define BLYNK_PRINT Serial

#define TINY_GSM_MODEM_SIM900
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

#include <SimpleTimer.h>
BlynkTimer timer;

SoftwareSerial SerialAT(7, 8);
TinyGsm modem(SerialAT);

char apn = "internet";
char user = "";
char pass = "";

int startrelay = 9;

int startrelesi = 0;

bool startrelesiON;

unsigned long cycleTime = 60000;
unsigned long starttime ;
unsigned long onTime ;
unsigned long lastTime = 0;
float percent = 0;

char auth = "MyAuth";

BLYNK_WRITE(V3){ // START/STOP switch button in blynk app
startrelesi = param.asInt();
if (startrelesi== HIGH)
{

    Blynk.virtualWrite(V3, param.asInt());

}
else {

   digitalWrite(startrelay, LOW);

   Blynk.virtualWrite(V3, LOW);

}
}

BLYNK_WRITE(V6){ //slider for percentage adjusting from blynk app
percent = param.asFloat();
starttime = cycleTime * (1-(percent/100))-1000;
onTime = cycleTime * (percent/100);
Blynk.virtualWrite(V5, percent);
}

void start(){

      Blynk.virtualWrite(V3,startrelesi);

if(millis() - starttime < onTime)
startrelesiON = true;
else
startrelesiON = false;

if(millis() - starttime > cycleTime)
starttime += cycleTime; // starttime= starttime + cycleTime
if((startrelesiON == true) && (startrelesi == HIGH ) ){

digitalWrite(startrelay,HIGH);
}

else
digitalWrite(startrelay,LOW);
}

void setup(){

pinMode(12, OUTPUT);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(2000);

SerialAT.begin(9600);

modem.restart();
Blynk.begin(auth, modem, apn, user, pass);

         pinMode(startrelay, OUTPUT); 

           Blynk.virtualWrite(V6,0);// Slider in Blynk app
           Blynk.virtualWrite(V3,0); // toggle button in Blynk app
           Blynk.virtualWrite(V5,0);// labeled value in Blynk app

}
void loop(){
//CheckConnection();

timer.run();
Blynk.run();
start();

}

Forget about the percentage for now

Can you get a value from the Blynk slider to the Arduino and display it on the Serial monitor ?

I'm sorry for my bad English firstly.
Yes I can get the value. I want to make a center pivot controller. And I made it. I made percent timer too. The period is 60 seconds. When I choose 50% from the app relay pin has to be HIGH for 30 seconds and LOW for 30 seconds. But it doesn't work stable. Every time it cunts 60 seconds and plus 1 second LOW again. Totally 61 seconds. So I need true percent timer for my project.

Please post your code using code tags as described in How to get the best out of this forum

the code is below

#define BLYNK_PRINT Serial

#define TINY_GSM_MODEM_SIM900
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

#include <SimpleTimer.h>
BlynkTimer timer;

SoftwareSerial SerialAT(7, 8);
TinyGsm modem(SerialAT);

char apn[] = "internet";
char user[] = "";
char pass[] = "";

int startrelay = 9;

int startrelesi = 0;

bool startrelesiON;

unsigned long cycleTime = 60000;
unsigned long starttime ;
unsigned long onTime ;
unsigned long lastTime = 0;
float percent = 0;

char auth[] = "MyAuth";

BLYNK_WRITE(V3){ // START/STOP switch button in blynk app
startrelesi = param.asInt();
if (startrelesi== HIGH)
{

    Blynk.virtualWrite(V3, param.asInt());

}
else {

   digitalWrite(startrelay, LOW);

   Blynk.virtualWrite(V3, LOW);

}
}

BLYNK_WRITE(V6){ //slider for percentage adjusting from blynk app
percent = param.asFloat();
starttime = cycleTime * (1-(percent/100))-1000;
onTime = cycleTime * (percent/100);
Blynk.virtualWrite(V5, percent);
}

void start(){

      Blynk.virtualWrite(V3,startrelesi);

if(millis() - starttime < onTime)
startrelesiON = true;
else
startrelesiON = false;

if(millis() - starttime > cycleTime)
starttime += cycleTime; // starttime= starttime + cycleTime
if((startrelesiON == true) && (startrelesi == HIGH ) ){

digitalWrite(startrelay,HIGH);
}

else
digitalWrite(startrelay,LOW);
}

void setup(){

pinMode(12, OUTPUT);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(2000);

SerialAT.begin(9600);

modem.restart();
Blynk.begin(auth, modem, apn, user, pass);

         pinMode(startrelay, OUTPUT); 

           Blynk.virtualWrite(V6,0);// Slider in Blynk app
           Blynk.virtualWrite(V3,0); // toggle button in Blynk app
           Blynk.virtualWrite(V5,0);// labeled value in Blynk app

}
void loop(){
//CheckConnection();

timer.run();
Blynk.run();
start();

}

Why did you take no notice of the advice to use code tags ?

post code using </>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.