Tutorial 10: Fade an LED: Arduino Course for Absolute Beginners (ReM)

🤩 Get the 10 Arduino Programming Tips PDF here: 👇👇 https://bit.ly/4o0eL4Q **If you like this, I think you'll like the premium Arduino training we offer. Check it out here** https://bit.ly/3nSBPUs We designed this circuit board for beginners! Kit-On-A-Shield: https://amzn.to/3lfWClU SHOP OUR FAVORITE STUFF! (affiliate links) --------------------------------------------------- Get your Free Trial of Altium PCB design Software https://www.altium.com/yt/programming... We use Rev Captions for our subtitles https://bit.ly/39trLeB Arduino UNO R3: Amazon: https://amzn.to/37eP4ra Newegg: https://bit.ly/3fahas8 Budget Arduino Kits: Amazon:https://amzn.to/3C0VqsH Newegg:https://bit.ly/3j4tISX Multimeter Options: Amazon: https://amzn.to/3rRo3E0 Newegg: https://bit.ly/3rJoekA Helping Hands: Amazon: https://amzn.to/3C8IYXZ Newegg: https://bit.ly/3fb03X1 Soldering Stations: Amazon: https://amzn.to/2VawmP4 Newegg: https://bit.ly/3BZ6oio AFFILIATES & REFERRALS --------------------------------------------------- ►Audible Plus Free trial: https://amzn.to/3j5IGrV ►Join Honey- Save Money https://bit.ly/3xmj7rH ►Download Glasswire for Free:https://bit.ly/3iv1fql FOLLOW US ELSEWHERE --------------------------------------------------- Facebook:   / programmingelectronicsacademy   Twitter:   / progelecacademy   Website: https://www.programmingelectronics.com/ Click Below to Read About This Topic on Our Website https://www.programmingelectronics.co... Description: Arduino Course for Absolute Beginners Lets expand the repertoire of output that we can use by looking at the function analogWrite(). I experienced much confusion with analogWrite(), because I suspected that it had to do with the analog pins on the Arduino. The function, however, has nothing to do with the analog pins. There are 5 pins on most Arduino boards marked with an '~' next to the pin number - these pins can be invoked to rapidly change the power being applied at the pin - this is a technique called pulse width modulation (PWM). You Will Need LED - any color is fine 220 Ohm Resistor Alligator Clip Glacial ice cubes Step-by-Step Instructions Take the short leg of your LED and stick it in the GND pin. Take either leg of the resistor and place it in pin 9. Connect the long leg of the LED with the other leg of the resistor using an alligator clip Plug the Ardunio into your computer with the USB cable Open up the Arduino IDE Go to File, Examples, 01.Basics, Fade Click the Verify button (Top Left). The button will turn orange and then blue once finished. Click the Upload button. The button will turn orange and then blue when finished. Watch in mesmerizing amazement as the LED fades in and out. The sketch starts with the usual multiline comment describing the sketch and how to set up the circuit. The first block of code we encounter is the declaration and initialization of 3 int variables... int led = 9; // the pin that the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by The variable names and comments are both descriptive and helpful - remember this when naming and commenting your own code - it is a pillar of success! The "brightness" variable will store the value of the current brightness of the LED. "fadeAmount" is the rate at which the LED will fade and brighten. And of course, as the comments explain, "led" is simply the pin number where we have attached our LED (through a 220 Ohm resistor). Now that we have declared and initialized our variables, we move on to setting up the board with the setup() function... void setup() { // declare pin 9 to be an output: pinMode(led, OUTPUT); } The only thing we do here is set the mode of pin 9 as an OUTPUT using the pinMode() function. Recall that pinMode() takes two arguments - the pin number and the mode. In this case we assign the pin number using our variable "led", which we previously initialized as the number 9. By now you know that setup() only runs once - the code inside the setup() curly bracket will only be executed a single time by the Arduino. Where the real action happens is in loop().