Skip to main content

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
1 answer
93 views

I am using millis () function but after one iteration it does not check the condition and enters the loop. What should I do?

I am using mq7 sensor where I have to toggle vcc between 5 to 1.5 V for 1 min and 1.5 min. For this I am using millis function.But after 1st iteration it skips the condition and enters the loop. The ...
Yukta Sanghvi's user avatar
1 vote
1 answer
108 views

Fixing a pedestrian traffic light sequence pattern in a cycle using millis and without delay

I was emulating the pedestrian traffic light cyclic pattern (red, green, green flashing) in the next Arduino code. But when I run this code with my ESP8266 Wemos D1 mini controller, it appears the ...
Hong Christian Lin Jiang's user avatar
1 vote
2 answers
417 views

Working with pulseIn() and millis()

I'm trying to use pulseIn with elapsed time using millis(), I don't want to use interrupts instead of pulseIn (I need pulseIn because I need accurate pulse time), the elapsed time doesn't need to be ...
Takata's user avatar
  • 71
1 vote
2 answers
1k views

Stepper motor micros (millis) non-blocking delay simple example?

I am trying to get a simple non-blocking replacement for: digitalWrite(stepPinX, HIGH); delayMicroseconds(500); digitalWrite(stepPinX, LOW); delayMicroseconds(500); This is what I tried, and the ...
adamaero's user avatar
  • 198
0 votes
2 answers
3k views

The same button with one click and double click [closed]

i hope to get some help with my code. I am trying to distinguish between a single press and a quick double press of the button with debouncing. I am making some silly mistake in my code and i can't ...
Carlos Costa's user avatar
0 votes
1 answer
183 views

Using Millis instead of delay to reboot relay

I want to reboot relay (turn off , waiting 4 seconds and turn ON) it works perfectly if I use delay(4000), but code is blocked while delay (4 seconds) and I cant start relay 2. How can I use Millis ...
vito's user avatar
  • 101
-2 votes
1 answer
282 views

LED blink patterns with multiple LEDs with millis() not using Delay()

I want to make LED blink patterns with multiple LEDs with the millis() function. I researched about it but did not find a perfect solution. I found one blog, but it is using a LED pin number array; I ...
coder's user avatar
  • 1
0 votes
1 answer
670 views

Milliseconds using square wave RTC

i am trying to make a code that prints the time hh:mm:ss:ms using RTC,i have made it using millis() but it is not accurate +/-2 milliseconds ho can i make it using sq wave and intterupt here is the ...
Amr Ahmed's user avatar
0 votes
3 answers
722 views

Using 1 ms delay() in a for loop to check inputs.. Bad?

So first off, I know millis() exists. Just asking out of curiosity. Say you have a button you wanna check for during a delay.. Maybe a 10 second delay. So you make a for loop that checks for input and ...
BobaJFET's user avatar
  • 135
2 votes
2 answers
991 views

Toggle button switches through case statements with button debouncing

The overview of my code is that I want a toggle button to be pushed and each button push will move the code to the next case statement. In each case statement, there will be different LED functions. I ...
Myles's user avatar
  • 73
2 votes
2 answers
87 views

Trying to keep my main code running unless an input is LOW for a certain amount of time

I have code that creates a sequential signal with 4 LEDS. It cascades to the right. This works when I hold down the input button. What I need help with is having the code run exactly the same when ...
Myles's user avatar
  • 73
0 votes
1 answer
366 views

Question about using millis for alarm conditions - Arduino

I am new to programming in general and to Arduino as well. I am working on a small project to improve my ability to write complete and kind of useful programming sketches. I am facing a problem. I am ...
Maher's user avatar
  • 9
3 votes
1 answer
974 views

How do I run 4 LEDs sequentially based off of a push button input?

I am trying to create a program that runs 4 LEDs sequentially while also being able to do other things with different inputs and outputs. Because of this, I am using the millis function and not the ...
Myles's user avatar
  • 73
0 votes
1 answer
323 views

Question about ElapsedMillis() library and state machines

I'm making a sort of state machine with 3 states, and I'm actually doing some tests by configuring at the start of my code state=3. I've wired on each pin 2 leds, for a total of 12 leds. I'm using ...
tommy's user avatar
  • 29
