Paul McWhorter arduino lesson 21


If what we’re going to do today is a little bit of a follow on from lesson number 20 and lesson number 20, we learned how to hook up and work with an RGB LED and we’re going to follow on that lesson and we’re going to do a Little bit more mixing of the colors, and so if you haven’t already done lesson 20, you probably need to go back and do that one. I don’t want to start over from scratch, because then this lesson would be too long, but this is a follow on from the earlier lesson number 20. So what I need you guys to do is I need you to get your eel egg. Oh super starter, kit. Out has all the components you need for this. What you don’t have one look down in the description: click the link. 35. You get all the components, including the Arduino that you need to play along at home. With this with a series of lessons. Also, I need you to pour yourself a nice big mug of iced coffee. I am out of coffee I’m out of coffee. You know you guys, you know what I do. I make this in the morning a great big thing of it. I drink it throughout the day and when I run out of coffee, I stopped making Arduino lessons. You want more Arduino lessons. Somebody ought to send me a Keurig. Ok, somebody should send me a Keurig, and this is my address.

Let me get out of your way. Palma quarter, box 496, Eldorado, Texas, 7, 6. 936. Send me a Keurig. Send me a lot of those little Starbucks those little Starbucks k cups to go with the Keurig and boom. You will be getting a lot more lessons from me because when I run out of coffee, I stop making lessons we’ll have more lessons tomorrow, but I will go ahead and finish this one and what we are doing is we are learning how to mix colors and You can go to the last lesson and kind of catch up with where we are. This was the code where we left off before and let’s just run this code really quickly to kind of remind you of what we could do in case. You don’t remember so. I’M gon na go ahead and I think I need to move over to this view and then I will pop open my serial monitor and here it is here so it says what color do you want you notice as a tribute to our British listeners. I spilled it as Co. L, oh, you are okay. So what color do you want red and when I type red boom this turns red man? I wish I really wish you could see it better, but this auto this auto color balance is making it where it doesn’t show real well and then the next one is green. Okay, that is great man. It is just so perfect when I look down at it, but because this document camera tries to automatically adjust the exposure, it kind of washes this out, then the other one that we can do is blue and it turns the LED, blue and just in case what Happened did not work blue.

Why am I not getting blue let’s see what is going on here? Red green blue blue looks like that. That really really really really looks right. So why is that not turning blue? What color do you want B, lu d? Let me reset this thing: Yui, okay, resetting it works red, gr, ven, and then I do believe that I had another color in there which was aqua and then, when I type in aqua boom, it goes to aqua red. It turns red green. It turns green and blue. It turns blue okay, it’s working this time, alright. So in this, what I’ve done primarily in this earlier in this earlier work is just kind of primarily red turns the red on green turns the green on blue turns the blue on just so, you can see this is just an RGB LED under here that I Have put a little a little color globe on top of a little color a little ping pong ball on top of alright, so let’s think a little bit about how colors work. You know people talk about primary colors and primary colors are red, green and blue, and if you have red, green and blue, you can mix any of the other colors that you want, but really there’s. Nothing fundamental about red, green and blue it’s, just kind of like they are orthogonal away from each other, so that with those three you can mix any other color that you want, but there’s other primary colors.

So let’s look at this. This would be kind of a picture of what I’m talking about. If you take red and green, you can mix and make yellow. If you could take green and blue, you can mix and make cyan. If you take blue in red, you can mix and get magenta. Okay, but red and green and blue are not the only primary colors. You could also come at it from this angle. You could start with cyan, magenta and yellow. If you mix I an in Genta kit. Together, you get blue if you mix magenta and yellow together. You get red if you mix, yellow and cyan together, you get green and you could just switch along this, this kind of color wheel and there would be an infinite number of primary colors that you could use to mix all the other colors. Now, for our particular case, we have three LEDs that are inside of this RGB LEDs and those three LEDs are fundamentally, I have a red one. I have a green one and I have a blue one, and so what I want to do here is just kind of play around with mixing the colors, but I got to use these as our as my primary colors and then let’s see if we can get Some of these other colors and so let’s see if I can find a nice view here. I think this will be a good view. That’Ll, allow you to see all the different things, so the first thing that we want to do is let’s see if we can mix red and green and get yellow, and so we need to come in here and I’m going to take this this one that I Did earlier like let’s just take this this off one here and let’s do a control C, and then I am going to paste control V and we’re gon na say.

