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 - วิทยาศาสตร์และเทคโนโลยี
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
Yes indeed. I believe I've mentioned it in another video about the limitation of counter. Thanks and stay safe.
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
You are welcome. I am glad you found it useful.
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!
Thank you for this video, it has helped me grasp the subject much better!
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...:)
Ans here is an example of LED On and off each with different time th-cam.com/video/rUtDfadf8Jk/w-d-xo.html
Detailed explanation. Very clear with good examples. Great tutorial.
Thank you.
You are welcome.
very well explained, thanks Robojax!
You are welcome.
Great tutorial. Thanks ROBOJAX, now I know what's the "millis()" function is for Arduino script.
You are welcome. Pleased to hear you found it useful.
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
Good example, great tutorial........thanks...
Jazak Allah khair
و ایاکم.
here is free Arduino Step by Step Course (over 100 video lectures) Starts here robojax.com/L/?id=338
Thank you so much Mr Robojax.
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.😊 .
Thanks, Great tutor
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?
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
Thank You!...😃😃😃
You are welcome. here is free Arduino Step by Step Course (over 100 video lectures) Starts here robojax.com/L/?id=338
@@robojax wow. Great. Thanks. I'll check... 😊👍👍
Great tutorial Robojax, Salam from Malaysia
Walaikum salam, I am sorry for late reply. I was on vacation. Thank you.
Another great video 👍
Thanks again!
thanks for the great video!
Glad you liked it!
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?
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
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
Thanks so much!
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❤️
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.
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
رائع ومبدع استاذ احمد
شكرا لك. أنا سعيد لأنك أحببته.
Thank you sir for sharing this
You are welcome.
THANK YOU
you are welcome.
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++;
}
Hi, under all my videos in the description I have links to related videos. and I have video on that.
Great tutor. Thank you so much sir.
you are welcome. here is the full video with practical example th-cam.com/video/obBX9hyH5mM/w-d-xo.html
Good job sir u explained it very easily
You are welcome.
Thank you sir...
you are welcome. I hope you've subscribed as your subscription help my channel grow. Thanks
muito obrigado :)
Você é bem vindo.
Thanks for sharing
You are welcome.
Is it possible to make delay function in separate tab and use millis single line command like delay? For make code more simpler
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
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
Hello, relay timer video is here th-cam.com/video/6DGQhQgr7Ak/w-d-xo.html
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
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?
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.
@@robojax Lot of thanks. I have done it now.
thanks
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
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
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.
@@robojax ok thanks ill watch your videos thanks
can any help me for the code for led matrix 7*12. which show falling rain drops.
Hi, sorry I am very busy
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?
Please check the link to blik using millis in the description.
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
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.
robojax ,,,,best for the reason
Thank you Rohit. I do my best. I am glad you found it useful.
@@robojax i should thank you sir ,,for your superb content videos
one push button used one led blinking in millis program video required sir.pls
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.
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
Oi, eu trabalhei no seu problema e fazendo vídeo nele. Em breve vou postar em cerca de uma semana.
@@robojaxobrigado pela ajuda, seus videos me ajudam muito
Você é bem vindo. Estou feliz em ouvir isso.
Oi, acabei de postar o piscar usando vídeo millis th-cam.com/video/rUtDfadf8Jk/w-d-xo.html
I.e code to read "say "pulse is 200 fed by keypad to lcd I2c to rum steeper to 200 pulse
Please see millis full details here th-cam.com/video/obBX9hyH5mM/w-d-xo.html
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!!!!!
you are watching wrong video. Search for "millis" to see the other video.
emoneySwag nice drip
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
When you use UPPERCASE text you are screaming 😱.
and it is hard to read
@@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
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..???.
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
To reset millis() to 0, here is a video:
th-cam.com/video/3Du1n2VRA68/w-d-xo.html
Your comment was in the "likely Spam" and I approved it. Usually I delete them but this is useful. Thanks
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
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.