Arduino Millis function explained with 3 example

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 มิ.ย. 2024
  • milis() function is explained practically with code and with push button.
    The value of millis() goes back to zero after approximately 50 days. Read more here: www.arduino.cc/reference/en/l...
    The best thank you for me is to not to skip ads and Subscribe 🔔 to my channel, like 👍 the video It is greatly appreciated. 🔔 😊.
    I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe and enable the bell 🔔.😊
    Learn Arduino in 30 Minutes (video): robojax.com/L/?id=135
    آشنایی با ملیس به فارسی
    • Video
    Jump to different chapter of this video:
    00:00 Start
    00:21 What is millis()
    02:01 Code explained
    04:35 Example 1: Action after some time
    07:12 Example 2: Detect push button pressed after 5 seconds
    10:25 Example 3: Detect Pushbutton pressed twice
    Download code example for this video: robojax.com/L/?id=209
    Related videos:
    Blink using Millis with different ON and OFF time: • Arduino LED blink usin...
    Robojax Timer V1 used millis() • Home Automation: Contr...
    Robojax Timer V1.1 used millis() with Display: • Home Automation: Roboj...
    Learn Arduino in 30 Minutes (video): robojax.com/L/?id=135
    Tutorial by Ahmad Shamshiri form Canada
    ****************************
    Arduino Step by Step Course (over 100 lectures) Starts here • Lesson 00 What is Ardu...
    ****************************
    If you found this tutorial helpful, please support me so I can continue creating contents like this. Here is PayPal link paypal.me/robojaxTV
    Follow me on Facebook robojaxTV
    Follow me on Twitter: / robojaxtv
    Follow me on Instagram: / robojax
    Tutorial by Robojax.com
    Get other projects code and learn Arduino
    robojax.com/learn/arduino
    #robojax #robojax_millis
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 101

  • @whitefields5595
    @whitefields5595 3 ปีที่แล้ว +2

    The millis() function is often a struggle for newcomers to understand. This is a very useful and practical set of examples. Could have mentioned the roll-over after around 50 days just for completeness, but that is a minor point

    • @robojax
      @robojax  3 ปีที่แล้ว +1

      Yes indeed. I believe I've mentioned it in another video about the limitation of counter. Thanks and stay safe.

  • @TheFalconJetDriver
    @TheFalconJetDriver 4 ปีที่แล้ว

    Thank you for explaining Millis I am building an automated Dust Collection system for my wood shop, when I turn on as an example the table saw the dust collector will start after the blast gate opens. I am using a sketch that Bob Clagget wrote for this purpose.
    I have had to make changes for the sketch to work for me. Several times he used the millis function. I am now better able to grasp what the sketch is doing. When you are new to the Arduino and not a code writer learning can be a steep hill. The electrical part is easy for more me.it learning the code that is a challenge. Again thank You

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome. I am glad you found it useful.

  • @First.Last.99
    @First.Last.99 ปีที่แล้ว

    Thank you a lot. this was very effective tutorial and much better than other videos out there, very very effective. I got my code to work!

  • @margaretridley5115
    @margaretridley5115 3 หลายเดือนก่อน

    Thank you for this video, it has helped me grasp the subject much better!

  • @qzorn4440
    @qzorn4440 3 ปีที่แล้ว

    great video... this is a nice way to have different timed actions to happen from one button input. the longer the button is pushed 1-5 seconds more event steps thanks...:)

    • @robojax
      @robojax  3 ปีที่แล้ว

      Ans here is an example of LED On and off each with different time th-cam.com/video/rUtDfadf8Jk/w-d-xo.html

  • @madhukeshnp
    @madhukeshnp 4 ปีที่แล้ว

    Detailed explanation. Very clear with good examples. Great tutorial.
    Thank you.

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome.

  • @604smit
    @604smit 4 ปีที่แล้ว +2

    very well explained, thanks Robojax!

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome.

  • @anythingunderthesun9930
    @anythingunderthesun9930 4 ปีที่แล้ว

    Great tutorial. Thanks ROBOJAX, now I know what's the "millis()" function is for Arduino script.

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome. Pleased to hear you found it useful.

  • @chandraprakashsharma7890
    @chandraprakashsharma7890 2 ปีที่แล้ว

    I am impressed by your coaching will you pl guide me for reading data from keypad and lcdI2C to use to drive stepper say indeed pulse "x" required to run stepper to that x steps

  • @rishav2005
    @rishav2005 2 ปีที่แล้ว

    Good example, great tutorial........thanks...

  • @manmanman3951
    @manmanman3951 2 ปีที่แล้ว

    Jazak Allah khair

    • @robojax
      @robojax  2 ปีที่แล้ว

      و ایاکم.
      here is free Arduino Step by Step Course (over 100 video lectures) Starts here robojax.com/L/?id=338

  • @alphonsesynrem28
    @alphonsesynrem28 4 ปีที่แล้ว

    Thank you so much Mr Robojax.

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome. The best thank you for me is to not skippin the ads and Subscribe 🔔 to my channel, like 👍 the video and do not skip the ads.. It is greatly appreciated. 🔔 😊.
      I will reply to all Subscriber's 🔔 questions. So make sure to Subscribe.😊 .

  • @ledc131
    @ledc131 3 ปีที่แล้ว +1

    Thanks, Great tutor

  • @sylgonjaysanoy8890
    @sylgonjaysanoy8890 ปีที่แล้ว

    i would like to ask about the millis and the pushbutton?
    if I put 2 pushbutton and using millis that if either one them will be push the other one will be disable like whatever push must be done in second button it will never able to send data until a certain seconds is pass and it will be available again for both of the push button.? and how would it be code it if it possible?

    • @robojax
      @robojax  ปีที่แล้ว

      Hi, the condiation you are asking needs a full project. you may look at this video which is showing how to have LED blink without a delay th-cam.com/video/obBX9hyH5mM/w-d-xo.html

  • @Oshan_Dissanayaka
    @Oshan_Dissanayaka 2 ปีที่แล้ว

    Thank You!...😃😃😃

    • @robojax
      @robojax  2 ปีที่แล้ว

      You are welcome. here is free Arduino Step by Step Course (over 100 video lectures) Starts here robojax.com/L/?id=338

    • @Oshan_Dissanayaka
      @Oshan_Dissanayaka 2 ปีที่แล้ว

      @@robojax wow. Great. Thanks. I'll check... 😊👍👍

  • @voltronicsautomation
    @voltronicsautomation 4 ปีที่แล้ว

    Great tutorial Robojax, Salam from Malaysia

    • @robojax
      @robojax  4 ปีที่แล้ว +1

      Walaikum salam, I am sorry for late reply. I was on vacation. Thank you.

  • @sanjaybhatikar
    @sanjaybhatikar 4 ปีที่แล้ว

    Another great video 👍

    • @robojax
      @robojax  4 ปีที่แล้ว

      Thanks again!

  • @danujayasaputro7861
    @danujayasaputro7861 3 ปีที่แล้ว

    thanks for the great video!

    • @robojax
      @robojax  3 ปีที่แล้ว

      Glad you liked it!

  • @user-fo8sz2ym4u
    @user-fo8sz2ym4u 9 หลายเดือนก่อน

    Hi there :-) I need some help with my coding.
    I would like to run a few motors and sweep a servo with one push button from and Arduino Mega board.
    I have tried using if statement for the push button and millis function for after the button is pushed and separating the operation of each component with different time in millis.I might have made a mistake or I could have forgotten something.
    Can somebody help me please or is there maybe an example sketch that I can work from?

  • @georgeusroger1
    @georgeusroger1 4 ปีที่แล้ว

    Hello , can i use two functions at same time ? , first function is for running DS18B20 use millis() , seconde fonction while (for running stepper motors and many security sensors , thanks

    • @robojax
      @robojax  4 ปีที่แล้ว

      have you watch my other video on this? Blinking LED with millis()? See it here th-cam.com/video/rUtDfadf8Jk/w-d-xo.html and here the Robojax Timer V1 th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html

  • @mivison
    @mivison ปีที่แล้ว

    Thanks so much!

    • @robojax
      @robojax  ปีที่แล้ว

      You are welcome. The best thank you for me is to subscribe to my channel. Your subscription is stamp of approval and my videos will be suggested to more people and this will help me. I appreciate it. thanks❤️

  • @abualis1178
    @abualis1178 4 ปีที่แล้ว +1

    Great video as always, thank you. I have a question if anyone can help, is there a way to force the program to restart from the beginning if no a laps of time has passed while waiting for user's input. let's say I am ask the user to pick a product from a list then he needs to pay for the product and sometimes the user change his mind and walks away, the program stays at the same prompt how can I use millis to cancel the operation and start again.

    • @robojax
      @robojax  4 ปีที่แล้ว +1

      Hello, here is the timer using millis with push button to restart th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html and you can change it NOT to restart. just stop or whatever you want

  • @afif-tech2673
    @afif-tech2673 3 ปีที่แล้ว

    رائع ومبدع استاذ احمد

    • @robojax
      @robojax  3 ปีที่แล้ว

      شكرا لك. أنا سعيد لأنك أحببته.

  • @auroshisray9140
    @auroshisray9140 4 ปีที่แล้ว +1

    Thank you sir for sharing this

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome.

  • @cksmaya
    @cksmaya 2 ปีที่แล้ว +1

    THANK YOU

    • @robojax
      @robojax  2 ปีที่แล้ว

      you are welcome.

  • @hilmigureken
    @hilmigureken 4 ปีที่แล้ว

    Hi, I can blink the led once with the delay function in the code below. How can I manage it with millis? Thx.
    while(sayac < 1 ) {
    Serial.print("sayac:");Serial.println(sayac);
    digitalWrite(2, HIGH);
    delay(5000);
    digitalWrite(2, LOW);
    delay(5000);
    sayac++;
    }

    • @robojax
      @robojax  4 ปีที่แล้ว

      Hi, under all my videos in the description I have links to related videos. and I have video on that.

  • @kitkirkyen2002
    @kitkirkyen2002 2 ปีที่แล้ว

    Great tutor. Thank you so much sir.

    • @robojax
      @robojax  2 ปีที่แล้ว

      you are welcome. here is the full video with practical example th-cam.com/video/obBX9hyH5mM/w-d-xo.html

  • @ShivamGupta-us8oc
    @ShivamGupta-us8oc 4 ปีที่แล้ว

    Good job sir u explained it very easily

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome.

  • @sufiyantronics559
    @sufiyantronics559 3 ปีที่แล้ว +1

    Thank you sir...

    • @robojax
      @robojax  3 ปีที่แล้ว

      you are welcome. I hope you've subscribed as your subscription help my channel grow. Thanks

  • @maicomcoelholopes9032
    @maicomcoelholopes9032 4 ปีที่แล้ว

    muito obrigado :)

    • @robojax
      @robojax  4 ปีที่แล้ว

      Você é bem vindo.

  • @muhammadzia252
    @muhammadzia252 4 ปีที่แล้ว

    Thanks for sharing

    • @robojax
      @robojax  4 ปีที่แล้ว

      You are welcome.

  • @shrikantnikam2426
    @shrikantnikam2426 4 ปีที่แล้ว

    Is it possible to make delay function in separate tab and use millis single line command like delay? For make code more simpler

    • @robojax
      @robojax  4 ปีที่แล้ว

      what do you mean by "separate tab"? we use millis() so we can do something else. here is my video with more examples th-cam.com/video/rUtDfadf8Jk/w-d-xo.html

  • @mysubway6928
    @mysubway6928 3 ปีที่แล้ว

    I have esp 8266 nodemcu with 4 relay board and 18b20 temp sensor
    I need relay 1 to activate when temp reach 80F and de active when temp reach 65F
    Relay 2 need to activate after 2 minutes when power up to the nodemcu
    Relay 3 need to activate every 4 hrs for 30 minutes but when really 3 actives, relay 1 and 2 must be de active for 30 minutes
    Then relay 1 will wait 1 minute then active again and relay 2 will wait for 2 minutes to active again
    I seen your millis function video so I though this can be done
    do you think you can make some kind of video to cover this kind of time event?
    Thanks

    • @robojax
      @robojax  3 ปีที่แล้ว

      Hello, relay timer video is here th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html

  • @jyotisuthar8476
    @jyotisuthar8476 2 ปีที่แล้ว

    Anyone please help me
    My problem - using 3 led
    First led glow 10 sec and other both is low and then after 5 sec led glow 2 for 10 min then 5 sec delay then 3rd led glow for 10 sec and 1 st and 2nd off

  • @asadulhuq
    @asadulhuq 2 ปีที่แล้ว

    Thanks for your excellent presentations. I have a question. Please answer. It seems that once I want to download a code it downloads an html file. Is there a way to download your code as text file?

    • @robojax
      @robojax  2 ปีที่แล้ว +1

      Hello, you just copy the code and past it in Arduino. That is pure code. but if you want to use in microsoft word, then paste it into notepad which removes all formatting and then copy it from notepad and then past it into Microsoft word.

    • @asadulhuq
      @asadulhuq 2 ปีที่แล้ว +1

      @@robojax Lot of thanks. I have done it now.

  • @sirousazaruoon4092
    @sirousazaruoon4092 ปีที่แล้ว

    thanks

    • @robojax
      @robojax  ปีที่แล้ว

      You are welcome. here is the a better video with example which is part of my Arduino course th-cam.com/video/obBX9hyH5mM/w-d-xo.html

  • @elzjonz
    @elzjonz 4 ปีที่แล้ว

    Is it possible for 2 sensors namely S1 and S2 to light up LED in "OR function" namely Output1??? If S1 is triggered output1 lights up for 10seconds and then switch off
    Same goes for S2 it lights up same output1 for 10seconds and switch off after.. But within or less than 10 seconds, while output1 is switch on any of the 2 sensors (s1 or s2) was triggered again, it will restart count 10 seconds and then switches off..
    Example, s1 was triggered, so output1 lights up, after 3 seconds s2 was triggered or s1 was triggered again, so it makes 13 seconds output1 switches on and then switches off.... Is it possible using millis? Thanks for possible code and sorry for bad english

    • @robojax
      @robojax  4 ปีที่แล้ว

      Yes it is doable. I have two videos on millis() and used it on lots of projects on my channel. You would have to have patience and play with it.

    • @elzjonz
      @elzjonz 4 ปีที่แล้ว

      @@robojax ok thanks ill watch your videos thanks

  • @aboutthenature.6113
    @aboutthenature.6113 2 ปีที่แล้ว

    can any help me for the code for led matrix 7*12. which show falling rain drops.

    • @robojax
      @robojax  2 ปีที่แล้ว

      Hi, sorry I am very busy

  • @JayPatel-bw3bn
    @JayPatel-bw3bn 3 ปีที่แล้ว

    Sir i am using the photosensors to blink the led light. So my project is blink the led light every seconds the photosensor is covered. How can i do that?

    • @robojax
      @robojax  3 ปีที่แล้ว

      Please check the link to blik using millis in the description.

  • @anujsaini9353
    @anujsaini9353 3 ปีที่แล้ว

    Thank you for explanation, Sir. I want to know, weather millis function can be used for RCWL sensor or not. I tried but nit succeeded. Can U plz guide me. Code as below and I want sensorVal=1 for 5 min
    int =rcwlPin=2;
    int=sensorVal;
    cosnt unsigned long Interval=1000*60%5;
    unsigned long PreviousTime=0;
    void setup(){
    pinMode(rcwlPin,INPUT);
    Serial.begin(9600);
    void setup(){
    sensorVal=digitalWrite(rcwlPin);
    millis()=unsigned long CurrentTime;
    if(sensorVal==1){
    if (CurrentTime-PreviousTime>=Interval){
    sensorval==1
    PreviousTime=CurrentTime;
    }
    }
    else
    { (sensorVal==0)
    }
    Serial.println(sensorVal);
    )
    I upload this sketch, but not getting desired result.
    Kindly resolve it. Thank you

    • @robojax
      @robojax  3 ปีที่แล้ว

      Hi, Please see this blink example video th-cam.com/video/rUtDfadf8Jk/w-d-xo.html and try your code to turn ON and OFF LED first. once it works, then use your sensor.

  • @__RohitDevar
    @__RohitDevar 4 ปีที่แล้ว

    robojax ,,,,best for the reason

    • @robojax
      @robojax  4 ปีที่แล้ว

      Thank you Rohit. I do my best. I am glad you found it useful.

    • @__RohitDevar
      @__RohitDevar 4 ปีที่แล้ว

      @@robojax i should thank you sir ,,for your superb content videos

  • @sarathigayu9049
    @sarathigayu9049 4 ปีที่แล้ว

    one push button used one led blinking in millis program video required sir.pls

    • @robojax
      @robojax  4 ปีที่แล้ว

      what does the push button do? Start or reset?
      I can read all comments on ONE page. So wherever you post it, I can read them.

  • @maicomcoelholopes9032
    @maicomcoelholopes9032 4 ปีที่แล้ว

    você poderia me ajudar? Eu estou tentando fazer um led piscar, mas eu quero controlar o tempo que é alto e o tempo que é baixo, mas eu estou tendo dificuldade, seria interessante para um próximo vídeo sobre milles () parte 2
    Aqui está o sketch:
    unsigned long previousmillis_led_low=0;
    unsigned long previousmillis_led_high=0;
    int one_second=1000;
    int two_seconds=2000;
    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    unsigned long currentmillis=millis();
    int status_led=LOW;
    if(status_led == LOW){//it's off?
    if(currentmillis-previousmillis_led_low == two_seconds){//is LOW for more than 2 seconds?
    previousmillis_led_low = currentmillis;
    status_led = HIGH;
    Serial.println("status_led_high: ");
    }
    }
    else{//--------------- so it's on
    if(currentmillis-previousmillis_led_b_high == one_second){// is HIGH for more than 1 seconds?
    previousmillis_led_b_high = currentmillis;
    status_led = LOW;
    Serial.println("status_led_low: ");
    }
    }
    }//void loop

    • @robojax
      @robojax  4 ปีที่แล้ว

      Oi, eu trabalhei no seu problema e fazendo vídeo nele. Em breve vou postar em cerca de uma semana.

    • @maicomcoelholopes9032
      @maicomcoelholopes9032 4 ปีที่แล้ว

      @@robojaxobrigado pela ajuda, seus videos me ajudam muito

    • @robojax
      @robojax  4 ปีที่แล้ว

      Você é bem vindo. Estou feliz em ouvir isso.

    • @robojax
      @robojax  4 ปีที่แล้ว

      Oi, acabei de postar o piscar usando vídeo millis th-cam.com/video/rUtDfadf8Jk/w-d-xo.html

  • @chandraprakashsharma7890
    @chandraprakashsharma7890 2 ปีที่แล้ว

    I.e code to read "say "pulse is 200 fed by keypad to lcd I2c to rum steeper to 200 pulse

    • @robojax
      @robojax  2 ปีที่แล้ว

      Please see millis full details here th-cam.com/video/obBX9hyH5mM/w-d-xo.html

  • @georgeivbarrett5106
    @georgeivbarrett5106 3 ปีที่แล้ว

    if (digitalRead(bPin)==LOW){
    if (currentMillis = millis() + (unsigned long) waitTime){

    // The code above is where im having trouble: If the button is
    // low i want a delay of 10 seconds before writing the LED high.
    //The LED is high as soon as button is low without a 10 second delay.
    HELP!!!!!

    • @robojax
      @robojax  3 ปีที่แล้ว

      you are watching wrong video. Search for "millis" to see the other video.

  • @lemao9995
    @lemao9995 3 ปีที่แล้ว

    emoneySwag nice drip

  • @susantakumarbehera8171
    @susantakumarbehera8171 ปีที่แล้ว

    I MAKE A CODE IN ARDUINOTO READ DUTY CYCLE . BUT ARDUINO CANNOT READ DUTY AND FREQUENCY FROM 1 Hz to 30Hz
    what is the solution

    • @robojax
      @robojax  ปีที่แล้ว

      When you use UPPERCASE text you are screaming 😱.

    • @robojax
      @robojax  ปีที่แล้ว

      and it is hard to read

    • @susantakumarbehera8171
      @susantakumarbehera8171 ปีที่แล้ว

      @@robojax I make a code in arduino uno to read frequency and duty cycle. But arduino cannot read from 1Hz to 30Hz and its duty cycle

  • @nanditofernandeshornay8967
    @nanditofernandeshornay8967 ปีที่แล้ว

    Sr. please make the code bellow becomes millis:
    Void loop () {
    if (digitaRead (tombol)==0){
    digitalWrite (led, HIGH);
    delay (3000);
    digitalWrite (led, LOW);
    delay (3000);
    digitalWrite (led, HIGH);
    delay (3000);
    digitalWrite (led, HIGH);
    delay (3000);
    }
    else {
    digitalWrite (led, LOW);
    }
    }
    How to be version millis Sr..???.

    • @robojax
      @robojax  ปีที่แล้ว

      Hi, please watch the latest full video th-cam.com/video/obBX9hyH5mM/w-d-xo.html always search my channel you will find surprising contents

  • @abcdefghijk3168
    @abcdefghijk3168 4 ปีที่แล้ว

    To reset millis() to 0, here is a video:
    th-cam.com/video/3Du1n2VRA68/w-d-xo.html

    • @robojax
      @robojax  4 ปีที่แล้ว +1

      Your comment was in the "likely Spam" and I approved it. Usually I delete them but this is useful. Thanks

  • @steveboisseau6481
    @steveboisseau6481 3 ปีที่แล้ว

    bonjour,
    auriez-vous une piste pour créer un millis ou autre en boucle avec un temps défini (qui redémarrerait automatiquement et ou on peut intégrer des ordres sur différentes sorties pwn (ordre de mise en route selon une plage défini)
    exemple
    temps en boucle de 0 a 36000seconde
    déclenchement de la sortie pwn 2 de 65 a 85 secondes
    déclenchement de la sortie pwn 4 de 180 a 260 seconde
    déclenchement de la sortie pwn 2 de 600 a 900 seconde
    merci par avance

    • @robojax
      @robojax  3 ปีที่แล้ว

      Bonjour, vous pouvez regarder ce Blink en utilisant Millis avec des heures ON et OFF différentes: th-cam.com/video/rUtDfadf8Jk/w-d-xo.html et écrire votre propre code.