Weekend Arduino Projects for Parents and Kids — Project Zero: “Arduino, meet LED”
By: Jayden Chua
Tags: Arduino Uno, Parents With Purpose, Arduino, Kids And Tech, Kids Learning

Let there be LED!

Ok, so here is the fun part, we are going to turn on a LED! To do that, let’s connect the LED directly into the Arduino. Parents, please help kids do this the first time.

The LED has 2 legs. One long and one short. The longer leg is the positive terminal and the shorter leg, the negative terminal.

LED 2 pins, the left is the positive, the right is the negative.

Connect the long leg to “PIN 13” and the short leg to “GND”. Don’t worry you can do this while the board is connected.

Connecting LED to GND and pin 13

Now the hardware is all setup. Let’s make some instructions!

Instructions!!

Head on over back to the mBlock software now, we will write our first set of simple instructions.

First make sure you have Arduino selected in the “Devices” tab, and in the “Blocks” panel you can see that the Arduino is now the device you can send instructions on.

There are groups of different commands to choose from. But first look at the “Events” group. Here is where the magic starts.

Drag the “when Arduino starts up” block into the “Blocks” section.

Next select “Pin” groups and drag “set digital pin 9 output as high” and click it right below “when Arduino Uno starts up”. Finally change the number 9 on the block to 13. Your final screen should look like the below.

Once that is done, hit “Upload” in the “Devices” tab. Wait for the instructions to get uploaded to Arduino… Bam!!!

Successfully turning on your LED.

What next?

Now that we can turn on the LED, it’s really no use if we cannot turn it OFF!!

So take a minute to think about how we can turn off the LED. Hint: What is that “high” option there in the block?

You’re absolutely right! Yes, let’s change the “high” to “low”. This way we can turn the LED OFF!

Changing High to Low

Once you have done that, remember to again upload your instructions. Now, on the Arduino, you should see the LED turned off.

Shall we dance?

Yes! Let’s celebrate with a dance! And maybe let’s get our LED to dance with us. What if we can get the LED to turn on and off and on and off and … you get the idea…

How can we we make the LED light turn on and off? Hint: We can add as many blocks as we like.

Sure! Maybe we can add a block right below that will turn OFF the LED after it has been turn ON! So let’s go ahead and drag another block right below our first 2 blocks and set the PIN to 13 and output as LOW.

Upload the instructions again… Did it work? Well if it didn’t seem to work don’t worry, it actually did!

So what was the problem, or what just happened? Why did it not work as we have expected?

So this is what happened. The “brain” of Arduino actually works really fast. You can imagine that it will perform every instruction in a split of a second (To be exact, in one second it will will perform 16 million instructions!) So, what happened was, Arduino, understood us as once the “Arduino Uno starts up, set digital pin 13 output as high and then set digital pin 13 output as low.” All these 3 instructions were carried out in less than one second! That was way too fast for our eyes to even see it happen.

What should we change in the code that would allow us to see the LED being turn on and off? Hint: Maybe we can somehow slow things down slightly?

Ok, this one is a little tough, but if you got it great work! If not, let’s make this happen together.

We will add a new block now. Click on “Control” in the tabs, and drag “wait 1 seconds” block right between our “High” and “Low” code. Your code should look like the below now.

Let’s see if this makes sense. First Arduino starts up, then we turn on the LED, then we wait 1 second, and finally we turn off the LED. Sounds right! Let’s upload.

Code with 1 second delay

YAY! You have managed to successfully turn ON and OFF the LED, and you saw it this time around.

Now, but you say to yourself, “I want it to DANCE!!!”, hm… how might we now achieve that?

Loopy Loops

You might have already guessed it, yes, we should really repeat this on off thing a couple of times. Let’s see how we can do it with the blocks.

First drag “repeat 10” block into our code.

Before we upload the code, let’s read it to make some sense out of it. So here, the Arduino will start up, then we turn on the LED, next we wait 1 second, and we turn off the LED, next we repeat the whole section 10 times.

Does it sound right? What do you think the expected result is? If you think it makes sense, upload the code and see what the result is.

Did the code you upload to Arduino work? Why did it not work? Hint: Should something happen between off and on?

Yes, you might have guessed. Between OFF and ON, we did not add another wait block. This will seem like the LED is constantly ON to our eyes because everything happened so fast between OFF and ON.

Let’s fix it. Let’s add another wait block right after OFF so that we can see that the LED is OFF for 1 second.

That’s ALL! You have now an implemented a blinking LED with instructions you gave to your Arduino, great job!

Quick Recap

You know how to turn on and off an LED. You know how to write a simple block of code that loops and has delay. You know an Arduino can work on many instructions in one second.

What Next?

In the next project, we’ll look at how to build a simple LED traffic light. With our new found LED knowledge, how can we go about making instructions for more LEDs at the same time? What do we need to connect more LEDs to Arduino? Will the current hardware setup suffice? Stay tune for the next projects while we go through these questions and have another fun weekend building a simple LED traffic light!

Series Links

Note

This is an ongoing series and more articles will be posted as we move along, feel free to comment so either me or someone in the community can jump in and help! Furthermore, your comments will definitely help other kids and parents as well!