Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [millis]

Is a standard library function. It returns the number of milliseconds since the Arduino board began running the current program.

0
votes
1answer
18 views

millis() replace delay() question

// each "event" (LED) gets their own tracking variable unsigned long previousMillisLED12=0; unsigned long previousMillisLED13=0; unsigned long previousMillisLED3=0; // different intervals for each ...
2
votes
0answers
51 views

Why would using the += operator on an unsigned long crash my sketch? [closed]

I wrote a simple Timer class that's designed to work even in the face of the 49 day wrap of the millis() counter. I wanted a library that I could easily re-use and I could never remember the right way ...
1
vote
0answers
46 views

Millis() is Not Working

I have a sketch that uses two timers using millis() from a library I created to keep time. The timers seem to be working correctly, but when I print the start time of each timer, it is clearly wrong. ...
0
votes
0answers
48 views

Stepper wait for X seconds in a loop with millis (not delay)

In the code below I would like the stepper to bounce back and forward between two limit switches and while it is doing this it should turn and than wait for e.g. 1 second. I thought I could achieve ...
0
votes
1answer
55 views

Arduino stops logging data after ~32761 seconds

I made a small set up to log temperature on SD card, everything is running smoothly until it reach 9:06:01 of logging that is 32761 seconds. I know that corresponds roughly to the maximum value of an ...
-1
votes
1answer
58 views

How to use millis instead of delay on Arduino for independent time intervals for two output pins

