Arduino Millis function explained with 3 example

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 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 5 лет назад

    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  5 лет назад

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

  • @margaretridley5115
    @margaretridley5115 8 месяцев назад

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

  • @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!

  • @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 ruclips.net/video/rUtDfadf8Jk/видео.html

  • @anythingunderthesun9930
    @anythingunderthesun9930 5 лет назад

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

    • @robojax
      @robojax  5 лет назад

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

  • @rishav2005
    @rishav2005 3 года назад

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

  • @604smit
    @604smit 5 лет назад +2

    very well explained, thanks Robojax!

    • @robojax
      @robojax  5 лет назад

      You are welcome.

  • @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

  • @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 ruclips.net/video/6DGQhQgr7Ak/видео.html and you can change it NOT to restart. just stop or whatever you want

  • @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

  • @afif-tech2673
    @afif-tech2673 3 года назад

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

    • @robojax
      @robojax  3 года назад

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

  • @madhukeshnp
    @madhukeshnp 5 лет назад

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

    • @robojax
      @robojax  5 лет назад

      You are welcome.

  • @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... 😊👍👍

  • @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.😊 .

  • @kitkirkyen2002
    @kitkirkyen2002 2 года назад

    Great tutor. Thank you so much sir.

    • @robojax
      @robojax  2 года назад

      you are welcome. here is the full video with practical example ruclips.net/video/obBX9hyH5mM/видео.html

  • @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 ruclips.net/video/obBX9hyH5mM/видео.html

  • @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.

  • @cksmaya
    @cksmaya 3 года назад +1

    THANK YOU

    • @robojax
      @robojax  3 года назад

      you are welcome.

  • @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 ruclips.net/video/6DGQhQgr7Ak/видео.html

  • @VirgilBruiners
    @VirgilBruiners Год назад

    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 ruclips.net/video/rUtDfadf8Jk/видео.html and here the Robojax Timer V1 ruclips.net/video/6DGQhQgr7Ak/видео.html

  • @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.

  • @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 ruclips.net/video/rUtDfadf8Jk/видео.html

  • @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

  • @anujsaini9353
    @anujsaini9353 4 года назад

    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  4 года назад

      Hi, Please see this blink example video ruclips.net/video/rUtDfadf8Jk/видео.html and try your code to turn ON and OFF LED first. once it works, then use your sensor.

  • @auroshisray9140
    @auroshisray9140 5 лет назад +1

    Thank you sir for sharing this

    • @robojax
      @robojax  5 лет назад

      You are welcome.

  • @asadulhuq
    @asadulhuq 3 года назад

    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  3 года назад +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 3 года назад +1

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

  • @ShivamGupta-us8oc
    @ShivamGupta-us8oc 5 лет назад

    Good job sir u explained it very easily

    • @robojax
      @robojax  5 лет назад

      You are welcome.

  • @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❤️

  • @ledc131
    @ledc131 3 года назад +1

    Thanks, Great tutor

  • @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 ruclips.net/video/obBX9hyH5mM/видео.html

  • @JayPatel-bw3bn
    @JayPatel-bw3bn 4 года назад

    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  4 года назад

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

  • @aboutthenature.6113
    @aboutthenature.6113 3 года назад

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

    • @robojax
      @robojax  3 года назад

      Hi, sorry I am very busy

  • @sanjaybhatikar
    @sanjaybhatikar 4 года назад

    Another great video 👍

    • @robojax
      @robojax  4 года назад

      Thanks again!

  • @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

  • @jyotisuthar8476
    @jyotisuthar8476 3 года назад

    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

  • @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.

  • @danujayasaputro7861
    @danujayasaputro7861 4 года назад

    thanks for the great video!

    • @robojax
      @robojax  4 года назад

      Glad you liked it!

  • @__RohitDevar
    @__RohitDevar 5 лет назад

    robojax ,,,,best for the reason

    • @robojax
      @robojax  5 лет назад

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

    • @__RohitDevar
      @__RohitDevar 5 лет назад

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

  • @muhammadzia252
    @muhammadzia252 4 года назад

    Thanks for sharing

    • @robojax
      @robojax  4 года назад

      You are welcome.

  • @sirousazaruoon4092
    @sirousazaruoon4092 2 года назад

    thanks

    • @robojax
      @robojax  2 года назад

      You are welcome. here is the a better video with example which is part of my Arduino course ruclips.net/video/obBX9hyH5mM/видео.html

  • @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

  • @georgeivbarrett5106
    @georgeivbarrett5106 4 года назад

    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  4 года назад

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

  • @maicomcoelholopes9032
    @maicomcoelholopes9032 5 лет назад

    muito obrigado :)

    • @robojax
      @robojax  5 лет назад

      Você é bem vindo.

  • @nanditofernandeshornay8967
    @nanditofernandeshornay8967 2 года назад

    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  2 года назад

      Hi, please watch the latest full video ruclips.net/video/obBX9hyH5mM/видео.html always search my channel you will find surprising contents

  • @maicomcoelholopes9032
    @maicomcoelholopes9032 5 лет назад

    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  5 лет назад

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

    • @maicomcoelholopes9032
      @maicomcoelholopes9032 5 лет назад

      @@robojaxobrigado pela ajuda, seus videos me ajudam muito

    • @robojax
      @robojax  5 лет назад

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

    • @robojax
      @robojax  5 лет назад

      Oi, acabei de postar o piscar usando vídeo millis ruclips.net/video/rUtDfadf8Jk/видео.html

  • @lemao9995
    @lemao9995 3 года назад

    emoneySwag nice drip

  • @abcdefghijk3168
    @abcdefghijk3168 4 года назад

    To reset millis() to 0, here is a video:
    ruclips.net/video/3Du1n2VRA68/видео.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 4 года назад

    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  4 года назад

      Bonjour, vous pouvez regarder ce Blink en utilisant Millis avec des heures ON et OFF différentes: ruclips.net/video/rUtDfadf8Jk/видео.html et écrire votre propre code.