Stack Exchange Network

Stack Exchange network consists of 174 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
44 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
37 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
28 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
47 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
35 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 ...
9
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
67 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
65 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
198 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() { // ...
0
votes
1answer
85 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
266 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
63 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
520 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
226 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
50 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
97 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
419 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
369 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
596 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
60 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
59 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
320 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
119 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
3k 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
387 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
116 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
615 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
149 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
228 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
261 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
145 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
253 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
150 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
903 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
3k 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
396 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
346 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
67 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
405 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
339 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
171 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 ...
0
votes
2answers
388 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 ...
0
votes
3answers
2k views

Arduino Blink two LEDs without Delay(amount of repetitions)

Arduino community. I have had experience with Arduino for 3 years now and have finally come to the conclusion to get rid of the delay function entirely. Below is the code to blink two LEDs a ...
1
vote
2answers
5k views

Converting `millis()` to decimal seconds?

I would like to get my Arduino to print milliseconds as decimals of seconds. For example, instead of printing 10456, printing 10.456 I have tried to set a float value or millis, and dividing by 1000 ...
1
vote
2answers
52 views

Make something happen on a continous input just once and for a specific amount of time

My project is very complicated, but here is a visual synthesis The input actually comes from a kinect, that detects a person position through Processing, which I connected via Serial to Arduino. ...
1
vote
1answer
466 views

Cycling LED's for specific time period with millis()

My goal in pseudo code is : only LED-6 HIGH for 6 seconds, then only LED-7 HIGH for 2 seconds, then only LED-8 HIGH for 4 seconds, then restart This is very easy with delay(), but I struggle with ...
0
votes
1answer
344 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 ...
1
vote
2answers
274 views

Delaying an action inside a function

My current function is supposed to play a sound effect, then after the sound effect is done (14 seconds), perform the next action (digitalWrite(CONTROLLINO_R1, LOW)). if (digitalRead(CONTROLLINO_A8) =...