Probably a misplaced bracket or missing clsoing bracket somewhere. Those are the worst errors to debug.
These are simple C++ compile errors.
You need to check over your code for extra brackets.
Ok now work all very good!
thanks very very very much!!
Not to steal the Lufkin’s tread - but is it possible to use several timers (SimpleTimer) objects on a Nano board?
I tried declaring multiple timers, but using more than one crashes the board continuously.
Used a method aprox. like this:
#include <SimpleTimer.h>
SimpleTimer timer;
int t1 = 1;
int t2 = 2;
void setup(){
t1 = timer.setInterval(5000L, tf1);
t2 = timer.setTimeout(12000L, tf2);
}
void tf1(){
//do something..
}
void tf2(){
//do something..
}
void loop(){
Blynk.run();
timer.run();
Haven’t been able to finde an NANO example with multiple timer-objects. Has anyone tried something similar?
BR
Can you further define “crashes”? A Nano is going to run similar to an UNO, so it is more likely your code is incorrect or something else is the issue, not just because it is a nano.
Can you paste your actual code instead of your aprox example?
I think your issue might be in how you have set yours up: e.g. tx = timer…
Here is how I have mine, running fine on an Mega, Uno and Pro Micro
#include <SimpleTimer.h>
SimpleTimer timer;
void setup(); {
timer.setInterval(500L, AnalogSensors); // Misc analog sensors on CodeShield
timer.setInterval(500L, whiteLED); // White LED on CodeShield
timer.setInterval(1000L, thermTemp); // Thermistor on CodeShield
timer.setInterval(1000L, clockDisplay); // Time and Date Widget
timer.setInterval(2000L, sendUptime); // Up Time Widget
timer.setInterval(5000L, sendTempHum); // DHT11 sensor read
}
void loop()
{
Blynk.run(); // Run internal Blynk functionality.
timer.run(); // Run timers
}
Yes by crashes I mean reboots. Starts up, goes into setup-loop, runs the code for some seconds and reboots - over and over.
The App tell me the device was disconnected every time. Led’s and println tells me that it restarts.
Thourght it might be a matter of resources on the board.
Will paste code.
Code not complete since I never got that version with timers working.
Difference to your example is that I have several timer-objects (instances of Timer) not just one Timer (timer)…
/*
PIN 3 = DHT
PIN 6 = Power Realy
PIN 7 = "Connection Lost"-warrning LED
PIN 13 = Work in pprogress - onboard LED
PIN A0 = Light sensor
VPIN V0 = Light
VPIN V1 = Humidity
VPIN V2 = Temeparature
Your basic bathroom ventilation controller - MMonitor humidity and light.
By light-change to over 100, trig relay after 5 min., after light-change to below 100 reset relay after 5.
If humidity is abowe 60%, trig relay until humidity is 50% - set timer for 1h - if relay stille active send pushnotification.
Send monitoring data to blynk and allow for remote manually override.
*/
#include "DHT.h" //DHT22 sensor library
#include <SimpleTimer.h> // here is the SimpleTimer library
#include <UIPEthernet.h> //Serial Ethernet module library
#include <BlynkSimpleUIPEthernet.h> //Blynk library
SimpleTimer timer; // Create a Timer object called "timer"!
//SimpleTimer t2Light; // Create a Timer object for relay hold after light off
//SimpleTimer t1h; // Create a Timer object for 1 hour warrning
//#define BLYNK_PRINT Serial
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //Delade DHT instance
const byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; //DE:ED:BA:FE:FE:ED
//IPAddress server_ip (192, 168, 2, 35);
//IPAddress arduino_ip (192, 168, 2, 179);
//IPAddress dns_ip (192, 168, 2, 1);
//IPAddress gateway_ip (192, 168, 2, 1);
//IPAddress subnet_mask (255, 255, 255, 0);
const char auth[] = "####"; //Token from Blynk app
int hum; //Stores humidity value
int temp; //Stores temperature value
int newLux = 0; //latest read lux
int lux = 0; //Light sensor read
int tLoop = 1;
int t2Light = 2;
int t1h = 3;
//const int ledPin = 13;
const byte warrningPin = 7;
const byte relayPin = 6;
void setup() //startup configurations
{
//pinMode(ledPin, OUTPUT);
pinMode(warrningPin, OUTPUT);
pinMode(relayPin, OUTPUT);
dht.begin(); //start DHT22 sensor
Serial.begin(115200); //start serial communication used for Ethernet module
Blynk.begin(auth, IPAddress(192, 168, 2, 35), 8442, IPAddress(192, 168, 2, 179), IPAddress(192, 168, 2, 1), IPAddress(192, 168, 2, 1), IPAddress(255, 255, 255, 0), arduino_mac); //Start blynk with Token, server IP, port
// while(Blynk.connected() == false){
//Serial.println("connecting to blynk");
//}
tLoop = timer.setInterval(5000L, tf); // Here you set interval and which function to call (time, function)
t2Light = timer.setTimeout(120000L, relayOff); // 2-min lights timeout to fan-start
t1h = timer.setTimeout(3600000L, relayOff); // Timer set to 1 hour
}
void hum1Hour(){
digitalWrite(relayPin, LOW);
Blynk.notify("FAN OFF - RUNNING FOR MORE THAN 1 HOUR!!");
}
void relayOff(){
digitalWrite(relayPin, LOW);
Blynk.notify("FAN OFF - LIGHTS OUT FOR 2 MINUTS.");
}
BLYNK_CONNECTED(){
digitalWrite(warrningPin, HIGH); //LED turns off when Bllynk is conneted once again
Blynk.syncAll();
Blynk.tweet("NANO Ventilation Connected");
}
void tf() //Timed functions goes here
{
// digitalWrite(ledPin, LOW);
hum = int(10.0*dht.readHumidity()); //Read humidity
temp = int(10.0*dht.readTemperature()); //Read temperature
newLux = analogRead(A0);
if(Blynk.connected()){
Blynk.virtualWrite(V2, (float(temp/10.0))); //Write temperature to virtual Blynk-pin
Blynk.virtualWrite(V1, (float(hum/10.0))); //Write humidity to virtual Blynk-pin
Blynk.virtualWrite(V0, newLux); //Read analog pin A0 and write value to virtual blynk-pin 0
// digitalWrite(ledPin, HIGH);
}else{
digitalWrite(warrningPin, LOW);
}
if(lux != newLux){
if(((100 - newLux) + lux) < 0){ // Light changed to on
}else if(((100-newLux) + lux) > 0){ // Lights changed to off
timer.restartTimer(t2Light);
}
}
lux = newLux;
if(hum/10 > 60){
if(digitalRead(relayPin) == LOW){
digitalWrite(relayPin, HIGH);
timer.restartTimer(t1h);
Blynk.notify("VENT ON from Humidity.");
}
}
else {
//Serial.println("else");
if(digitalRead(relayPin) == HIGH){
//Serial.println("if relay high");
digitalWrite(relayPin, LOW);
Blynk.notify("FAN OFF - Humidity below 50%");
timer.disable(t1h);
}
}
}
void loop() //main loop
{
Blynk.run(); //All the Blynk Magic starts here...
timer.run(); //Run timer
}
Try this instead…
timer.setInterval(5000L, tf); // Here you set interval and which function to call (time, function)
timer.setTimeout(120000L, relayOff); // 2-min lights timeout to fan-start
timer.setTimeout(3600000L, relayOff); // Timer set to 1 hour
Yes I can do that and that works - however I want to be able to restart the timers and suspend them independently.
Like this?
int t1;
t1 = timer.setTimeout(120000L, relayOff);
timer.disable(t1);
timer.enable(t1);
timer.toggle(t1);
Full doco: Arduino Playground - HomePage
Yes exactly - and that’s the example I used.
But just defining a second timer makes the board crash.
try not to define the t1 and t2.
Just declare them as int’s .
int t1, t2;
Pls help me…i have this error and i not understand
exit status 1
‘param’ was not declared in this scope
What ??
Thanks, i solved the problem
i have last question about this function
Now if i Press a botton (V12)
Relay Pin D5 start cycle and work is good!
but now i need to add other relay (when V12 are switch on) without cycle…only turn on
situation :
V12 ON
D5 pin cycle time
D6 pin turn on
V12 OFf
D5 Off
D6 Off
Can you help me to undestatand ths?
@Lufkin you want to control 2 relays, correct?
Are the 2 relays in any way connected in your project or are they both independent of each other?
If they are independent I would just duplicate all the code and make a minor adjustment to the variable names for the 2nd relay.
Hi Fettkeewl
i have a question
in your code if i press ON button, start with 20sec OFF and 10 ON
but i need to place inverse time…
when start — >> 20sec ON and 10 off
but i not understand …can you help me??
Thanks very very much
Just swap theese values