blinking led arduino code

It is an easy way, but it might not behave exactly, like you want to. If you have more questions, please post them in the comments section. // the setup function runs once when you press reset. The tool we are going to use is the Arduino IDE which is freely available on the Arduino website. Connect LED to another pin of Arduino and change the blink time. We use a built-in function called pinMode() to do this. You can find it in table 16-5 in page 143 of the ATmega328 Datasheet: The next line (number 5) tells the CPU to generate a hardware interrupt whenever the timer reaches the maximum number (or overflow). It took me many Google searches and digging through various resources, but I finally (We highly recommend you type code instead of copying and pasting so that you can develop your coding skills and learn to code by heart.) Can you write the code for that? Look into the millis() function.Search: aduino multitasking to learn morehere's the code:class Flasher, int ledPin; // the number of the LED pin, long OnTime; // milliseconds of on-time, long OffTime; // milliseconds of off-time, int ledState; // ledState used to set the LED, unsigned long previousMillis; // will store last time LED was updated, // and initializes the member variables and state, // check to see if it's time to change the state of the LED, if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime)), previousMillis = currentMillis; // Remember the time, digitalWrite(ledPin, ledState); // Update the actual LED, else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime)), previousMillis = currentMillis; // Remember the time, }taken from: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution, int led3 = 3;int led4 = 4;int led5 = 5;// the setup routine runs once when you press reset:void setup() { // initialize the digital pin as an output. For examples: Big LEDs usually are used for lighting. I had to run the last jumper from the GND on the Arduino itself to have the third led flash. This process is called compiling. for (int i = 0; i <= 5; i++) { led HIGH delay(500); led LOW delay(500); } Also the blink sequence has to be triggered, and have a reset after it is done. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. IDE is an abbreviation of Integrated Development Environment. Hence there should be another element to limit the current. The IDE only checks if it can read your code. I decided to try blinking the LED using serial port on Arduino myself, connected a green LED to pin 1 (TX) of the Arduino, and came up with the following code: Note that this approach doesn't truly blink the LED, only toggles it between high brightness and low brightness (due to the start/stop bits in the UART protocol). The delay() function occupied the program control entirely in the previous examples. You are using timers and counters together to toggle pin 9. First of all, our loop() function is empty, is the Uno doing nothing? Adafruit METRO 328 Fully Assembled - Arduino IDE compatible, Half Sized Premium Breadboard - 400 Tie Points, Premium Male/Male Jumper Wires - 40 x 6" (150mm), "Another belief of mine; that everyone else my age is an adult, whereas I am merely in disguise", Program an AVR or Arduino Using Raspberry Pi GPIO, Current Limiting Stepper Driver with DRV8871, A Minority and Woman-owned Business Enterprise (M/WBE). You can find more basic tutorials in the built-in examples section. We make use of First and third party cookies to improve our user experience. possible. We will see how to calculate the resistor value later in the later section. You can follow along virtually using Tinkercad Circuits. This is a circuit we think you'll want to make frequently, so it's saved as a circuit starter! You can resize the code editor by clicking and dragging the left edge. Another form of comment starts with /* and ends with */. digitalWrite() writes the value (LOW or HIGH) specified to a given pin. Therefore you could have typed 13 as well. (not) operator to invert that value, and thus toggle the state of the LED. In this tutorial I will show you how to make multiple LEDs blink with Arduino. But who is this mysterious OC1A pin? Open the new sketch File by clicking New. It is also one of the most popular Arduino program, and I bet electronics enthusiast has run it at least once in their life. ->Read our guide aboutWhat You Can Build with Adruino. Here is the correspondence between the constant and the digital pin. Hardware Required Arduino Board optional LED 220 ohm resistor Circuit This example uses the built-in LED that most Arduino boards have. We are using the Arduino Uno board, and we will choose pin 7. Your donation will be used for hosting, videos and maintenance, among other things. If you send a 1, the LED will turn ON (logic HIGH). You must refer to the datasheet to understand the polarity. First separate input and output, meaning button check code and LED blink code. They also show you how to use the Arduino IDE to upload code and run programs. To toggle blinking, just change it e.g. Inputting a. on Introduction, Led serial wise blink hogi ek ke baad ek but mujhe ye krna h ki.pehle led 1,2,3,4 ek k baad ek blink ho fir led 4,3,2,1 ek ke baad ek band ho, Answer For a more in-depth walk-through on setting up and programming your physical Arduino Uno board, check out the free Instructables Arduino class (first lesson). Are there any canonical examples of the Prime Directive being broken that aren't shown on screen? Whenever the timer reaches its maximum value, 65535, the interrupt service routine runs and toggles the LED (in line 10). Most Arduinos have an on-board LED you can control. messages appears. While. The bottom right shows the analog pins, which has 1024 possible values: 0 to 1023. You could see both variables to be of a different kind. Back in the components panel, find and bring over an Arduino Uno board. Affordable solution to train a team and make them project ready. 6 years ago. pinMode(2, OUTPUT) Before you can use one of Arduinos pins, you need to tell Arduino Uno R3 whether it is an INPUT or OUTPUT. Step 3: Compile and upload. What is scrcpy OTG mode and how does it work? For most of LED, we need to use a resistor. These commands are written in a syntax that the computer understands. This tutorial provides in-depth knowledge that helps you understand the working principle. In SMD (surface Mount Devices) the anode and cathode indications are difficult to notice. Change the code so the LED tuns on, wait for 0.5 second, turn off the LED and wait for 2 seconds. Clones could need special drivers being installed, while the original is just plug and play. I am confident that after reading this guide, you can now complete the connections and try all four methods of toggling the LEDs. When o release the button, LED will be OFF. Some As you can probably tell, this code will blink the LED a bit slower than once a second, rather once every 1.05 seconds (that is 65536 divided by 62500). Agree The best answers are voted up and rise to the top, Not the answer you're looking for? 1 for the current led state, 1 for the blinking state. The number of LEDs you can light up depends on the set LED current. pinMode(led, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(100); {digitalWrite(led2, HIGH); delay(100); digitalWrite(led2, LOW); delay(100);} {digitalWrite(led3, HIGH); delay(100); digitalWrite(led3, LOW); delay(100);}// wait for a second }. We are using the Arduino Uno board, and we will choose pin 7. The heart of the Arduino is the AVR-chip. By pressing this button you tell the IDE to verify your code for possible errors. The faster player wins and the appropriate LED is turned on (for 5seconds) to show the winner. You find this information on many webpages with a click of the mouse. In the op menu of the Arduino IDE you can choose: The IDE should open the code to blink the builtin LED automatically. Looking for job perks? One should blink with a 1 second delay and the other should blink with a 0.1 second delay. By using this website, you agree with our Cookies Policy. Arduino there was no YouTube with fancy instruction videos. Edit the resistor's value by adjusting it to 220 ohms in the component inspector which appears when the resistor is selected. Did you make this project? This is exactly what line 6 takes care of. Move the red jumper wire from the Arduino 5V connector to D13, as shown below: Upload the modified sketch to your Arduino board and the LED should still be blinking, but this time using pin D7. The complete code is to big to share, but it runs a bit like the following: There is a "bankValue", it is filled by a user, and counts back to zero. On whose turn does the fright from a terror dive end? Next up is a a yellow command block that waits for one second, simple enough. I want to connect a LED to PIN 13 (OUTPUT) and a button to digital PIN 2 (INPUT). Besides compiling the IDE also checks if the code is correct. pinMode (led, OUTPUT); pinMode (led2, OUTPUT); Also the other possible method to do same through Arduino. Wait for another second, and then repeat everything again. After you build the circuit plug your Arduino board into your computer, start the Arduino Software (IDE) and enter the code below. For security reasons, an e-mail has been sent to you acknowledging your subscription. Wait for 1000 milliseconds, or one second. Move the red jumper lead from pin D13 to pin D7 and modify the following line near the top of the sketch: Download File Copy Code int led = 13; so that it reads: Download File Copy Code int led = 7; Upload the modified sketch to your Arduino board and the LED should still be blinking, but this time using pin D7. Your program will immediately start after uploading. This function will be called over and over again. Arduino Uno code uploads successfully but nothing happens. At the bottom of this page you'll find the course material button. We can find this information in the chip's datasheet (page 140): For me, this was a little confusing, as the datasheet says that the hardware will toggle OC1A on Compare match. Hi..I just have a question, I have gone trough some example codes for arduino nano board but my doubt was not clear, I wanted to build a code where leds are connected to port b for all the 8 pins and I wanna blinking them alternatively similarly how we blink in 8051 just by sending hex value to port 0x55 and 0xaa. Here I will share some interesting facts and basics about LEDs. You'll find more information about this driver on the Sparkfun website. If you are using multiple LEDs, it is better to use a buffer or a MOSFET switch to control them. If you run this example with no hardware attached, you should see that LED blink. I tried changing the "if ledState == true && blinkState == true" to a while and it does start blinking but then it doesn't turn off. Once you provide the forward voltage for the LED, they act like a closed switch. Asking for help, clarification, or responding to other answers. The value of the resistor in series with the LED may be of a different value than 220 ohms; the LED will light up also with values up to 1K ohm. Click to enlarge image. If you don't mind things being damaged, by all means go ahead and discover yourself . For blinking you already have a state variable named blinkState. Finally, we take the number of seconds and calculate the remainder of dividing it by two, using the modulus (%) operator. Open the new sketch File by clicking New. int led = 13; int led2 = 12; int led3 = 11; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. In the image below, you can see that visible light has a wavelength range from 400 nm to 700 nm. After this the program continues with the loop(). pinMode(led3, OUTPUT); pinMode(led4, OUTPUT);pinMode(led5, OUTPUT); }// the loop routine runs over and over again forever:void loop() {for(int counter =3;counter<=6;counter++){digitalWrite("led"+counter, HIGH); delay(100); digitalWrite("led"+counter, LOW); delay(100); }}. With over 600 pages, the datasheet can be overwhelming at first sight, but it's a very valuable resource which you can refer to whenever you want to know more about the specifics of this chip. Via an USB cable the compiled program could be uploaded to the Arduino. Where does the "magic" number 256 comes from? On the Arduino UNO, LED_BUILTIN is an alias for 13 (the builtin LED pin). Which was the first Sci-Fi story to predict obnoxious "robo calls"? Comments allow you to provide human readable additional information which is completely ignored by the computer. This is the SMD variant of the chip. This is our first Arduino tutorial and therefore I have to explain some things to get you started. subject per video. LED forward voltages for various colour LEDs are summarized in the table below. Step 3: Create LED on/off loop in Arduino Code. I am trying to implement a toggle switch to turn blinking ON & OFF. Step 3: Set Pin 3 HIGH. How does it work then? For a more advanced version of this Arduino code, also check out the Blink Without Delay starter, which uses the current time to keep track of blink intervals instead of delay(); To program your physical Arduino Uno, copy the code from the window and paste it into an empty Arduino sketch, or click the download button and open the resulting file using your Arduino software. Did you notice the small LED flashing on the board itself? The LEDs positive terminal will be longer than the negative terminal, as shown in the image above. This function blocks Arduino from doing other tasks during the delay time. To start, we will work on blinking an LED, the Hello World of microcontrollers. To complete the connections, you will need: Connect the cathode pin of the LED to the Arduinos GND pin. I am beginner with arduino and i need your help to do that. In line 4 we set a flag called CS12 in the TCCR1B register. So my led keeps blinking. First connect a jumper wire from GND to the negative rail on the breadboard. First, we set the OCR1A register to 62500. Warning: Never connect an LED directly to the supply. In this section, we will see a few examples of how we can drive the LED using Arduino UNO. Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below. Example code controls the built-in LED on Arduino/Genuino UNO. Howerver, please do not copy the content to share on other websites. Click "Start Simulation" to watch the LED blink. Multiples Blinking LEDs Algorithm. Often cheaper components are being used which is not an advantage. Configure an Arduino's pin to the digital output mode by using, Open Arduino IDE, select the right board and port, See the result: The built-in LED toggles between. Connect Arduino to PC via USB cable Open Arduino IDE, select the right board and port Copy the above code and open with Arduino IDE Click Upload button on Arduino IDE to upload code to Arduino Open Serial Monitor Press the button 4 times See the LED: The LED toggles between ON/OFF periodically every second See the output in Serial Monitor COM6 Send I am using the Blink_LED_2_interval time variable, a predefined delay for LED2. Its value is the amount milliseconds the program has to wait. Also note, that using delay() is not the best way to debounce a button. I am using Arduino with RTC to operate the lights of my home. The colour options depend on the wave light of the light the LED produces. for devices/machines that use a high power supply ( > 5v) and/or high-current consumption, we need to use a relay between output pin and devices/machines - see Arduino - Relay. The timer is then automatically reset to zero, and starts counting up again. The above code uses the delay(). pinMode (3,OUTPUT); pinMode (4,OUTPUT); Thanks I didn't know that. Now our program is ready to upload to the Arduino. I could a start an endless story on electronics, bombarding you with circuit diagrams and stories about signals. Let us understand a few critical LED specifications from an example datasheet. This example (Arduino Blinking LED Code) uses the built-in LED that most Arduino and Genuino boards have. Read the line-by-line explanation in comment lines of code! If youre new to Arduino, this is a great place to start. Step 4: Then copy the code below to your Arduino IDE project and save it. 5 ways to blink an LED in Arduino using inversion operator Here's the trick: digitalRead () returns the current output value of the pin: 1 if the pin is high and the LED is on, 0. Instead of using the functions, you will use built-in hardware timers to toggle the LED. // initialize digital pin 9 as an output. For this tutorial I use the Arduino UNO, which has many pins to connect components to. The connections are easy to take significantly less time to complete. Every time the function has finished, it will be called again. The LED has two pins. Coding in the Arduino language will control your circuit. Code in a boolean condition. If you connected your resistor to the LED's anode (positive, longer), connect the resistor's other leg to Arduino's digital pin 13. If you look closely at the code you see two other functions being called: digitalWrite() and delay(). The second parameter specifies the written value, here HIGH. Thanks for contributing an answer to Arduino Stack Exchange! When i push the button delay 500msec and start led blinking. Adding EV Charger (100A) in secondary panel (100A) fed off main (200A). Why does Acts not mention the deaths of Peter and Paul? Even when the builtin LED is connected to another pin. Learn more about Stack Overflow the company, and our products. Creating blinking LEDs is one of the first simple projects that newcomers to Arduino do. The builtin LED is marked L on the PCB. Therefore you need to specify pinMode(buttonPin, INPUT_PULLUP); and make sure that your switch or button connects the input pin to ground when activated (which means that "active" will be LOW). For Indoor use, 1 mA is sufficient in most cases. My name is Bas van Dijk, entrepreneur, software developer and maker. Check if number can be displayed using seven segment led in Python, Semaphore and Mutex in FreeRTOS using Arduino, Suspend/Resume tasks in FreeRTOS using Arduino, Displaying data on OLED Screen using Arduino, Getting data from Vibration sensor using Arduino, Arduino IDE 2.0 Using the Boards Manager. Is it safe to publish research papers in cooperation with Russian academics? In this article, we covered the basics of LEDs. Enjoy unlimited access on 5500+ Hand Picked Quality Video Courses. The possibilities are endless: mp3 player, mobile phone, robot, weather station, game computer, RC cards, home automation and much much more! One single LED can indicate more than ten statuses! If you want a little bit more guidance, please continue reading. The first blue output block sets the built-in LED HIGH, which is Arduinos way of describing on. This output command will activate a 5V signal to anything connected to the specified pin. Make sure you've selected the correct board in the IDE: If you are not sure which port to use, try them all until you can successfully upload your code. I skipped explanations of the basics because I wanted to get my This LED is connected to a digital pin and its number may vary from board type to board type. In this blog post, I am going to show you 5 different ways of blinking an LED on Arduino: blinking an LED by turning it on/off roughly once a second. If you don't have an external LED, depending on which board you have, you could use the BUILTIN_LED of the board. By using a clever trick, we no longer need to call delay() in our code to blink the LED using Arduino. Upload the code and watch your onboard LED flash with the custom blink you created VLED Forward voltage of the LEDILED Forward current of the LED. As you can see, we have first defined the LED_PIN. Step 4: Upload the sketch to the Arduino UNO board. The colored stripes identify the resistors value, and for this circuit, anywhere from 100 ohms to 1000 ohms will work great. Blink_LED_2_timer variable is saved the last time you blinked the LED2. They can be combined into groups. You can use the equation below to find the resistors correct value. Please sign in to subscribe to this guide. Hello, I need help with Arduino code. You are enabling the timer interrupt. Can you still use Commanders Strike if the only attack available to forego is an attack against an ally? Great to see you made it this far! Instead of using the delay() function, you can use the millis() function to track the time. Checks and balances in a 3 branch market economy, Embedded hyperlinks in a thesis or research paper, Using an Ohm Meter to test for bonding of a subpanel. The third and final LED can be turned on and off using the Serial Monitor. Once 1000 milliseconds have elapsed, you will change the pin status. First we have to connect our Arduino to the computer with the USB cable. You have been successfully subscribed to the Notification List for this product and will therefore receive an e-mail from us when it is back in stock! Our solutions to blink an LED with Arduino so far relied on Arduino's built-in functions, so they would virtually work on any board supported by the Arduino environment. As a result the LED goes off. How can I control PNP and NPN transistors together from one pin? Now you will need to paste the following code into the Arduino software and upload it to the Arduino. Connect your resistor to either side of the LED. Next, in the setup, we have defined that pin as an Output pin. You will find the necessary Arduino code in the later sections. There is a pull down resistor in the circuit. Anode and a cathode. Lastly, put the longer leg of the Led (+) under the wire that goes to the Arduino. Normally it defaults to INPUT if you don't manually specify anything, and I assume from your results that you don't have an external pullup or pulldown resistor. I have included a list of the most frequently asked questions about projects built using Arduino and LEDs. In the code you see all kinds of commands. I suggest to restructure your code. Replace '== false' by '!' This is in turn the 6th way of blinking an LED on Arduino. The main body of the program is inside the loop, indicated by another set of curly braces { }. The only way to stop the program is to disconnect the power or to upload a new program. You can even view this lesson from within Tinkercad if you like! "if (ledState == true && blinkState == true)" , can you also write them without the == signs? And this goes on in a loop until there is no more power supplied to the Arduino board. Can you help me with this? To learn more about the timer features of the Arduino, refer to the link. You can share the link of this tutorial anywhere. With the current scope of the code you are fine with this structure. It runs once when the program starts up, and contains everything within its curly braces { }. However, if we focus just on the Uno board, we can start taking advantage of its specific hardware features - namely, timers and interrupts. Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. int led = 13; int led2 = 12; int led3 = 11; // the setup routine runs once when you press reset: void setup () { // initialize the digital pin as an output. The Arduino is a so called microcontroller. But what if the hardware could also take care of toggling the pin for us? You can copy and paste the code in the editor window and program the Arduino. 5 years ago. It was last My personal favorite was using the Arduino's serial port. Setting the COM1A0 flags tells our chip that we want to toggle a specific pin whenever the timer hits our target value. Now, the code will look like the following . At a time, one pin can take only one task. If you are using only one LED, you can directly connect the LED to the Arduino. This pin is connected with the builtin LED. Step 2: Setup Output Pins. There are two possible ways to connect the LED. A tool which converts your code into the bits and bytes which the Arduino understands. ArduinoGetStarted.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com, Amazon.it, Amazon.fr, Amazon.co.uk, Amazon.ca, Amazon.de, Amazon.es and Amazon.co.jp. density matrix. The Arduino can sink up to 20 mA per pin. If the required output is not seen, make sure you have assembled the circuit correctly, and verified and uploaded the code to your board. On the UNO, MEGA and ZERO, it is attached to digital pin 13, on MKR1000 on pin 6. I tried using random () to get the LEDs to randomise but I'm unsure as to how the coding works.My code is as shown below. digitalWrite() in this case, makes sure that the LED on pin 13 will be lit. earlier! In between the on and the off, you want enough time for a person to see the change, so the. How to modify this to blink multiple LED one after another. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ECLIPSE - the Ring Lamp With Progressive Lighting, IR Controlled, DIY Arduino Camera Robot (Motorized Pan Tilt Head). Since you are dividing the millis() by 1000, every time the millis() reaches a multiple of 1000, the modulus 2 will either generate a one or a zero. No. This beginner example is also available directly within the Arduino software under File-> Examples-> 01.Basics-> Blink. Each one has its own pros and cons. These can do exactly the same as the original Arduino. When reading the word pins you might expect solid metal pins. Share it with us! Learn how to use AIs help to learn Arduino programming faster, find bugs, and understand programs line-by-line! Agree It does not check if you have written correct code for what you are trying to program. Actually, it can, if we accept some constraints. In order to blink an LED using Arduino, we first connect perform the hardware connections. As a result you should now see your Arduino LED blink with 1000ms intervals. We are considering to make the video tutorials. The component between the LED and pin 13 is a resistor, which helps limit the current to prevent the LED from burning itself out. You Can just Copy this code and paste it in arduino software see my video for detail. The circuit will look like this As you can see, one end of a resistor is connected to pin 7 of Arduino Uno. You can also explore the language reference, a detailed collection of the Arduino programming language. LCD display working now, not after reading boring theory. Making statements based on opinion; back them up with references or personal experience. I've chosen to make short, yet powerful YouTube videos with a the same structure and one If your project requires to do some tasks, avoid blocking Arduino by using the non-blocking method for Arduino. How a top-ranked engineering school reimagined CS curriculum (Ep. ->Read our article aboutHow Easy Is It To Learn Arduino? The LEDs will not be brighter. If you buy the components through these links, We may get a commission at no extra cost to you. After sharing this post in the Arduino Facebook group, some users shared their insights about how they'd blink an LED. So the program will pause while the LED is on for one second. In this Project, you will toggle the LED every second. Connect a 220-ohm resistor to the anode pin of the LED. Then you turn it off with the line: That takes the LED_BUILTIN pin back to 0 volts, and turns the LED off. Did you make this project? When you connect multiple LEDs, the current consumption will be too high, damaging the GPIO port or the onboard regulator due to excess power. Components Required Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Voltage beyond this value will destroy the LED permanently. These can only have one of these two values: HIGH or LOW. On the Arduino Uno board, pin 13 is connected to the built-in LED. Please remember that this subscription will not result in you receiving any e-mail from us about anything other than the restocking of this item. This is because these boards are using the CH340/CH341 chip for USB communication with your computer. digitalWrite(2, HIGH) When you are using a pin as an OUTPUT, you can command it to be HIGH (output 5 volts), or LOW (output 0 volts). Generating points along line with specifying the origin of point generation in QGIS, Understanding the probability of measurement w.r.t. It's perfect for learning, teaching, and prototyping. You can choose any resistor value between 220 ohms and 1 kOhm. When the program starts it executes the setup() function once. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. In the image below, you can easily see the cathode part being wider than the anode inside the LED. The circuit will look like this . Can it be done by reading Arduino Serial Monitor? Why do men's bikes have high bars where you can hit your testicles while women's bikes have the bar much lower? In the tutorial, Bas demonstrates how to make an LED on the board blink using a pre-written example code from the IDE. In the Tinkercad Circuits components panel, drag a resistor and LED onto the workplane. On the bottom left you'll see the current pins like 5V, 3.3V, ground GND and the reset pin RES. By connecting the Arduino's pin to LED's anode(+) pin (via a resistor), we can programmatically control LED's state.

Norfolk Police Department Arrests, Mark Allen Chevrolet Wife, Buds Chicken And Seafood Calories, Man Jumps From Stratosphere Las Vegas Pictures, Brevet Sergeant Sapol, Articles B

blinking led arduino code