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
2answers
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; ...
1
vote
2answers
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 ...
1
vote
2answers
84 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 ...
1
vote
1answer
36 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 ...
1
vote
3answers
123 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. ...
1
vote
1answer
392 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
96 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) { ...
1
vote
1answer
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 ...
1
vote
2answers
10k 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
1answer
983 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 ...
1
vote
1answer
35 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 ...
1
vote
1answer
26 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 ...
1
vote
2answers
115 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 ...
1
vote
2answers
231 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 ...
1
vote
2answers
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 ...
1
vote
1answer
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&...
1
vote
2answers
513 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
1answer
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 ...
1
vote
3answers
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 ...
1
vote
2answers
58 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
2answers
424 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) =...
1
vote
1answer
153 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 ...
1
vote
3answers
771 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 ...
1
vote
3answers
921 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 ...
1
vote
1answer
44 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'...
1
vote
1answer
67 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 ...
1
vote
1answer
75 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) ...
1
vote
1answer
42 views

Atmega Millis with Quartz crystal

I followed https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard this tutorial to program my Atmega 328p to run on a breadboard with a 16 MHZ Quarz crystal and two 22pF capacitor. I want to program a ...
1
vote
2answers
404 views

Using millis() to create a timed sequence of events

I was hoping anyone could help me with my problem. I am trying to play a sequence of tones without using delay. So I am relying on millis(). However I have not been successful yet and after reading ...
1
vote
1answer
48 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 ...
1
vote
1answer
199 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....
1
vote
1answer
274 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
vote
1answer
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 ...
1
vote
1answer
178 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 ...
1
vote
1answer
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 ...
1
vote
2answers
3k 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 ...
1
vote
1answer
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 ...
1
vote
2answers
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 <...
1
vote
1answer
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 ...
1
vote
2answers
726 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()?
1
vote
2answers
1k views

Arduino time(milli) and pressure sensor

I've succeeded to get an Arduino to work with a pressure sensor. What I want to do is when I put pressure on the sensor, after 5 minutes the led lights on. it starts over again if there's no ...
1
vote
0answers
81 views

Arduino interface of push button and led using millis()

I am working on a project of blinking of led using push button without delay().The limitations of led blinking is in accordance with the no of times the push button is pressed the led should blink ...
1
vote
0answers
24 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: ...
1
vote
1answer
58 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 ...
1
vote
0answers
31 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 ...
1
vote
0answers
111 views

Change delay function to millis function to play music

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[] = { ...
1
vote
1answer
59 views

3 input (on/off/off with delay) to control 1device using ESP8266 as Web Server

I want to control one device in three ways : turn on / turn off / turn off with delay. To do that i use an ESP8266 web server + android phone app. The problem is that turn off with delay wont work. It ...
1
vote
1answer
61 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 ...
1
vote
0answers
284 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 ...
1
vote
1answer
42 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....