Using random numbers with Arduino

Sdílet
Vložit
  • čas přidán 11. 06. 2024
  • 🤩 FREE Arduino Crash Course 👇👇
    bit.ly/get_Arduino_skills
    **If you like this, I think you'll like the premium Arduino training we offer. Check it out here** bit.ly/3nSBPUs
    This video tutorial walks through the use of the random() and randomSeed() function as it pertains to Arduino. We first investigate the output of the random function, why we need to use the randomSeed function to generate more apparent randomness and how to do it. We then use the randomly generated numbers to turn on and off three separate LEDs...randomly...

Komentáře • 77

  • @programmingelectronics
    @programmingelectronics  Před 3 lety +1

    ****If you like this, I think you'll like the premium Arduino training we offer. You can check it out here**** bit.ly/3lHyzcB

    • @heebakl
      @heebakl Před 2 lety

      I was wondering if the premium course accepts debit card payments or do I have to stick with credit card payment....

  • @alienc5920
    @alienc5920 Před 3 lety +4

    The best explanation and ilustration of all. CZcamsrs should learn fron this tutorial. Clear, professional and to the ponit without annoying background music. THANK YOU!!

  • @walkswithmight9024
    @walkswithmight9024 Před 4 lety +7

    I must have spent 4 hours last night searching for the answer this and proper examples and instruction to figure this out, and you sir, are a genius! THANK YOU!

    • @programmingelectronics
      @programmingelectronics  Před 4 lety

      So great to hear it helped! Thanks for watching!

    • @richierich3135
      @richierich3135 Před 4 lety

      SAME THING HAPPENED TO ME , THIS TUTORIAL SAVED ME , THANKS ALOT SIR.

    • @jimbarrett2152
      @jimbarrett2152 Před 2 lety

      Yes ! This tutorial certainly explains clearly a very useful and fascinating function that you can use / I wonder if it can be used as an ‘interrupt’? I will try. My interest is in LED Cubes / one led color or the RGB LED / just plain fascinating !!!!

  • @MrEuphonious
    @MrEuphonious Před 2 lety +1

    Thanks so much.
    I was getting all kinds of headaches with generating random numbers

  • @gordonyoud5975
    @gordonyoud5975 Před 6 lety +1

    So very clean concise tutorial on random number generation, thank you.

  • @lutfilawijaya6588
    @lutfilawijaya6588 Před 3 lety +1

    Those randomSeed tutorials help me a lot, thanks !

  • @jameshenry8015
    @jameshenry8015 Před 5 lety +2

    I did the same sort of thing on a Mega 2560 with 26 white LEDs in a row. I refined it to a short delay (10) with an analogRead random seed and the effect is somewhat mesmerizing. I call it Rain Dance because it reminds me of a rain storm hitting lit pavement at night. It runs 24/7 in my office and has been since December 23!

  • @ANAZ-RX7
    @ANAZ-RX7 Před rokem +1

    bro i love you and your way of explaining and teaching things, really you're the best.... with all my thanks to you❤❤

  • @davisactual
    @davisactual Před 2 lety +1

    thorough but not verbose.. very good quality and the editing is def worth the time as it greatly helps the experience of the viewer!

  • @ArcanePath360
    @ArcanePath360 Před 8 lety +2

    Fantastic tutorial. Learned so much in a short space of time

    • @programmingelectronics
      @programmingelectronics  Před 8 lety +1

      +ArcanePath360 Awesome to hear! Thanks a ton for watching, I hope you find the other lessons helpful too.

  • @AioTranNhan
    @AioTranNhan Před 8 lety

    thank you very much, my instructor asked us to do something like this without teaching and I was kinda overwhelming. thanks this help alot

  • @christmasdreams1
    @christmasdreams1 Před 10 lety +1

    Another terrific tut ! Random, I like ! Any regularity causes the brain's "Flight or Fight" response, which is strictly attuned only to "new events", to wander away once it has determined that no threat exists. Therefore, Random Events are better for holding viewers attention, (to a degree, of course, because blinking lights as a rule are not a 'danger' per se! ). keep up the great work!

    • @programmingelectronics
      @programmingelectronics  Před 10 lety

      Derrick Windsor Great point about maintaining attention - I had not thought about it from that angle.

  • @MrOrnidoko
    @MrOrnidoko Před 4 lety +1

    awesome, i used half of your code to fix my issue! thanks alot

  • @joshuapitong899
    @joshuapitong899 Před rokem +1

    Great help.🙌 Thank you.😊

  • @maurelius6463
    @maurelius6463 Před 7 lety +4

    Thanks for your classes! How can I combine this random blink sketch with a led fade sketch? I'm trying to have five LEDs fade in and out in a random pattern with overlapping phases. Kind of like a slow ebb and flow effect. Any tips? Keep up the great work!

    • @christopherchance4860
      @christopherchance4860 Před 6 lety

      look into neo-pixels
      Adafruit has example code that will do that very thing

  • @jamesb.8393
    @jamesb.8393 Před 2 lety +1

    Your tutorial on the ‘random’ function and the ‘random seed’ function was excellent/ I would like to apply this bit of info to an 8x8x8 LED Cube / if I increased the number of Leds’ to 512 and sent out the A0 to 8 shift registers and at the same time to a layer ( 1 thru 8 ) ...........could that produce a random light in the cube at a specified delay . And yes , there is definitely one way to find out :-). Your thoughts?

  • @MrBanzoid
    @MrBanzoid Před 3 lety +1

    Most interesting, thanks.

  • @meande-man5351
    @meande-man5351 Před 5 lety

    Thats awesome! gotta love random

  • @TomDcanada
    @TomDcanada Před 3 lety

    These tutorials are great . Could your delay be replaced with millis ? I have looked at your millis tutorials but can’t make the jump to replacing the delay in this tutorial . Any help would be appreciated .

  • @thevastenigma2464
    @thevastenigma2464 Před 2 lety +1

    Great video, you are awesome!

  • @arachnophillic9709
    @arachnophillic9709 Před 7 lety +3

    i used random number generators in my 6x6x6 rgb led cub to make color changing rain that starts at a random led each time with a random color.

  • @kingshahzad78
    @kingshahzad78 Před 4 lety +1

    nice explanation sir. Excellent presentation

  • @kartitamohsine8016
    @kartitamohsine8016 Před 4 lety

    thank you,please i want to ask you how to turn led on after a random of time

  • @user-cp9wl5wl5m
    @user-cp9wl5wl5m Před 2 lety +1

    Thanks!

  • @nyakoi
    @nyakoi Před 4 lety

    Thank you!

  • @jaredcohen9552
    @jaredcohen9552 Před 6 lety

    what happens if you use all of the analog pins? how would you use the random seed?

  • @willemnorval876
    @willemnorval876 Před 7 lety +1

    I want to use a 4 or 5 digit random access number for each guest at a hotel. These numbers should be 'recognised' by Arduino and transcribed back to the one code that is actually the only true access code to allow access. How can that be done ?

  • @gregenxelcreates
    @gregenxelcreates Před 5 lety

    I just followed this tutorial and my LED's are all blinking at the same time. They are doing the exact same thing. What could be the issue?

  • @arjayballester520
    @arjayballester520 Před 5 lety

    Hello i'm already using the random seed, and it seems that no changes at all. will you help me ? thanks a lot

  • @taranagnew436
    @taranagnew436 Před 5 lety

    can you plz tell me where to get or what to type to get the labels you are using on your uno?

  • @goldstandard7406
    @goldstandard7406 Před 4 lety

    Question. I have been trying to figure this out for a little while now. I want some leds to blink random for a delay controlled by a pot. My lights flash correctly for one sequence. Takes about 1.5 seconds. If the delay is 10 seconds, the last 8.5 stay solid on the last random color. I don't want to use mills because the arduino will have power for long periods of time. But the lights come on from a sensor input. Any help would be cool. Thanks for your time. I remember seeing a solution to this problem in one of your earlier tutorials. If you could just point me there I would be grateful

  • @sagittariusblackerz4391

    amazing men, please how can i to do time random ? i cant finding this information helpme what s millis ? thanks

  • @candrasniper3404
    @candrasniper3404 Před 2 lety

    How to catch random number to a variable in void loop that will not change before the syntax has finished, so we can call it. Example, I press the button, and random number is generated, we catch it to a variable, then I press the keypad to fulfill a number, then I press another button to compare my input number to the variable than contains the random number before.

  • @Ctairs
    @Ctairs Před 3 lety +1

    how can i make it so that it only generates a number once?

  • @GTX4747
    @GTX4747 Před 8 lety +1

    awesome!

  • @tarikbenghannou9028
    @tarikbenghannou9028 Před 4 lety

    hi i need to give the value of number random to servomotor
    please help me to found a solution
    thank you

  • @tomguenthner2493
    @tomguenthner2493 Před 5 lety

    Once I get a random number I want to use it for display it . I only need one random number. How do I just get the one number? Thanks.

  • @hj0835
    @hj0835 Před 7 lety +2

    This works great, I increased it to 10 leds, which each led is in a model hotel room....Now how would I go about telling it to use random time also? If you could give me an idea where to start. Thanks and Thanks for all the other vid's you have done. I have learned alot from them.

    • @programmingelectronics
      @programmingelectronics  Před 7 lety +1

      Hi Jim - great question. Depending on how you have blinked your LED (I am assuming you are employing the delay function?), you could try using the random number generated to be the value used by delay().
      i.e....
      ...turn LED ON...then...
      myRandomNumber = random(100, 1000);
      delay(myRandomNumber);
      ...turn LED OFF...then...
      //another randomly timed delay
      Does this make sense? Have a good one.

    • @hj0835
      @hj0835 Před 7 lety +2

      Makes more than sense, thank you.

  • @armaansharma1080
    @armaansharma1080 Před 2 lety +1

    Thanks man!

    • @programmingelectronics
      @programmingelectronics  Před 2 lety

      Glad it was helpful! Are there any specific Arduino topics you would like covered?

  • @mohamadrafeekmaatouki3888

    It helps me realy

  • @foxtrot151000
    @foxtrot151000 Před 6 lety

    Anyone know of this could work on an Attiny85?

  • @pokednaful
    @pokednaful Před 2 lety +1

    How to get highest number jn arduino?
    Example i get 2 sensor. Sensor 1 detected 100, and sensor 2 detected 80
    I want to take the i highest number automaticly

    • @programmingelectronics
      @programmingelectronics  Před 2 lety

      In code, you could have an if statement that compares the two values.. something like...
      If(sensor_2 > sensor_1){
      highestReading = sensor_2;
      } else {
      highestReading = sensor_1;
      }

  • @ArduinoAzerbaycan
    @ArduinoAzerbaycan Před 7 lety

    Super!!!!!!!!!!!!!

  • @abishekjabez9853
    @abishekjabez9853 Před 2 lety +1

    7:25 '42' i see what you did there (Hitch hikers guide to the galaxy)

  • @DaRKeTaMiN
    @DaRKeTaMiN Před 9 lety +1

    Is there anyway to stop it repeating the same number twice in a row?

    • @programmingelectronics
      @programmingelectronics  Před 9 lety

      Chris Punton Great question! My first though would be to start looking around for some type of random number generator library that would give you more options other than the built in random function.
      But if that turned up nothing, you might be able to store the previous random generated value in a variable, and then compare it to the next value generated by the random function. If they match, than have if statement generate another random variable.
      Hope this helps some. Have a good one!

    • @programmingelectronics
      @programmingelectronics  Před 9 lety

      Just made a video answering this question Chris Punton . It will air on July 14th. Thanks for asking it!

    • @taranagnew436
      @taranagnew436 Před 6 lety

      can you please post a link to the video, thank you

  • @TheMusterionOfRock
    @TheMusterionOfRock Před 8 lety

    What if I need to use all 20 pins on the arduino, how would you generate a non repeating random number?

    • @programmingelectronics
      @programmingelectronics  Před 8 lety +1

      +The Musterion Of Rock, You could use the output of the millis() function to generate a random seed every time through the loop. This might do the trick.

    • @TheMusterionOfRock
      @TheMusterionOfRock Před 8 lety +1

      Open Source Hardware Group That's smart! Thanks :D

    • @programmingelectronics
      @programmingelectronics  Před 8 lety

      I hope it works ok - best of luck!

  • @rolandvarga5179
    @rolandvarga5179 Před 3 lety

    10:37

  • @ferryvandergaag304
    @ferryvandergaag304 Před 6 lety +1

    Je hebt echt skire lampjes

  • @nathanielcorey6747
    @nathanielcorey6747 Před 6 lety

    42 lol I see you have read that book