If my color equals yellow, then what we would want is, if it’s yellow. We would want blue to be completely off I’m, going to change these to yellow I’m gon na change these to analogue right. So we can get a little more fidelity, it will be end and then and logged and then and log, and then for the blue. We don’t want any blue at all in yellow, so that’s going to be set to zero and then let’s just try the full turn the full on. So that would be 255. That would be 255, okay and now I’m going to download this, and that looks like it’s going to be successful, open up the serial monitor and then it is going to ask me what color do you want co? Al? Oh, you are for all of our British friends, I want yellow, I will type and then, when I type yellow boom, this came on, and this is not really a very good yellow and you can probably not see that very much at all. But it’s really way too much green. I mean it looks a lot more green than it does red and so I’m going to turn the green down to like a hundred like that I’m going to download that alright try again what color do you want? Yellow, okay – and that is a very, very nice yellow. Let me see if I can. Just you see if you can kind of peek through my fingers, you can see that it’s starting to get to be a very, very close color of yellow all right.

So if we come back over here, we have mixed red and green to get yellow now, let’s do green and blue to get cyan. So we will come back over here and we will go ahead and copy this command, because it’s got the analog rights in it and then we will paste it and now what we want is and so yellow we want cyan and cyan is going to have cyan. Is going to have no red at all, and so the red needs to go to zero and then let’s just start at 255, 255 and then we’ll just see how that works pop open the serial monitor. What color do you want sigh end and then hit enter and boom? That is a really really nice cyan see I try to cover it up, so it won’t auto scale quite as much. That is a really really nice cyan’t. I don’t think that I need to tweak that one at all. I think that that is a pretty darn close cyan. What do we want to do next? We want to do magenta, so I will come in. I will copy this and then I will add it to the code and then I will did I add it: aqua, cyan, yellow off. Let me try and control V. Okay. Now I have to cyan so this second cyan I will change and I will make it mud, Genta and magenta would want to have let’s see here.

Magenta would be no green and it would be red and blue. It would be no green, zero and red I’ll turn all the way up to 55 and then green is zero in blue we’ll. Try this and then we’ll tweak it if it’s necessary right. So then I’ll pop this open. What color do you want? I want magenta magenta, okay, that is a pretty darn good magenta. If I look at that, I think it’s a little too blue and it needs it needs to tone down that blue a little bit. So if I come in here, I’m gon na say about a hundred and now I’m going to try it again because it’s a it’s a little purple, it’s purple ish, but it’s, not really pink so let’s say what color do you want magenta? Oh, that is much much better. That is a very, very nice magenta, a very nice magenta. I wish I could make that okay, you can believe if there was some way, I could show it to you better. I would but there if I cover it up, it shows it a little bit better, and so that is a very nice magenta. Okay, so do you see how you can mix any color that you want, and so red, green and blue are easy, because that’s what the LED is already putting out you can mix them to get cyan, magenta and yellow, and then you can just get any imaginable.

Colors and the way you do it is you don’t just turn them on and off, but you can turn them up and down into three values, and so you can see you’ve got 255 different choices of how strong you want the red to be 255 choices of How strong you want the green to be and 255 choices of how strong you want the blue to be, and actually, if you include zero, that’s really 256, so how many different possible colors? Can you get from this scheme? You can get a total of 16 million different colors just by adjusting these three commands and guys. I hope you will try this. I apologize that what you’re seeing on the camera is not nearly as brilliant is what I am seeing in person here. Try this. Let me know how it works at home: leave some comments down below think about giving us a thumbs up. Think about subscribing to the channel think about sharing this with other people also think about sending me a coffee finger I’m. Just joking about that, of course. Okay, Palma quarter from top tech boy comm.


Paul McWhorter arduino lesson 21 Video







Paul McWhorter arduino lesson 21 news








Paul McWhorter arduino lesson 21 Social






We’re opening the Arduino IoT Cloud to other platforms, starting with the ESP8266 by Espressif Systems — NodeMCU, SparkFun’s ESP Thing, ESPDuino, and Wemos (to name a few) — along with other inexpensive, commercially available plugs and switches based on this module.
safe image.php?d=AQB6YIkvOaOwGAQg&w=720&h=720& content%2Fuploads%2F2019%2F10%2FDSC00029 - Paul McWhorter arduino lesson 21

How fast can you run the 40-yard dash? Find out with your own wireless timing gate system.
safe image.php?d=AQDAnlSUYJivJY5S&w=720&h=720& mOWHBn2WBw - Paul McWhorter arduino lesson 21



(Visited 58 times, 1 visits today)

About The Author

You might be interested in

