LESSON 31: Understanding Arduino Arrays

Поділитися
Вставка
  • Опубліковано 2 кві 2018
  • You guys can help me out over at Patreon, and that will keep this high quality content coming:
    / paulmcwhorter
    In this tutorial we learn how to declare, dimension, and use arrays and array variables with the Arduino. We do a simple averaging program to show the concept
  • Наука та технологія

КОМЕНТАРІ • 153

  • @etc-b-28atharvapatil2
    @etc-b-28atharvapatil2 4 роки тому +18

    the best mentor anyone could ever get..

  • @erygion
    @erygion 4 роки тому +2

    Thank you Mr. Mcwhorter, another great lesson. I had lots of fun with this and modified it with a OLED and leds. I'm learning so much, you're very appreciated sir.

  • @andrewchiara8617
    @andrewchiara8617 6 років тому +2

    Mr. McWhorter,
    Thank you for the very clear teaching, laying a solid foundation towards my understanding of working with arrays. I learned a lot!

  • @rickm4130
    @rickm4130 6 років тому +1

    Thank you for returning to the Arduino series, Great fun!

  • @garylangley6532
    @garylangley6532 6 років тому

    I'm taking a programming class at University of Phoenix and I use your videos a lot for my class discussion. I really enjoy your videos and i learn a lot from them.

  • @SparkOutUs
    @SparkOutUs 3 роки тому

    I started off on your new arduino series and didnt bother checking this one until now and my god its a gold mine, thanks again!

  • @meagrebones
    @meagrebones 6 років тому +1

    Thanks, that was clear and easy to understand. I like that you made 'deliberate' mistakes to teach us to debug. I'm trying to move on from my cut and paste style of programming so this was a a great help.Looking forward to more.

  • @MrMikeD28
    @MrMikeD28 5 років тому +1

    That's a very good programming lesson! I like to see the mistakes and how you fixed them. I also didn't know how to prompt the user, now I know. Thanks!

  • @tonyw8522
    @tonyw8522 4 роки тому +1

    Thank you for your efforts Paul. Most of what I know about the arduino code is down to you! 66 years old now and Im still trying to learn. Be well..

  • @MrWahjudi
    @MrWahjudi 6 років тому

    I just saw this tutorial, Very very clear. English is my third language but you explain everything was very clear for me. Absolutely very excellent teaching.

  • @ingeborgsvensson4896
    @ingeborgsvensson4896 5 років тому

    Great tutorial. I used and modified this example to calculate the average value of a light intensity sensor. Thank you!

  • @TechnoAutomation
    @TechnoAutomation 6 років тому +5

    Thanks a lot. Nicely explained.
    Waiting for your new lesson.

  • @bartmanpoet9067
    @bartmanpoet9067 2 роки тому

    Thank you for helping me to work with arrays, please keep making video's. You are a good teacher. I get lost sometimes when you jump around, other than that they cover the material well. I end up re watching the material.

  • @elaheparvaee2390
    @elaheparvaee2390 3 роки тому

    I found this series of lessons tonight. While I'm in your channel every day, I've never found them , I don't know why. I'm so happy to discover them,
    A new opportunity to learn from you,
    Thank you so much,
    I appreciate,
    Elahe

  • @leginyela
    @leginyela 6 років тому

    Thanks again Paul. I appreciate your teaching style

  • @electronicsexplained287
    @electronicsexplained287 6 років тому +1

    You are a great teacher mr Paul .. Please keep em coming :)

  • @srduke
    @srduke 6 років тому +36

    I'm always talking to my boss about arrays. Never get one though........
    I'll get my coat.

  • @thambirajahpathmanathan7080
    @thambirajahpathmanathan7080 4 роки тому +13

    Hallo Sir, your Arduino videos are amazing, I really appreciate your Teaching style is so relaxing that learning with you really is a pleasure.

  • @rbmnewton
    @rbmnewton 5 років тому

    Thanks Paul,, just one of your fan in India... Learning about arrays on my way to office today morning....

  • @Thefarnworth1
    @Thefarnworth1 5 років тому

    MR. McWhorter; I am a 80 year old male and your videos are truly amazing, I really appreciate what you do; your style is so relaxing that learning with you really is a pleasure. Thank you and best regards.

    • @paulmcwhorter
      @paulmcwhorter  5 років тому

      Thanks for the kind words and glad to hear you are enjoying learning.

  • @twainstasiuk1945
    @twainstasiuk1945 6 років тому +8

    Ok,, thank you once again for an excellent tutorial on arrays! At the end of each lesson,, we have yet another technique for our toolbox not just a copy and paste example we can hope to implement into our work. This is how this tool works and here is a real life example. Excellent teaching! Here's an idea for a show at some point. I know you've done a few shows on interrupts,, and hardware interrupts isn't a big topic,, an easy add to what you've done and it does lead into denouncing code and circuits. I highly suspect anyone who has tried to watch and monitor hardware events has struggled with those topics. PS,,, I think we are ok with you misspelling some code,,making errors,,, sorta makes us feel good to catch stuff and that you are a human,, just like the rest of us. Enjoy the show!

  • @redserpent
    @redserpent Рік тому

    Great video. It was good to see you making mistakes and pushing through with the debugging. For the first time I began to understand the meaning of taking the trash out, THank you.

  • @thenightwhisper2872
    @thenightwhisper2872 6 років тому

    many thanks Sir,
    pls continue to make more videos, cause we learned from u very much

  • @andrewferg8737
    @andrewferg8737 3 роки тому

    Great video. Thanks for educating us!

  • @Constitutionallycorrect
    @Constitutionallycorrect 6 років тому

    Once again, a plethera of information!!! It's funny, before i saw your first video i told my girlfriend that i needed someone to turn this code into a bunch of containers, basically like html, so that I can understand it, and here you come with your bucket!! hahahaha, awesome stuff!!!!

  • @rukshansheriffdeen195
    @rukshansheriffdeen195 6 років тому

    Thank you Sir, you are a great social worker.

  • @ragnarmarnikulasson3626
    @ragnarmarnikulasson3626 4 роки тому

    Exelent tutorial! So we'll explained, clearly a great teacher.

  • @richardbrewer9251
    @richardbrewer9251 3 роки тому +2

    Paul, this is a great basic lesson. Now I would like to see an advanced lesson on arrays. I have a 20 X 20 neopixel display I am programming using large arrays. Much to my surprise, my Mega 2560 quickly ran out of memory. PROGMEM is the solution to that problem, but I am having trouble understanding the retrieval process. An advanced lesson would probably cover that subject.

  • @yamankhalid1352
    @yamankhalid1352 Рік тому

    Hi Paul, thank you so much for these lessons they helped me a lot. Also, I fixed the sumGrades problem by putting the variable inside the loop function (local variable), so it reset the variable everytime

  • @jimnolimit
    @jimnolimit 2 роки тому

    Thank you for making this video.

  • @naboulsikhalid7763
    @naboulsikhalid7763 5 років тому

    good lesson, onetime explained, onetime understood. magic

  • @Steve-GM0HUU
    @Steve-GM0HUU 3 роки тому

    👍 very nicely explained. Just what I needed to know. Thank you.

  • @Johann75
    @Johann75 2 роки тому

    Could never understand Arrays at school. Could not believe, I would understand it at the age of 46. Thank you Sir.

  • @madalinduna4160
    @madalinduna4160 4 роки тому

    Great lesson! Thank you!

  • @LizMyers
    @LizMyers 6 років тому

    Paul, thanks so much for your videos - you are an EXCELLENT teacher and offer real benefit. The Arduino programming fundamentals are SUPER. In this video you mentioned storing Temp values ove time and plotting them on a graph: could you show us how to do that please? As an added bonus - would be great if we could get an Arduino Touch screen (TFT type) tutorial too or a place to show the temperature graphic. I bought one from EBay and am having difficulty making it do anything! Thanks in advance - Liz

  • @rangaswamy8604
    @rangaswamy8604 6 років тому +1

    Good explanation. Could you teach further about assigning values to 3 dimensional arrays and retrieving them using for loops?

  • @toddduffett1378
    @toddduffett1378 4 роки тому +1

    Hi Paul,
    Curious to know if you would consider doing a follow up to this video covering Multidimensional Arrays?
    I love your style and clarity of explanation and think you would do the subject justice.

  • @Itzpugs
    @Itzpugs 6 років тому +3

    finally, an explanation that my puny brain comprehends. thank you

  • @capistor1
    @capistor1 6 років тому +1

    kindly explain functions and how to create them according to use and how to trigger a function in result to another trigger.

  • @punjabilog
    @punjabilog 2 роки тому

    Thank you very much Sir for this great video.

  • @OutTheGaWoods
    @OutTheGaWoods 4 роки тому

    Hello Sir, I enjoy being able to learn the lessons you teach. I hate to say I got stuck on this one. everything ran smooth until I put in the number of grades, it asked for the grade input twice before I could input the first one . I went back opened a new sketch and rewrote the code line for line ; and the same thing happened again. I will try again tomorrow. The wife just called me in for supper. Thanks again You Are Awesome......

    • @grantdennert6980
      @grantdennert6980 Рік тому

      I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!

  • @jovane.tech-io
    @jovane.tech-io 4 роки тому

    Just amazing!

  • @epartsacc
    @epartsacc 5 років тому

    Amazing explanation!!! Can you do a video on adding characters to an array to make a string? Then do something with the string like compare it.

  • @9205aidme
    @9205aidme 2 роки тому

    Very important to have "No line ending" I missed that first time round, and I was scouring the code to see why it was calculating the av too soon! The code was fine!

  • @lesliefoster9027
    @lesliefoster9027 6 років тому

    Great video, thank you. Could you show me how to enter numbers using a keypad and an LCD display because I'm stuck ? IE. how would you do this lesson with a keypad and LCD display?

  • @TechWizCraft
    @TechWizCraft 6 років тому

    Hey can you do full tutorial about nrf24lo1?

  • @berylc2734
    @berylc2734 6 років тому

    Hi, when we use analog read, how can we put those values into array and average it and take the highest average value as threshold

  • @alanfairclough3427
    @alanfairclough3427 Рік тому

    Great video. I have trouble with other tutorials that show various ways of doing something rather than just show one way and let that sink in before cluttering one's feeble mind with too much variety from the start. I now have to figure out how to set up an array and input ten light sensor readings and then select the highest number from the array. That is the next challenge.

    • @paulmcwhorter
      @paulmcwhorter  Рік тому

      Perhaps you do not have a feeble mind, but have just had the burden of learning from feeble teachers.

    • @alanfairclough3427
      @alanfairclough3427 Рік тому

      @@paulmcwhorter No Paul, I have learned from you but your lesson 31 on arrays only covered the basics. Now I need to progress with others.
      I managed to compare the values and isolate the highest value but don't know how to get the index of the highest value in the array. Other teachers overcomplicate their explanations to show off. You are graciously gentle with beginners. (Humility is a virtue.)
      I have set up an array arrayS[10] with fix being the highest value in the array, magicNum is the index of the highest value
      The values are readings off a photoresistor mounted on an actuator sweeping 10 positions in the sky looking for the brightest spot.
      this is the part that is not working:
      fix=arrayS[0]
      for (k=1;k= arrayS[k]){
      fix=k;
      magicNum=k;
      Serial.print ("k= ");
      Serial.print (k);
      Serial.print(" fix= ");
      Serial.print (fix);
      Serial.print (" magivNum= ");
      serial.println(magicNum);
      }
      but my magicNum keeps increasing. Do I need an else?

  • @paulpattyn9070
    @paulpattyn9070 4 роки тому

    always top! thx a lot Paul. could you make one video about multitasking , state machine of ..? Want to control little machine with simultaneously processes.

  • @bigbread9000000
    @bigbread9000000 6 років тому

    I wonder if it is possible to do a video with arduino and s2 xbee, reading in frames and holding them to do conditional statements?

  • @ntokozohlatshwayo165
    @ntokozohlatshwayo165 5 років тому

    how can i continuously read data from a sensor then compare the current value to the old value?

  • @bushrafarhat3798
    @bushrafarhat3798 6 років тому

    I have followed your videos till now. GREAT WORK. Can you please include line following robot as a project step by step. It's one of the basic Arduino projects but it's not clearly explained on other UA-cam videos. Thanks

  • @jan42holland
    @jan42holland Рік тому

    Thank you for the Lesson. Can I use this to create a sketch for the ultrasonic sensor with a sketch with sensor A02YYUW? What should you pay attention to?

  • @tonylawless5626
    @tonylawless5626 3 роки тому

    Your awsome keep up the great work

  • @seditiousmonkeyart
    @seditiousmonkeyart 5 років тому +1

    Hi Paul, I have moved forward with my Arduino coding since beginning to watch your videos, thank you. I am currently trying to use a keypad to enter the RPMs (4 digits) for a motor then have this pass to a 4 digit, 7 segment, LED display and pass through to the code for the motor controller. I finally got my head around using Modulo for the display but I am yet to find a good explanation of how to collect the 4 digits from the keypad. I am still missing some pieces in getting the For loop and array to work together and much of the information I have found is either misleading or incomplete. Any chance you can do a video on collecting multi-digit numbers from a keypad?
    Many thanks.
    PS Do you have a Patrion Page

  • @robertherzog2087
    @robertherzog2087 4 роки тому

    Other than looping through the array and clearing each value, is there a way to reset the entire array?

  • @ajitpattewar6877
    @ajitpattewar6877 6 років тому

    hi the videows are wonderful and excelent but when i done coading i am getting an id returned 1 or 2 error what is that please explain sir mr any one

  • @harisahmad9323
    @harisahmad9323 6 років тому

    hello sir. I wanted to make an LED cube of [8x8x8] with sound sensor with arduino,,so that cube will bright with beats of sound,,I have done it but every time it repeat the same pattern I wanted it to to bright differently on different beats .do you know how to do that.

  • @taranagnew436
    @taranagnew436 6 років тому

    I think you should do a video on "understanding Arduino interrupts"

  • @9205aidme
    @9205aidme 2 роки тому

    Great work, but I did find a problem Paul, you need to reset "sumGrades = 0" after you print the average, other wise it keeps adding the previous average to the answer.

  • @subhopriyojoarder3536
    @subhopriyojoarder3536 6 років тому +2

    please do a video on Hardware Interrupts on Arduino

  • @CanalUn
    @CanalUn 4 роки тому

    Thank you very much !

  • @vogesdg
    @vogesdg 6 років тому

    Hi Thank you for this excellent education, was wondering I am trying to understand the ESP NOW master example in the ARDUINO IDE, in future maybe you can explain that software to us step by step?
    Especially this part, cant get my head around it:
    void sendData() {
    data++;
    const uint8_t *peer_addr = slave.peer_addr;
    Serial.print("Sending: "); Serial.println(data);
    esp_err_t result = esp_now_send(peer_addr, &data, sizeof(data));

  • @isuruliyanage7817
    @isuruliyanage7817 3 роки тому

    Hello sir, Thank you for your video. But I have a problem. I`m new to Arduino. Is there function to get minimum and maximum from a float array in Arduino?

  • @blackartista
    @blackartista 6 років тому

    Mr. Paul McWhorter can you do something little about GSM(s) in your Arduino Lessons?.With your knowledge I believe we might be missing some techniques on programming GSM

  • @nikalfahb2072
    @nikalfahb2072 5 років тому

    Good job

  • @grantdennert6980
    @grantdennert6980 Рік тому

    To anyone having a problem with the serial monitor skipping the first value: I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!

    • @grantdennert6980
      @grantdennert6980 Рік тому

      I guess I could've just finished the video first too haha!

  • @bholeshankar852
    @bholeshankar852 6 років тому

    How to use bootloader atmega328p by the help of arduino uno explain please

  • @NJ-md8uu
    @NJ-md8uu 5 років тому

    can you explain about wire liber

  • @vikasmarkanday6663
    @vikasmarkanday6663 5 років тому

    you are awesome !!!

  • @venkateshgopalaswamy2457
    @venkateshgopalaswamy2457 2 роки тому

    Is it possible to initialize an array and dynamically adjust its length like in python.

  • @qzorn4440
    @qzorn4440 2 роки тому

    do you have one on using an arduino mega as a modbus master serial2 rtu rs485 19200N1 to read a panel-meter input registers 30001 30002 then display the values? 🤔thank you

  • @AliensInc.
    @AliensInc. 6 років тому

    One thing that you should show is how to handle Arduino WatchDog. This is for me essential as is can help a malfunction in the code by low power us such.

  • @qkcb
    @qkcb 6 років тому

    Are there more similar videos coming soon"

  • @astaragmohapatra9
    @astaragmohapatra9 6 років тому

    We don't need to declare cleanup sumgrades at the end as after one time running the arduino will start reading from the top ,so in declaration sumgrades is initialised with zero

  • @oke806
    @oke806 3 роки тому

    Hello sir,
    I want user to input data and store it into an array.

  • @orlagh10
    @orlagh10 3 роки тому

    unreal thanks!

  • @paparoysworkshop
    @paparoysworkshop 5 років тому

    At 24:15 when the error came up and you talked about cleaning up the code, you stated there is no reason to clean up the array itself. Now if you ran the code and the first time you entered 10 grades and the second time you only entered 5, then the first five would be overwritten with new data, but the second five from the first time run would still be in the array. Of course, you only would extract the first five numbers so it really doesn't matter. So I guess my question is, "would that be considered bad programing practice since the array would become cluttered?"
    Just a thought.

  • @tamburaimashonganyika4757
    @tamburaimashonganyika4757 2 роки тому

    its making sense thanks a lot

  • @wooferhound7571
    @wooferhound7571 3 роки тому

    How do you dimension an array ?

  • @arniep740
    @arniep740 3 роки тому

    Thanks for this tutorial. One question...Why do you declare "float grades [25]" at the top? I don't see where you use a variable named "grades." Thank you.

    • @arniep740
      @arniep740 3 роки тому

      Never mind...I see where you do use "grades."

  • @MrSirPain
    @MrSirPain 2 роки тому

    How would I program the array size when I do not know how many elements (slots) I need? Like a user inputs str of variables.

    • @paulmcwhorter
      @paulmcwhorter  2 роки тому

      Diminsion it the largest you might need, the use what is needed.

  • @pascalsampatsing5528
    @pascalsampatsing5528 6 років тому

    Sir, could I also use return (); in the last command: sumGrades= 0; ?

    • @mikaelkarlsson9945
      @mikaelkarlsson9945 6 років тому

      Pascal Sampatsing There is no need to return() anything, you're still in the loop..
      Just "empty the bucket" and you're fine..
      (If this were a function, you might want to return the value from the calculation for use in the rest of the main program. Depending on how you declare your variables)

  • @radkarolv.castro6068
    @radkarolv.castro6068 4 роки тому

    Mr. Mcwhorther, I have a question. How to display 30 random numbers using arrays - sorted highest to lowest. I hope you can immediately help me :))) thank you in advance :)
    from the Philippines

  • @nelsondarwinpaktech3954
    @nelsondarwinpaktech3954 3 роки тому

    Sir....These tutorials are meant for to get some knowledge for less intelligent programmers like me....easy to understand....

  • @imretoth8150
    @imretoth8150 6 років тому

    Beste Mr McWorther,
    First off i really like your video's. And im getting in to HAB. But how do you let an arduino (or just the Artmel Mega328 talk to a ham transmitter? Or is a ham radio shield used, or is it done with APRS?
    Greetings,
    Imre

    • @paulmcwhorter
      @paulmcwhorter  6 років тому

      I really can not advise on this because it is very complex legally. When you start dealing with long distance RF communication, there are lots of laws, and it depends on where you live, and what type of licenses you have.

    • @imretoth8150
      @imretoth8150 6 років тому

      Thanks for the quick reply anyways!

  • @user-st1ml9rl6b
    @user-st1ml9rl6b 6 років тому

    Just for curiosity, are you going to make tutorials for arduino nano or any different types of arduino sir?

    • @darthvader8433
      @darthvader8433 6 років тому

      When you attach the Arduino, simply select the device type. Different devices have different numbers of and numbering of pins, so make sure your connected component pins are corrected in the code.
      The Arduino code is universal across Arduino models.

  • @sona_YT-jn7up
    @sona_YT-jn7up 3 роки тому

    Thanks man

  • @dharmendrachauhan7884
    @dharmendrachauhan7884 3 роки тому

    Hi Sir,
    I run this average score example in my Arduino uno,nano,etc.then serial.println(please input your grade) line print in Serial monitor two time at a time.my code is as same as like your code. Please help.

    • @grantdennert6980
      @grantdennert6980 Рік тому

      I had this problem and worked through it for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!

  • @vikasverma8668
    @vikasverma8668 3 роки тому

    Sir, this program is not working in my Arduino ide

  • @hunterwilkie4812
    @hunterwilkie4812 5 років тому

    every time I open the serial monitor and input the number of grades I woud like to be averaged it skips the odd number. for example, if I wanted to input 5 grades, for the first, third and fifth grades, they will automatically be inputted at 0 and I can only input grades number 2 and 4. it doesn't let me input 1, 3 and 5. and my code is the exact same as yours. no errors. I was wondering if you know the issue or if anyone else has ever had this issue?

    • @grantdennert6980
      @grantdennert6980 Рік тому

      Yeah I have this same problem it asks twice for the grade

    • @grantdennert6980
      @grantdennert6980 Рік тому

      I worked through this problem for hours with ChatGPT, and what I figured out is that in the Serial monitor you must have the line ending set to "No Line Ending" otherwise it reads the new line or carriage return as a separate value-0. Hope this helps!

  • @laurenth7187
    @laurenth7187 3 роки тому

    First you should take care about the memory of the Arduino, which might be overflowed by an array... imho. So there should be a memory check routine available ?

  • @dougc3086
    @dougc3086 5 років тому +1

    What if the answer to "How many Grades? " was 26? Wouldn't that cause a stack overflow?
    How would you avoid this issue in this sketch?

    • @user-vn7ce5ig1z
      @user-vn7ce5ig1z 5 років тому

      It would cause an array-out-of-bounds exception, and he should have at least mentioned it as a thing to look out for. You can deal with it by checking numGrades against your array size, preferably immediately after they input a number that's too large rather than waiting until _after_ they enter 25 grades.

  • @royaustin473
    @royaustin473 2 роки тому +1

    Awesome!

  • @gitagoswami6878
    @gitagoswami6878 4 роки тому

    why not calculate the sum in the loop itself like
    for(int i=0;i

  • @pierdolio
    @pierdolio 6 років тому

    I forced myself to watch your presentation through to the end in case I might have missed something. If I were a student in you class I would definitely fail miserably because I have a hard time following your train of thought, meaning I don't see things the way that you do. To me, an array is like a BINGO grid.

  • @raymondzhao9557
    @raymondzhao9557 3 роки тому

    really cool

  • @philluvschips3787
    @philluvschips3787 2 роки тому

    Has anyone got a solution? I'm using the while (Serial.Available) routine but Arduino just blows right by the 1st and goes to the next while statement, then blows by the 3rd and goes to the 4th etc I have searched all over the internet, used 'if' statement instead, tried a short delay, tried 'flush' .serial, nothing works, this is most painful :(

    • @paulmcwhorter
      @paulmcwhorter  2 роки тому

      Is your serial monitor set to no line ending?

    • @philluvschips3787
      @philluvschips3787 2 роки тому

      @@paulmcwhorter OMG, I should really stop doing this until wee hours of he morning :) TY.

  • @k0pR0LiTh0s
    @k0pR0LiTh0s 6 років тому

    Very nice! but you forgot to say how the array can corrupt the code.

  • @familytime167
    @familytime167 6 років тому

    please make tutorial on msp 430 microcontroller

    • @igrewold
      @igrewold 6 років тому

      Use Energia, it makes it like an Arduino (IDE)
      ua-cam.com/video/V0GrBUbomDA/v-deo.htmlm11s
      energia.nu/guide/
      ua-cam.com/video/-KKmkwHapSw/v-deo.html