1 vote
1 answer
580 views

Assign a delay value generated by a random function called randomBlink()

I'm trying to make a sketch where my led blinks with random delay. I have 2 functions: ledBlink() and randomBlink(). The randomBlink use as delay parameter a random number "r" generated from ...
tommy's user avatar
  • 29
2 votes
1 answer
582 views

How to Independently run positional and continuous servos using millis()?

I am setting up 3 servos (2 position servos and 1 '360' continuous rotational servo) with Arduino. but I failed to run these independently. It runs one after another. I wish to run it in loop ...
Emlinux's user avatar
  • 43
2 votes
1 answer
382 views

Is there something that I need to do to make the code from this answer compile?

I tried to compile the following code (using Arduino 1.8.16 with an esp8266-12) extern volatile unsigned long timer0_millis; unsigned long new_value = 0; void setup(){ //Setup stuff } void loop(){ ...
TRS-80's user avatar
  • 21
5 votes
1 answer
868 views

Delay() and millis() functions don't work in cpp external files

I'm currently facing an issue using delay() and millis() functions in an external cpp file. The issue is that when I used delay() in my main program (meaning .ino file) it works well but when I call ...
Cyril_Ram's user avatar
1 vote
1 answer
1k views

How to reset ESP32 after a certain duration?

I would like to reset my ESP32 from the software, how do I do it and how to make it do this at regular intervals.
Coder9390's user avatar
  • 472
2 votes
2 answers
4k views

Arduino Reset via Software (every day)

Dear Stack Exchanger's, I want to reset my Arduino and system in every 24h for preventing frozen software and also other connectivity stuffs. I wrote a program which connects a digital pin to reset ...
Felix Pursian's user avatar
1 vote
2 answers
441 views

run a function for a certain amount of time! [duplicate]

i'm working on a project where i need to run a function for 20 minutes and the function writes to memory using EEPROM every minute. How can i make the function run for 20 minutes, i was thinking of ...
rohithrathod banoth's user avatar
2 votes
2 answers
1k views

How to write nonblocking code, for polling sensor at 100 Hz

I'm using this piece of code to try to poll an IMU sensor at 100 Hz (for a AHRS sensor fusion library). void loop(void) { // nonblocking code variables static uint32_t last_ms; uint32_t ms; // ...
Zhelyazko Grudov's user avatar
1 vote
0 answers
47 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 ...
Subha Jeet Sikdar's user avatar
3 votes
1 answer
91 views

Fader OOP Problem

This code works and it can fade three LEDs without any problem, obviously you can even add more of them : ) // Pins Definition const int button1 = 13; const int button2 = 12; const int button3 = 11; ...
alessandromrc's user avatar
1 vote
1 answer
542 views

Blink LED with different on off times just once with millis

So Im having trouble trying to figure this out. My project needs a valve to stay shut and when an event is triggered, 3 seconds into that event the valve opens for 2 seconds, then remain shut till it'...
Jason8899's user avatar
0 votes
2 answers
1k 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 = ...
guyd's user avatar
  • 1,049
1 vote
2 answers
979 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 ...
Subha Jeet Sikdar's user avatar
0 votes
1 answer
79 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 ...
EmbSysDev's user avatar
  • 103
1 vote
1 answer
1k views

How to use millis instead of delay? [duplicate]

Sorry if something similar has been answered before... I am working on a garden timer project that runs on a ESP8266 based NodeMCU and is integrated with Blynk. I have a waterNow function that ...
Coder9390's user avatar
  • 472
1 vote
1 answer
112 views

Millis timer question

Trying to figure out how to do this in millis. So right now the code works just fine, plays mp3_play(2) while a push button is closed then plays mp3_play(1) when its open. Lets say I want mp3_play(2) ...
Jason8899's user avatar
1 vote
1 answer
170 views

Get production count for current minute

I am trying to make a production counter for a machine. I want to display production count of the last minute for each seconds. So, display should update every second and should display real value of ...
user_fs10's user avatar
  • 187
0 votes
1 answer
3k views

ESP32 millis not working properly

