# Questions tagged [millis]

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

162 questions
Filter by
Sorted by
Tagged with
0answers
88 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; } ...
1answer
1k 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 ...
1answer
317 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 ...
3answers
512 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 ...
2answers
599 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?
2answers
50 views

### Display upTime using `millis()` - Arduino Uno

I want to use the following function to display MCU's uptime, but after several hours I get error. void uptime(char *ret_clk) { byte days = 0; byte hours = 0; byte minutes = 0; byte seconds = ...
2answers
81 views

### Issue with simple project

I'm new to Arduino and today I have a problem with this code: int led_1 = 10; int led_2 = 11; int led_3 = 12; int button = 3; int time = 0; byte val = 0; void setup() { // put your setup code here,...
1answer
40 views

### Using millis() in unsynchronized manner

I am assuming millis() is a Timer ISR function. If so : When using millis() as mentioned in Arduino Reference : unsigned long currentMillis = millis(); What would happen if the ISR asynchronously ...
1answer
155 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] = ...
1answer
713 views

### Faster and lighter approximate timing code without using timer

I want to use loop() iterations counter to execute some tasks periodically or tasks like debouncing. My other sketch is running every loop() at least 20 ms, and if i am using 5 ms time to wait to ...
3answers
1k views

### millis() function always returns same value

I'm trying to program an Arduino MKR1000 and I am using the millis() function to emulate a traditional timer. The problem is that any call to millis() inside the debounceTimer() function returns the ...
1answer
42 views

### Why does my servo execute an action in the beginning when the odds are almost 0?

I made a servo motor turn if the result of random(0, 10000) is less than or equal to 1. If that is the case, the motor turns to 130 degrees, to 50 degrees, and then to default position(90 degrees). It ...
2answers
57 views

### How to call multiple delayed functions using a single millis()

I am working in a project where I need to call more than 1 functions actually 4 functions using a single millis() Here is the code below. unsigned long then = 0; void loop(){ unsigned ...
2answers
626 views

### How to keep track of millis during sleep mode

In my application, I need to keep track of the time the application has been running as well as use sleep modes. However, when using the sleep modes, Timer0 is disabled, and therefore millis stop ...
1answer
290 views

### How do I put timers by using millis on 3 PIR sensors?

I want to make the PIRs to stay on for about 1 minute. I've found the code that can do so for 1 PIR, but I dont know how to apply the code for 3 PIRs. Here is the code for 1 PIR with timer using ...
1answer
298 views

### How to reset millis( )?

I am currently doing a school project. There you have to program a stopwatch with the Arduino. I wrote a program where millis starts. But when I press my start button, millis don‘t start from 0. ...
1answer
53 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 ...
1answer
189 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 ...
1answer
1k 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 ...
2answers
359 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 ...
3answers
163 views

### Millis…alternate flash

I thought I had the Millis() command sorted but i'm stumped on the one. Aim is to get 2 led's alternately dimming, they work great with delay(); of course....but i can't figure where i'm going wrong ...
2answers
523 views

### What am I doing wrong with my millis()?

Im new to Arduino and have been trying to use the millis() function for an assignment of mine. I have had a lot of trouble trying to get the millis() function to work but now it seems to be working ...
1answer
1k views

### Change from using the external crystal to the internal oscillator

BACKGROUND I have made my own Arduino PCB based on the circuit of the Arduino Pro Mini (below) (including the external oscillator). I have already written the firmware and the code is stable. The ...
1answer
761 views

### How to delay outside loop

I am using a function outside loop(), which is called after an interrupt. Inside this function, I am setting several relays that need to change after a second or two, depending on my setting. I tried ...
1answer
108 views

### Arduino Blocks at Uploading

I am trying to make an operating hours counter with arduino, i started with a basic script to make the arduino work as a stop watch, This is my script: unsigned long start=0, finish=0, elapsed=0; ...
1answer
62 views

### Arduino stuck in PT_WAIT_UNTIL

I am using the Protothread Library from Adam Dunkels. It is supposed to wait 1 second and then continue. But instead it gets stuck there and everything after that line is not executed. lastTimeBlink = ...
1answer
65 views

### how to ignore a sensor being tripped the first time and start recording millis on the 2nd time it is tripped

I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts. when it drops it will trip the 1st sensor starting to ...
3answers
60 views

### restart counter of elapsed millis willingly with read

When I trigger high it will count for as long as I ask it while I am high then shut off. I am able to start counting again whenever I want by triggering low and going back to high and it starts from ...
2answers
165 views

### Restart sequence of NeoPixel stick with a push button at any time

I am really happy with my new Arduino stuff and playing around with all those pixels :). I am new to programming and it's difficult to understand it, but with every success, I grow in knowledge. My ...
1answer
40 views

