A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [millis]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
66 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. ...
1
vote
1answer
35 views

My millis() code doesn't work

I am doing a project with bluetooth and an LED. I wrote a code which supposed to turn on an LED after it receives a byte of value 1 after 5 seconds, unless it receive another byte of value 1 (which ...
0
votes
1answer
36 views

I need to change this code to start the section of code when the switch is on and not when the switch is released

I have this section of code. It works fine and how I want it only, it executes when the button is released not when it is pressed. My application needs to execute this code when a switch is on. The ...
0
votes
1answer
29 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 ...
0
votes
1answer
63 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 (...
0
votes
3answers
74 views

Time counting using millis

I am trying to write a code where photoresistors (a or b) sense blinking of the light, and lights LED (k and d) simultaneosly with that blinking. And I want that when both photoresistors sense dark ...
0
votes
2answers
51 views

buiReliable time in ISR

I'm using a Nano. The code below is a simplified workup of my problem code. The point of it is asynchronous debounced button press detection. The actual code sets a volatile bool to tell the main ...
0
votes
1answer
82 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 ...
1
vote
1answer
115 views

Which is better millis() or timer?

I want to create a 30 minutes delay in my program (Arduino). which is better millis() or timer for this purpose? please give me an example to clarify my doubt ... Thanks.
1
vote
1answer
49 views

Arduino Timer0 Piggyback

As described here https://learn.adafruit.com/multi-tasking-the-arduino-part-2/timers I use timer 0 to get my own timer with a milliseconds resolution. It is setup like this: void setup (void) { ...
0
votes
0answers
113 views

Millis() does not back to zero after woke up from deep sleep mode

I am going to make a project that needs four boards of Arduino which synchronization in time is needed. The project is about capturing the timestamp (in ms resolution) whenever something is crossing ...
0
votes
1answer
85 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 ...
0
votes
2answers
160 views

Reaction timer using millis

I've written this code for a reaction timer game. The reaction time is to be displayed in milliseconds to the serial monitor as accurately as possible. The reaction time is not being displayed ...
2
votes
0answers
58 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
135 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
134 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
70 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
279 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
73 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
82 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
41 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
34 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
114 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
39 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 ...
14
votes
1answer
2k 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 ...
1
vote
1answer
224 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 ...
-1
votes
1answer
152 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
3k 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
463 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
539 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
170 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
1k 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; ...
1
vote
0answers
80 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
140 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
813 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 ...
2
votes
1answer
962 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
2k 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
86 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
80 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
770 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
225 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 ...
1
vote
2answers
7k 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
779 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
217 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
1k 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
244 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
361 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
731 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 ...
2
votes
1answer
6k 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
252 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 ...