Hi. Iām using USB serial connection with arduino to connect blynk.
Auto mode > manual mode was fine. Auto mode suppose to run 5sec and idle 5sec
But when manual mode switch back to auto, therere no relay pulse. The time frame is not restoredā¦
Iām new to blynk and electronics. Please help
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <DHT.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
#define relay1 11
#define lightpin 0
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
SimpleTimer timer;
int i=0;
int button2;
int selectmode;
int timer1;
int timer2;
int timer3;
int Lux;
char auth[] = "14df01c16b1548518503a6bf1d74681c";
WidgetLED led1(8);
WidgetLED led2(9);
void setup()
{
// Debug console
DebugSerial.begin(9600);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
pinMode(lightpin, OUTPUT);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
dht.begin();
Blynk.begin(Serial, auth);
timer.setInterval(3000,senddata);
}
void loop()
{
Blynk.run();
timer.run();
}
void senddata(){
int analoglux=analogRead(lightpin);
int h = dht.readHumidity();
int t = dht.readTemperature();
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V2, t);
Blynk.virtualWrite(V3, analoglux);
}
void Auto(){
if( i==0 && selectmode ==0){
digitalWrite(relay1, HIGH);
timer2=timer.setTimeout(5000,OFF);}
}
void OFF(){
digitalWrite(relay1, LOW);
timer.disable(timer2);
}
void Manual(){
if(button2==1&&selectmode==1){
digitalWrite(relay1,HIGH);}
else{
digitalWrite(relay1,LOW);}
}
BLYNK_WRITE(V6){
button2 = param.asInt();
}
BLYNK_WRITE(V5){
selectmode = param.asInt();
if(selectmode ==1){
i=1;
led1.off();
led2.on();
timer3= timer.setInterval(1000, Manual);
}
else{
i=0;
led1.on();
led2.off();
timer1 = timer.setInterval(10000, Auto);
}
}
BLYNK_CONNECTED(){
Blynk.syncVirtual(V5);
Blynk.syncVirtual(V6);
}
Please donāt create multiple topics for similar issues on the same project. I have merged this latest question back into your original.
You need to supply much more detail on what you are trying to do, what you are needing help with, what you have already tried, etc. Not everyone on this forum is able or willing to figure out your whole code based on your own terms of āmanual and autoāā¦ I mean, manual and auto what, automotive transmission?
Ops. Iām Sorry. But im desperateā¦
So, The auto-mode is suppose to send pulse to relay and turn on the water pump for 5 seconds and idle for the other 5 seconds which is fine at first. Next, when user clicked on manual mode. This allows user to control the relay on/off via button2.
Now, the problem comes. When i switched back to auto mode, the time frame is not restored as the same for auto mode. 5s on and 5s off. The relay on/off almost instantly.
I bet thereās error here. But i just donāt get it.
I donāt understand what you are doing hereā¦ you donāt take a timer function and apply it to a variable.
Build your code in stagesā¦ Create two totally separate functions, one that works automatically in a non-blocking loop, using timers as you have tried.
Create a second function that relies on manual control, with itās own timers if necessary.
Then create a third function that chooses one of the two prior ones based on a button/switch stateā¦ no timers involved for that.
Properly name your timers and comment your code. Simple names like timer1, timer2ā¦ etcā¦ are too easy to get confused. And no one else will even bother trying to figure it out.
And finally, please understand that your cries of desperation does not guarantee quicker or better assistance, perhaps even the opposite, as others avoid what appears to be a potential hand holding session
Actually its perfectly valid, timer functions return an integer that represents that timers specific ID. With it the programmer can delete, enable and disable that specific timer
Iāll take a look after I watch my show
Just an fyi timer intervals canāt be changed, you must delete the current timer and create a new one in order to āchangeā intervals
This project works quite similiar to mine. So i follow what he wrote and auto-mode work like a charm. i delete the timer so it wont overflow to the next timer which caused an infinite cycle. YAY! Phew, after so many hours.
Yeah. Thanks Gunner and sorry
Another question, Can hardware receive sensor data from blynk uploaded by another device? through this method (with same auth token)
No apologies necessary! Glad you got it doing what you want it to [quote=āWesley, post:23, topic:13752ā]
Another question, Can hardware receive sensor data from blynk uploaded by another device? through this method
[/quote]
Not quite that method (but you can control multiple devices from the app with same or different auth codes) ā¦ but yes, sharing data from device to device can be done via bridge command:
Ay the variable name is just a way to call an object of the type Simpletimer, every simpletimer object can hold 10 timed events, and every event has its specific ID for manipulation
The type is SimpleTimer
You are a human
You call an object of Simpletimer, timer1
You are called doktor Emmet Brown
Timer1 can run ten timers
Emmet Brown can move ten fingers