Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 vote
3 answers
1k views

How to rewrite code in millis?

I am currently working on a project that makes a plateua move back and forth using a stepper motor. On this plateau I have attached LEDs that create patterns. However, the plateau should be moving ...
user avatar
1 vote
4 answers
1k views

need help for saving the millis function when arduino was rebooted

I have two questions want to ask I'm using Arduino Uno with 16*2 LCD Blue ( also I have temp. sensor and two motors also 3 limit switches) ,, my code is working good, but sometimes my lcd stop ...
user avatar
1 vote
3 answers
141 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 ...
user avatar
1 vote
2 answers
3k views

How can I made my Arduino follow the time exactly?

I am making an Arduino clock. You can set time to it, and then it keeps on going. The problem is that it is always within a minute off. It is not a major issue, but one that I would like to fix. I use ...
user avatar
  • 300
1 vote
2 answers
3k views

How to simulate delay() to debounce mechanical button using millis()?

Im trying to use the millis() function as a replacement for the delay() function in order to debounce a mechanical button. This is for an electric drum kit I am building. Im using a teensy Arduino to ...
user avatar
1 vote
1 answer
83 views

Random Blink with millis()

i'm trying to make a sketch where my led blink with random delay. I have 2 functions: ledBlink() and randomBlink(). the second functions get as delay parameter a random number "r" generated ...
user avatar
  • 23
1 vote
2 answers
297 views

Running Arduino with 2 outputs and 2 inputs

Totally new to Arduino, 3 weeks old! I am doing a project with 2 inputs (2 x ultrasonic sensors) and 2 outputs (buzzer and send SMS) The code to run the buzzer and sms works perfectly individually. ...
user avatar
  • 31
1 vote
2 answers
2k 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; ...
user avatar
  • 13
1 vote
3 answers
193 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 ...
user avatar
  • 109
1 vote
2 answers
4k views

run two motors in turns without using delay()

I googled solutions and tried, but I still cannot get it working. I've tried BlinkwithoutDelay. I feel it is very confusing to track timing of two motors (i.e., step, direction, speed) for the ...
user avatar
1 vote
1 answer
161 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.
user avatar
  • 452
1 vote
2 answers
573 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 ...
user avatar
1 vote
3 answers
145 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. ...
user avatar
  • 51
1 vote
1 answer
545 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.
user avatar
  • 29
1 vote
1 answer
121 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) { ...
user avatar
  • 41
1 vote
2 answers
97 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 ...
user avatar
1 vote
2 answers
217 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 ...
user avatar
1 vote
1 answer
248 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 ...
user avatar
  • 452
1 vote
2 answers
199 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 ...
user avatar
1 vote
1 answer
32 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 ...
user avatar
1 vote
1 answer
82 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 ...
user avatar
1 vote
2 answers
9k 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 ...
user avatar
  • 176
1 vote
1 answer
1k 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&...
user avatar
1 vote
1 answer
1k 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 ...
user avatar
  • 1,468
1 vote
1 answer
2k 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 ...
user avatar
1 vote
2 answers
11k 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 ...
user avatar
1 vote
2 answers
62 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. ...
user avatar
1 vote
2 answers
436 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) =...
user avatar
1 vote
1 answer
163 views

How come my code does not wait for a specific time before going into an if statement?

I have an HC-SR04 attached to a servo. When the 90 degree reading is less than 30 cm, I want the motor to take 2 seconds to turn to 130 degrees, get a measurement on the right, and turn back to 90 ...
user avatar
  • 300
1 vote
3 answers
936 views

trying to use millis()

I'm learning how to use the millis() function. Instead of having it in the main body of the program I wanted to place it in a function so I can change the time interval with which an led will flash. I ...
user avatar
1 vote
1 answer
1k views

Is it possible to replace this delay with millis()? (And issue with other millis loop)

I am working on updating a project and I have a thread over in the Arduino forum which helped me out, but I'm a bit stuck, and there isn't much activity going on there. This code is for use with a ...
user avatar
  • 11
1 vote
3 answers
973 views

Managing timer intervals using millis at random intervals

I am doing a project which needs to meet the following specifications. On receiving an SMS arduino will start switching 1st relay on after some time duration(say 30 Seconds) relay 1 will be ...
user avatar
  • 167
1 vote
1 answer
120 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'...
user avatar
1 vote
1 answer
81 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) ...
user avatar
1 vote
1 answer
72 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 avatar
  • 177
1 vote
2 answers
158 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 ...
user avatar
1 vote
1 answer
64 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 ...
user avatar
1 vote
2 answers
267 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 ...
user avatar
  • 11
1 vote
1 answer
236 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....
user avatar
  • 113
1 vote
1 answer
282 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 ...
user avatar
  • 13
1 vote
1 answer
1k 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 ...
user avatar
  • 790
1 vote
1 answer
191 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 ...
user avatar
  • 13
1 vote
2 answers
531 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 ...
user avatar
  • 109
1 vote
4 answers
4k 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 ...
user avatar
1 vote
1 answer
1k 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 ...
user avatar
1 vote
2 answers
4k views

How often can I ping an HC-SR04 ultrasonic sensor?

In my current project, I want the sensor to be continuously scanning for a value of less than 30cm. I was wondering how long of a delay I need (if any) between each call of the ping function. It ...
user avatar
  • 300
1 vote
1 answer
1k views

millis() in a millisecond stopwatch

I'm making a stopwatch that will measure time between two points. I want that stopwatch to have a millisecond accuracy. After the start when someone touch the pad it will show like the time of the ...
user avatar
1 vote
2 answers
3k views

Why doesn't my 7 segment update every second like in the program?

I used sevseg.h library to write numbers to my 4 digit seven segment. The display should update every second with the current time since program started running. This is my code so far: #include <...
user avatar
  • 300
1 vote
1 answer
2k views

millis() not working properly

I'm doing a little project that, on a press of a button, will light up three LEDs and then will turn off the LEDs in different times. I'm using the millis() function to control the time that each LED ...
user avatar
1 vote
2 answers
773 views

Is it correct to use pulseIn() in ISRs?

Since it is not right to use millis() in an ISR to calculate duration of the input, Is it correct to use pulseIn()?
user avatar