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
44 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
69 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
57 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
87 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
45 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
83 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
75 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
147 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
57 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
112 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
112 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
67 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
243 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
62 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
76 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
97 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 ...
13
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
201 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
146 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
2k 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
400 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
500 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
127 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
78 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
137 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
742 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
877 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
80 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
77 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
710 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
208 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
6k 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
709 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
200 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
233 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
341 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
657 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
5k 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
236 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
427 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
5k 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
160 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 ...