Hot answers tagged

9

Several options here, and a couple folks have pointed out some challenges. "Best" answer -- probably to use a real-time clock (RTC) board to assist your timing, and effectively set a target time (next motor run is at 23:14...) each time the cycle restarts. By saving this target off (to the EEPROM or an SD card for instance), you'd protect against ...


3

Since this is for an incubator, I suspect that you don't need high precision. So delay() will work perfectly well, if you don't want to do anything else in the meantime (like maybe monitor temperature, control a heater, and/or light LEDs for over/under temperature). In that case you could use a loop that handled all those operations at some convenient rate ...


3

Using delay() for a 6-hour delay is a bit awkward, but perfectly doable. It will, however, not be very accurate, because the accuracy depends on the accuracy of the Arduino's clock, and it will block all other code you may wish to run. Using timing with millis() would allow your Arduino to do other things while waiting. It will be just as inaccurate, though. ...


2

Try strptime from the time.h. void setup() { struct tm tm = {0}; char buf[100]; // Convert to tm struct strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); // Can convert to any other format strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm); Serial.printf("%s", buf); } void loop(...


2

I have an automatic watering system that (among other things) trigger on time. I use the excellent Timer Library for this. It allows several useful timed interactions such as Pulse or Oscillate in addition to After which would solve your issue - or Every if you want a recurring 6 hour code block to execute In the end - behind the screen - it is just as ...


2

As well as specifying your IP address and gateway you also have to provide DNS server addresses. These are normally provided by DHCP, and the ESP8266 doesn't assume that it's the same as your gateway address when using a static IP address. Normally you would use your router's IP address as your DNS server address, but you can also use the Google public DNS ...


2

The way to go depends on the time range, that the event will have. The Arduino framework already includes a function for timekeeping: millis(). It returns the number of milliseconds since the startup (much like a clock) and measures the time via the hardware Timer0 and it's interrupts. This function will work good in the 2 digit millisecond range and above. ...


2

You can not trust system-level structs for data storage or transfer between different systems. The main reasons are: Different data type sizes (16 / 32 / 64 bit ints, floats vs doubles, etc) Struct element alignment differences owing to underlying architecture optimizations and limitations Unless you are working with a system struct that is specifically ...


1

Another way to solve this problem is using cronAlarm. It can provide precise control on timings and you can schedule your job also. https://www.arduino.cc/reference/en/libraries/cronalarms/


1

See this answer for an explanation. Using unsigned variables, and subtracting will definitely work. Not only will unsigned variables not become negative (by their very nature) but the rollover will be handled smoothly and accurately.


1

You could do something like this: unsigned long startTime; unsigned long elapsedTime; // Any needed setup stuff void setup() { ... } void loop() { // Wait for input to go high while(digitalRead(2) == LOW); // Start timing startTime = millis(); // Wait for input to go low while(digitalRead(2) == HIGH); // Now wait for it to go high again ...


1

As I said in a comment, if you really need to compute that moving sum, you absolutely need to store the last 60 one-second counts in memory. That being said, there are a few small issues with this code for which I would have some suggestions: There is no point in storing totalCount. You do not really use it, and it will eventually overflow. You do not need ...


1

Use External Interrupts is the short answer. Longer version: You probably want to make a buzzer system like what in family feud game show. I assume you are using Arduino UNO/MEGA and or having experience with programming. 1/ Use INT0 and INT1 for button 1 and button 2. When an interrupt is raised, the mcu jumps to a specific address to run the interrupt ...


1

If you use Arduino IDE with <ESP8266WiFi.h> there is a different order for the arguments in the config-statement See the comment in the source code: //ESP argument order is: ip, gateway, subnet, dns1 //Arduino arg order is: ip, dns, gateway, subnet. So after lots of trouble i changed my config in WiFi.config(STATICIP, DNS1, GATEWAY, SUBNET) and ...


1

#include <SoftwareSerial> SoftwareSerial s1(5,6); void setup { s1.begin(9600); s1.setTimeout(50); //sets the timeout of parseint() to 50ms } Please note that lowering the timeout too much can cause errors, i would not go below 10.


1

The X-axis is fixed and nothing gets plotted on the X-axis. It has its own divisions and they are automatically set by the Arduino IDE. The Arduino IDE still has to do some improvements to its software so that the X- axis can be adjusted and plotted too! This is my experience so far and corrections are welcome!


Only top voted, non community-wiki answers of a minimum length are eligible