### How to execute commands over desired amount of time

I have a program that receives 4 commands on 4 channels to change the color of an LED using mqtt communication. Lets just focus on two of the channels, the time and the red. I am sending a length of ...
1answer
203 views

### millis() function works with inline code and gives output but when creating own library it doesn't works

I am creating library for GPS to use in my project. I am using Adafruit GPS and its library to create my own library in which I am using millis() function to display the GPS Location after 1 minute (...
1answer
221 views

### Stepper motor based clock movement with DS3231

I am working on a clock movement that is powered using a stepper motor and the GSM2 driver board. The delay between steps needed to achieve 1 rpm on the second hand works out to 25 ms. In my current ...
1answer
97 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 ...
1answer
41 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 ...
1answer
651 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 ...
1answer
119 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
1answer
178 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 ...
1answer
2k 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, ...
1answer
304 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 ...
2answers
738 views

### Press on pressure sensor once, turn on LED for 6 seconds

I am working on a project where I would like to press on a pressure sensor (0-1024) once and turn on the LED and turn off by itself after 6 seconds. I am quite new to arduino and I can't seem to ...
1answer
874 views

### Using millis() function to start at potentiometer reading

I am trying to use the millis() function to start a countdown of 3 seconds when I turn my potentiometer to high travel. My code so far starts the timer at the beginning of the loop or when reset is ...
3answers
761 views

### Time.h rollover after 49.7 days [duplicate]

I'm developing a arduino based system, which includes a alarm system. Searching on the Internet, I found these lybraries "Time.h" and "TimeAlarms.h". In the requirements, it says: "Time does not ...
2answers
169 views

### Sketch does not work without delay() or other complex functions like digitalWrite()

I have a simple sketch here that should just blink a led once a second or so (approximately): boolean onOff=true; int count=0; void setup() { pinMode(13, OUTPUT); } void loop() { count++; ...
1answer
932 views

### ATtiny44 millis() not working with 16 MHz external clock

I'm using ATtiny44 with Arduino IDE according to this tutorial: http://highlowtech.org/?p=1695 I have a problem with millis(). When I use an internal 1 MHz clock it works correctly but when I use ...
2answers
358 views

### How do I set the motor state to “HIGH” at the beginning of this sketch?

My intent with this sketch is to have motors run for one minute, then stand by for 18 minutes. In practice, the sketch starts the motor state at "low" for the OffTime interval, then goes to the OnTime ...
0answers
37 views

### What happens if Millis() method variable goes out of it's capacity? [duplicate]

I am now working on a project which is expected to last at least 5 years from the time it is completed. In that project, i can not use delay() for some purposes so I am using millis() method unsigned ...
0answers
45 views

### How to get delay after millis and stop the relay

thats my flowchart for my code void loop() { //-------------Fungsi Read sensor----------- sensorAll(); hasilec = (ppmcensor - inputec); ph = (phcensor - inputph); // hasilec = random(...
0answers
50 views

### IR Remote Breathing effect

Hı everyone I am trying give my led a breathing effect using millis() But neither led isnt breathinng and it stucks I cannot use other fucntions. Please help... #include <IRremote.h> #define ...
0answers
22 views

### Change delay function to millis function to play music2 [duplicate]

I'd like to write a code by changing the delay function in the music playing code to the millis function, do you know how? #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 ...
0answers
134 views

### Run a dc motor for amount of time without delay

Hi everyone I have a project and I need to run a dc motor for amount of time without using delay I use DelayWithoutBlink technique. In this code the motor should run for 5 second in cw then it will ...