Comment (30)

  1. I’ve played with this setup for a while and it worked out really well, of course I wasn’t pushing for 16×10^6 colors but it is fun. I though about trying a random number generator and will continue just for the heck of it, who knows what I’ll get. Thanks Paul.

  2. Definitely a thumbs up on this one! And I am going to wire and code this one up for sure. Thanks for all you do.

  3. Using a loop to set integer values for each colour of the RGB LED.
    here’s the code! it uses a loop to ask a question and then uses a function to input the values:
    int redpin=9;
    int greenpin=10;
    int bluepin=11;
    String setmsg=”Would you like to set a colour for RGB LED?”;
    String redmsg=”What value do you want for colour red?”;
    String greenmsg=”What value do you want for colour green?”;
    String bluemsg=”What value do you want for colour blue?”;
    String answer;
    int redval;
    int greenval;
    int blueval;
    void setup() {
    // put your setup code here, to run once:

    void loop() {
    // put your main code here, to run repeatedly:
    while (Serial.available()==0){

    void RGB(){
    while (Serial.available()==0){



  4. Another treasure trove Paul. many thanks from a 81 year old newbie in the UK. Already looking forward to the next lesson.

  5. I will be looking forward to watching this tutorial as soon as I can get the lesson 30 code to work. Can not digitalWrite from within the “IF CLAUSE”. Have been troubleshooting this problem for days with no joy. Wondering if there is something wrong with my RGB LEDs. Will try it with individual LEDs. The RGB light up when powered directly from 5 Volts but not from pins 8, 9, and 10. Maybe the readString is not working properly. Guess I’m doomed to “fall behind” the rest of the “class”. Would still like to see/print out the entire code as presented. Al in Ann Arbor.

    1. Simplify. Take evertying out of the if clause but a simple print statement. Verify if you are getting into the if clause. If not, you have a typo in the line of code of the if statement

    2. All, I enter the code as Paul presents each piece, even if I have to pause the video and back up until I get it correct and it compiles. After getting the code to work you can print it from the file tab in the Arduino IDE.

    3. @Paul McWhorter
      I have the same issue. Tested the LED and it is wired correctly. Copied the sketch, then deleted the code after digitalWrite(redPin,HIGH); } } I added a Serial.print(myColor); command after Serial.readSrting command. Compiled and uploalded the file. The serial monitor displays the correct text, including my input, but the LED will not light. I am running on a Mac OS 10.14.5, could it be the compiler on the MAC? I have tried this with three different Arduino boards. All the other tutorials work fine until now.

    4. @Chuck Pickering Thanks Chuck. As it turned out I am confident that was ultimately using the code that Paul presented, but it still would not run properly. After much thought and experimention I discovered that my Serial Monitor was adding spaces when I responded with “red”, “green”, “blue”, causing the “if conditional” to always return a “false” that the “if clauses” never executed (something I never expected!). The solution was to include a “.trim()” statement to trim off any invisible spaces. Please see the code that I sent Paul under my reply to him under Lesson 20. Sorry, I did not intend to turn this into a “Forum”

  6. Another great lesson! How about adding a pot in each of the RGB legs and varying  the applied voltage co you could continuously change the colors? Does the Elgoo kit have 3 pots of the same value?

    1. A great idea. Dont think the elegoo kit has three pots, but they cost next to nothing on Amazon . . . grab a few in your next amazon order.

  7. I am following your videos and learning an a lot. But I have a request for you to make a video about E – 3, which you said you might make. I would like to understand this engineering concept! you are the best teacher I have ever had!!

  8. the reference is in video #9 of the arduino tutorial at ten minutes into it when you explain OHM’S LAW and talk about setting your calculator at a certain notation.

    1. That is engineering notation. Look at the LIVE Shop talk I released today and it will explain the whole thing

  9. I would appreciate a full explanation on this if you can find the time. I am great full for all the time that you put into these videos!! They are the best learning tool I have ever found!

  10. I bought the elegoo from your link and it has been great but the actual arduino did not work correctly, but I had an original which I have been able to utilize for the videos. Again I appreciate all the work you put into these great videos!!

  11. Just came back from holiday without Internet. Happy to catch up soon and try this colours with 3 potmeters I think. Thank you for this lesson.

  12. Paul, Still watching and learning, Sir! I noticed you started to add a delay in the loop with a integer, then declared a variable int dt=1000; , but did not use it in the loop, but I did, BOOM! NOTE: I did a Crazy mind thing whereas I declared my variable as buzzPin=8; however every time I called the variable I input bussPin, need more coffee!!! Thanks, Gary

  13. I used a potentiameter and 2 pullup resistors with RGB LED and switch between main colors by tapping a key, adjusting the strength of each color by turning the nub, and clicking another button to set the color. It’s amazing!!!


Your email address will not be published. Required fields are marked *