I wanted to use millis for the code below but stuck in between . can anyone help to change the given code to millis? Code here: void set(){ digitalWrite(on, HIGH); // turn the motor on (...
1
vote
1answer
46 views

Measure Sofware Serial write() time

As you probably know, SoftwareSerial uses Interrupts to do some of the timing stuff of the Serial communication. What I am trying to accomplish is to measure the time that it takes SoftwareSerial....
0
votes
1answer
54 views

to measure the time between the ON signal and OFF signal

int pin_state = LOW; struct Channel { byte pin; byte state; byte count; unsigned long fell, rose; }; const int CHANNEL_COUNT = 3; Channel channels[CHANNEL_COUNT] = ...
0
votes
1answer
39 views

Detecting the down time of a system by subtracting the time when the sytem gives ON signal and when it goes OFF

int pin_state = LOW; struct Channel { byte pin; byte state; byte count; unsigned long fell, rose; // times of fall and rise }; const int CHANNEL_COUNT = 3; Channel ...
0
votes
1answer
30 views

Elapsedtime variable not resetting

I am new to Arduino programming. Let me describe the application I am working on. I am pressing a button for a certain period of time (30 sec). I can not hold it in a pressed position for all the time....
0
votes
1answer
55 views

Regarding running multiple functions using millis

I have been writing code for measuring when the digital signal comes and goes (ON and OFF respectively). I have done the part calculating a single system's downtime (difference in timings between ON ...
0
votes
1answer
38 views

Button that gives an Input, Has a small delay — then gives another [closed]

I'm pretty new to the Arduino scene, and my question will likely be solved simply by some more experienced fellows. I'm trying to create a code for a switch/ button that when you press it, it ...
10
votes
1answer
1k views

How millis() resets itself to 0

Looking at the documentation for the millis() function , it says: Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back ...
0
votes
1answer
90 views

How to write a script if water sensor comes into contact with water for more than 2 mins and LED lights up

I am a newbie to arduino and programming. I would like to come out with a code for water sensor to detect the presence of water for more than 2mins before lighting up the LED lightbulb. Currently ...
0
votes
1answer
74 views

Using mills() in place of delay() on relays not getting solid switch over

I know I should post some code that maybe cleaner but really I am just in need of a answer to a problem I seem to run into a lot when using mills() in place of delay(), whilst making a Christmas light ...
2
votes
1answer
445 views

nodeMCU - Millis() - Simple Counter - How long is LED on?

PROGRESS, now I have this (WITH GREAT HELP): void setup() { Serial.begin(9600); // initialize digital pin 13 as an output. } uint32_t timer_start = 0; int timer_running = false; void loop() { // ...
1
vote
1answer
164 views

Use MQTT to update internal clock

I write code to upload to ESP8266. I wish to use time stamp in order to log events. I found an NTP sketch, I can work with ( since it has a wifi connection ), but I wish to keep my code as simple as ...
0
votes
1answer
339 views

Function Millis() Arduino

I would like to make a countdown with arduino. To do this I'm using the millis () function, but I have a problem, I can not reset this. Reading on the internet I read that it is not possible to do ...
0
votes
2answers
71 views

Does delay() pause the counting of millis()?

If I add a delay for a few seconds, and then will the value given by millis () be equal just before and after delay? Or to put it in other words, does the internal clock of Arduino stop during delay?
1
vote
2answers
712 views

Issue in long ON OFF timer using millis()

I have 3 components: a relay and two LEDs...I want two timers using Arduino... In timer one, relay should be off on; one LED is off; and other is on...In second timer, relay is off; one led is on; ...
0
votes
0answers
279 views

Counting pulses of a signal between 2 pulses of another signal

I set an Arduino Nano to read the time between 2 pulses of a signal (kind of rotary encoder) to get and display an rpm value. I've done this using interrupts. Now I'd like to add a second (kind of) ...
1
vote
0answers
59 views

Storing random and different values of millis() while inside a loop? [closed]

Is it possible to store a value of time while you're inside a loop? Entertain the condition: if (condition && value > 0) { timeTrans = millis() + 2000; timeTrans - millis() = value; } ...
1
vote
1answer
115 views

Slowly decreasing the speed on a steppermotor over time

I am currently working on an elevator for my examsproject in school. It's a quite simple simulation of a lifesize elevator. I'm currently using a steppermotor for the elevatorchair and it's set with ...
0
votes
1answer
479 views

LED Strip Effect without delay

so a brief introduction about the project which I am working on before I go onto my issue. I am working on a love-o-meter project (Not similar to the arduino example), whereby 2 people place 1 of ...
1
vote
1answer
509 views

Does millis() work inside a function?

So I know that millis() doesn't work how it's suppose to if you use it in an interrupt but lets say we have a code that looks like below, will millis() work properly or how it behaves in an interrupt? ...
2
votes
1answer
891 views

How to set the sampling frequency in Arduino without using a delay

I am reading an ECG signal using a single lead heart rate monitor. What I know is that when I use delay(15) it means that I am getting 66.67 readings in a second which corresponds to the sampling ...
0
votes
1answer
64 views

Using time function in arduino

how to get exact timestamp of a sensor reading and compare it with other sensor values in arduino? Ex: Get the time of low reading of LDR and compare it
0
votes
1answer
63 views

How to replace the delay() function in my code?

I'm new to Arduino and I currently have a project that involves the control of an LED via ultrasonic sensor. Basically, if an object passes through the ultrasonic sensor, the LED will be ON for 5 ...
0
votes
1answer
426 views

uno timer0 prescale

I have a project where I need to get a low frequency to get a pwm suited from my project. The problem is that after I modify the frequency of timer0 the millis() becomes slower or faster depending on ...
0
votes
2answers
136 views

Hold all “millis()” values in an array?

I'm working on a project where I could have up to six devices connected to an arduino, it might be the case that not all of them will be attached at the same time, and all of them need to be able to ...
0
votes
2answers
4k views

Arduino Vending Machine to monitor coin slot input while waiting for user input

I have this project called Onionskin Vending machine. The function should be: when a coin is inserted, the pulses from the coin acceptor (which is not accurate sometimes so i didn't use ...
1
vote
1answer
480 views

LCD Clock Millis Code Issue

I am trying to create a clock on an LCD when I upload the code below, all it displays is a very rapidly flashing 0:00 PM. Please help. This is my first time using Millis. #include <LiquidCrystal.h&...
2
votes
3answers
139 views

How can I find the time taken while a function is being called? [duplicate]

I tried using millis, but I wanted to know if there is any better way to find out the exact time from when a function is called and finally when it terminates.
0
votes
1answer
696 views

Using millis() to time the start / stop of a DC motor

I'm trying to use a DC motor with pinion engaged to a rack gear, and have that motor move a distance, save the distance, delay, reverse, and travel back the same distance from where it started, delay, ...
0
votes
1answer
176 views

What is wrong with my state machines?

My goal is to make an automatic gate and garage door, and it has a servo as the lock mechanism on the gate, and alarm systems that notify when the gate or garage door is open too long, more than the ...
0
votes
3answers
264 views

Why doesn't millis() use 1 µsec or 1 msec interrupt?

Arduino millis() does not make use of one millisecond interrupt. Instead they make use of 1,024 µsec interrupts and manipulate. Any specific reason why this was implemented this way? In one case, we ...
1
vote
1answer
350 views

How to start particular event for particular time using millis()?

In my recent project, I want to run particular event for the particular time. For example, If I want to Turn ON my LED for 20 Second. And rest time LED must be off. I know using delay() it is possible ...
3
votes
1answer
3k views

Button with switch timer and reset time function + LED feedback. What am I doing wrong?

Beginner here. I´ve been trying to implement a button function timer working with millis() instead of delay as I want the button to be responsive while the timer is running. So far I´ve managed to ...
-1
votes
2answers
164 views

Arduino millis() fuction execution problem

I am new to Arduino development. I want to use millis function instead of delay because delay is blocking further execution of program. Program description: In this code I want to control 2 solenoid ...
1
vote
2answers
314 views

State Machine Logic problem with added states monitoring safety switches

I have been working on getting a state machine to work correctly but am having trouble with adding in the last bit of logic. What it needs to do is several things: Read two button inputs. Make sure ...
1
vote
5answers
3k views

Using millis(), in nested loops

I am using millis() to flash some lights (neopixels) on an arduino pro mini. The problem is that I cannot flash the lights for the desired period. More specifically, the lights flash for ~250 ms, ...
1
vote
3answers
155 views

Problem with Dual Safety Switches Initiating Timed Relay

I have been working on an Arduino project that has me kind of stumped. What it needs to achieve is that two momentary safety switches need to be pushed and held within a specified time frame as ...
1
vote
1answer
1k views

How to keep a 24 hour maximum and minimum temperature

I am keeping a simple weather station to monitor humidity and temperature in my greenhouse. I have a ds18b20 and dht probes. everything works great and I even used a little trick to hold my maximum ...
1
vote
4answers
4k views

Use timer0 without affecting millis() and micros()

I'm writing a library which needs an ISR to turn off an LED some time after it was turned on. Since it's all about turning an LED on and off it doesn't need to be very precise. On the other hand I ...
1
vote
1answer
491 views

Measuring distance based on time [closed]

I have written a arduino sketch which is used to measure the distance travelled. Since distance = speed * time , I have initiated speed = 6. I have initiated time = millis() variable and it calculates ...
-1
votes
1answer
402 views

Countdown sometime stop

I've made a game with 3 countdowns and 1 global countdown. When we start, the global one, go from 45:00 to 00:00. The 1 go from 15:00 to 00:00 and if it reach 00:00: The 2 start and go from 15:00 to ...
1
vote
1answer
73 views

PIR sensor code logic works on Mega but not on Yún

I am trying to use this example(it works on Arduino Mega): millis() - lowIn comes greater than 5000when motion ends. ///////////////////////////// //VARS //the time we give the sensor to calibrate (...
2
votes
1answer
481 views

Pause in the program for some time

I have a variable timeInSec which records the time as loop begins. It is defined as timeInSec = millis();. I have two conditions. If (timeInSec - lastRun)< 5 (that is 5 sec) , the first condition ...
2
votes
2answers
378 views

timer0_millis always returns 0

I am trying to make a simple debounce function as explained here but the condition if((millis()-timeCheck)>reboundDelay) is never met. As you can see in my code below, I am trying to control a PWM ...
1
vote
1answer
188 views

Calculating with millis()

The following code works fine until I turn the if (tijd - action >= 500) into if (tijd - action >= 1000) I wonder why this fails. If I just loop and print the tijd - action it has no problem ...