I have a program which measures temperatures every 30 minutes and sends them to a database. Immediately after running the program the first measurement is sent, however, the second (which should be ...
Nina's user avatar
  • 185
1 vote
2 answers
621 views

Using millis() instead of delay() when playing a melody

I want to make my Arduino to play several simple melodies, and also be able to skip a melody by pressing a button and go on with the next song. therefore I cannot use delay() because the code should ...
Rsoc2002's user avatar
1 vote
1 answer
59 views

How can I remove the delays in this code for sweeping the servo?

I know this is probably a very asked question, but I am building a fairly basic radar type thing which sweeps left and right and uses an ultrasonic sensor to determine the distance to an object and a ...
SourOddity's user avatar
1 vote
1 answer
283 views

Issue with simple timer based on millis()

Sorry to bother but I am at my wits end. I'm experimenting with timers, and starting very simple. The following code is supposed to print the content of a variable each time an interval of time has ...
Zhelyazko Grudov's user avatar
1 vote
2 answers
290 views

Switch on the piezo emitter for a short time

I need a short beep for every minute of change. I wrote a separate function. The signal duration should be 50 ms, the rest of the time the emitter connected to the A1 contact should be silent. A ...
Антон's user avatar
1 vote
0 answers
26 views

error ph meter cant show the data [duplicate]

im using ph meter DFROBOT v1.0 at i compiled the code from the DFROBOT web this is the code * # This sample code is used to test the pH meter V1.0. # Editor : YouYou # Ver : 1.0 # Product: ...
daffa faiz's user avatar
1 vote
1 answer
283 views

Timing push button code

I am trying to time how long button is held for. The code seems to work but with two problems: the millis values are being read wrongly. If you hold the button for 1 second, it returns holdTime of ...
j83's user avatar
  • 19
2 votes
2 answers
1k views

smooth DC motor control with millis

So the task is to control 12v DC motor. With first button, you can add up motor speed by certain speed step. With second button, you can slow down motors speed by certain speed step. With third button ...
Jānis's user avatar
  • 59
0 votes
1 answer
182 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 = ...
hypertext's user avatar
2 votes
1 answer
107 views

Relays just switch ON and OFF on delay(), not on millis()

I use fuzzy logic for the running time of relays, but the relays just switch ON and OFF at the interval of the delay() I put at the end of loop. This is my code: void loop () { ph = -180/100.0; ...
daffa faiz's user avatar
1 vote
3 answers
187 views

Ignoring the first high output from the sensor

If the vibration sensor with Arduino detects two high inputs within 1 minute, I want the led to flash in one second. My ability to write Arduino code is very low; I tried with millis() but I couldn't. ...
Sabri73's user avatar
  • 51
2 votes
1 answer
260 views

Help with millis to get accurate timing

I'm essentially trying to create a music box which is light activated using an LDR. When it's open a song plays, while a servo rotates a figurine back and forth, and an LED dims and illuminates in ...
TonyStark's user avatar
1 vote
0 answers
175 views

how to control 2 sensor and 3 relay with fuzzy

i'm using fuzzy to decide how long the relay on pump on and i got some trouble for it he just looping on relay how should i do thats my code //---------Fuzzy 2.1 prelauch---------- //-----iNPUT ...
daffa faiz's user avatar
1 vote
2 answers
325 views

controlling 2 sensor and 3 pump using millis

i make a 3 pump for output and im using millis for it, i want to stop if rach the intervalm now in my code its still looping not realy stop for it thx int pump1 = 5;//pin D5 int pump2 = 6;//pin D6 int ...
daffa faiz's user avatar
2 votes
3 answers
516 views

How to use millis() in my code instead of delay()?

I'm having issues trying to convert my code to non-blocking. I was able to do so in some parts, but the rest aren't the same. When I try to replace delay with an if statement like the spinning and ...
KD Technology's user avatar
3 votes
2 answers
286 views

How to use Multipile millis()

I've a exhaust fan that runs when the humidity is high. When the exhaust fan is on it should work for 3 minutes and should wait another 5 minutes to on. I am a beginner to this struggling for almost 2 ...
user2037091's user avatar
1 vote
0 answers
122 views

Change delay function to millis function to play music [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? #include "pitches.h" // notes in the melody: int melody[] = { ...
alice's user avatar
  • 11
0 votes
1 answer
156 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 ...
chris's user avatar
  • 1
1 vote
0 answers
342 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 ...
yo777's user avatar
  • 23