Arduino Nano – Blink Extreme

 

Assignment:

Program a Blink on the Arduino

Goals:

You will learn how to perform exciting programming tasks with Arduino and LEDs yourself.

Lesson:

Supplies:

For the extra challenges:

  • various LEDs
  • RGB LED
  • Soldering tools.

To perform the extra challenges, you must have learned how to solder, for example, if you did the exercise with the vibrating robot.

Note:

If you are going to use the mobile Arduino IDE on your own computer, you first need to install the driver for this nano.

If you use our mobile Arduino install: In the mobile folder you will see a subfolder “Drivers”, containing two folders “01” and “02”, each with a driver. Install them both.

If you have to arrange it yourself: Look for the number of the USB controller chip at the bottom of the Arduino. Usually, that’s CH34… –> for this number you look on the internet for a driver. Tip: it is sometimes difficult to find a usable driver, so use this zip: arduino_nano_drivers containing two folders “01” and “02”, each with a driver. Install them both.

https://junioriot.nl/app/uploads/2000/12/arduino_nano_drivers.zip

 

 

Working method:

Explanation of the Arduino parts (if you have done the vibrating robot)

 

We’re looking at the arduino Nano. This is the same as all other arduino’s, but smaller and with a handy micro-USB connection.

You make your program on your computer screen and then send it via the USB to the chip. For all those legs you see on the side of the board also connection holes. In the pocket of the arduino you will also see connection legs. We don’t use those today.

On the back of the Arduino, you see a big black chip. It takes care of the communication with the USB. We have chosen the right driver on the computer.

The smaller black cube on the back converts the current of the USB from 5 volts to about 3 volts. This is the same as the battery we used with the vibrating robot. You can use the same LEDs here.

Oh yeah, on the side of the Arduino you can see all kinds of numbers at those holes. For example, do you see where D2 and D3 are?

Your first blink

On the Junior IOT laptop, you look for the white icon on the desktop for the shortcut or shortcut to Arduino. Click it and wait for the Arduino screen to open.

This screen is called the Arduino IDE. On the Junior IOT laptop, you use a portable version, so you could copy the whole folder with program, libraries and your code on a USB stick at once. This is useful if you want to continue working at home, for example. You can even open the Arduino IDE from the USB stick.

Connect the Arduino via the USB cable to the laptop.

Open the example code on your screen via file/examples/01 basics/Blink.

Look under Tools/board and make sure it is selected: Arduino Nano

Look under Tools/port, and select the correct port (which is usually the highest number).

Send the Blink program to the Arduino by selecting the second round button on the top left of your screen with the arrow.

You will then see on the bottom right that the program is being prepared and the computer tries to send it to the Arduino. If there is an orange bar at the bottom there is a problem, but most of the time it goes well. If there is a problem you can see which text is in the orange bar, maybe the port is not selected correctly or you may have an error in the code.

Is the Arduino blinking?

Clean up on your screen

The program is now in the middle of your screen. What’s on the top line? No, right at the top.  The first line starts with two strange characters: /*

After that, there will be a number of light grey lines and then you’ll see another line with two strange characters: */

We’re gonna take that whole piece away. Move your cursor all the way to the left on the top line. Then hold down Shift and use the down arrow to select all the grey text with the strange characters. Press Delete or Backspace. The text and the strange characters are then gone. You can now see the program better.

Send the program again to the Arduino to see if it still works. If there is an orange bar you might have left some clutter on the screen. Just make sure it’s okay.

Your second blink

Now there are only a few lines left on your screen. In them, you will see the number 1000 in two places. Next to that, you’ll see all kinds of brackets and semicolons. You don’t have to change them, but you can change the numbers.

Make 300 of the first number and 2000 of the second number. Those are milliseconds. Send your program to the Arduino.

Does the Arduino blink differently now?

You can try again with other numbers. The fastest blink I’ve seen is with the numbers 1 and 10; the led doesn’t blink but is faintly on.

Put the numbers back to 300 and 2000.

We look at the code

Teacher: get the students’ attention and tell them…

In your program, you can see two parts. The first part is called Setup, and this is done when you turn on the Arduino, whether the program is loaded, or when you press reset. In the assignment, you can read that the Arduino knows which port we are going to use for the flashing led. This is called LED_BUILDIN, but I know that this port is 13.

The second part is called Loop, and this is repeated over and over again. If you look closely, you’ll see that there are four command lines. The first line turns on the port with the LED since HIGH means 3 volts or “on”. Then there is a line that indicates how much he has to wait, those are the milliseconds. The third line turns the port with the led off again because LOW means 0 volts or “off”. And then you see another waiting line. And you see the blinker because the loop repeats over and over again…!

Teacher: Now let the students go to the computer again to see if that is indeed there.

 

Werkwijze:

Uitleg van de Arduino onderdelen (als je de trilrobot hebt gedaan)

We kijken naar de arduino Nano. Dit is hetzelfde als alle andere arduino’s, maar dan kleiner en met een handige micro-USB aansluiting.

Je programma maak je op je computerscherm en dan stuur je het via de usb naar de chip waar veel pootjes aan zitten. Voor al die pootjes zie je aan de zijkant van het bordje ook aansluit gaatjes. In het zakje van de arduino zie je ook aansluitpootjes. Die gebruiken we vandaag niet.

Op de achterkant van de arduino zie je een wat grote zwarte chip. Die zorgt voor de communicatie met de usb. Daarvoor hebben we in de computer de juiste driver gekozen.

Het kleinere zwarte blokje op de achterkant converteert de stroom van de usb van 5 volt naar ongeveer 3 volt. Dat is hetzelfde als de batterij die we bij de trilrobot hebben gebruikt. Je kunt hier dan ook dezelfde leds gebruiken.

Ohja, aan de zijkant van de arduino zie je bij die gaatjes allerlei nummertjes staan. Zie je bijvoorbeeld waar D2 en D3 staan?

Je eerste blink

Op de Junior IOT  laptop zoek je op de desktop het witte icoontje voor de snelkoppeling of shortcut naar Arduino. Klik deze aan en wacht even tot het Arduino scherm opent.

Dit scherm heet de arduino IDE. Op de Junior IOT laptop gebruik je een portable versie, zodat je de hele folder met programma, libraries en jouw code in één keer op een usb stick zou kunnen kopiëren. Dat is handig als je bijvoorbeeld thuis verder wilt werken. Je kunt zelfs de Arduino IDE vanaf de usb stick openen.

Sluit de Arduino via de usb kabel aan op de laptop.

Open de voorbeeld code op je scherm via bestand/voorbeelden/01 basics/Blink

Kijk bij Hulpmiddelen/board en zorg dat deze is geselecteerd: Arduino Nano

Kijk bij Hulpmiddelen/poort, en selecteer de juiste poort (dat is meestal het hoogste nummer)

Stuur het Blink programma naar de Arduino door op je scherm links boven de tweede ronde knop te kiezen, met het pijltje.

Je ziet dan rechts onder dat het programma wordt klaargemaakt en de computer probeert deze naar de Arduino te sturen. Als er onderin een oranje balk komt is er een probleem, maar meestal gaat het goed. Bij een probleem kijk je welke tekst in de oranje balk staat, misschien is de poort niet goed gekozen of je kan een foutje in de code hebben.

Knippert de arduino?

Even opruimen op je scherm

Het programma staat nu midden op je scherm. Wat staat op de bovenste regel? Nee, helemaal bovenaan.  De eerste regel begint met twee rare tekens: /*

Daarna komen er een aantal lichtgrijze regels en dan zie je weer een regel met twee rare tekens: */

Dat hele stuk gaan we weg halen. Ga met je cursor helemaal naar links op de bovenste regel. Houdt dan Shift ingedrukt en met pijltje naar beneden selecteer je alle grijze tekst mét de rare tekens. Druk op Delete of Backspace. De tekst en de rare tekens zijn dan weg. Je kunt nu het programma beter zien.

Stuur het programma nog een keer naar de Arduino om te kijken of het nog steeds werkt. Als er een oranje balk komt heb je misschien nog wat rommeltjes op het scherm laten staan. Zorg even dat het goed gaat.

Je tweede blink

Nu staan er nog maar een paar regels op je scherm. Daarin zie je op twee plaatsen het getal 1000. Daarbij zie je allerlei haakjes en puntkomma’s. Die moet je niet veranderen, maar de getallen mag je aanpassen.

Maak van het eerste getal 300 en van het tweede getal 2000. Dat zijn milliseconden. Stuur je programma naar de arduino.

Knippert de arduino nu anders?

Je mag het nog een keer proberen met andere getallen. De snelste knipper die ik heb gezien is met de getallen 1 en 10; de led knippert dan niet maar staat vaag aan.

Zet de getallen weer terug naar 300 en 2000.

We kijken naar de code

Leraar: zorg dat je de aandacht van de leerlingen krijgt en vertel…

In je programma kan je twee delen zien. Het eerste deel heet Setup, en dit wordt uitgevoerd wanneer je de arduino aanzet, of het programma geladen is, of als je op reset drukt. In de opdracht kan je lezen dat de arduino weet welk poortje we gaan gebruiken voor de knipper led. Dat heet LED_BUILDIN, maar ik weet dat dit poortje 13 is.

Het tweede deel heet Loop, en dit wordt telkens herhaald. Als je goed kijkt dan zie je dat er vier opdrachtregels zijn. De eerste regel zet het poortje met de led aan, want HIGH betekent 3 volt of “aan”. Dan is er een regel die aangeeft hoeveel hij moet wachten, dat zijn de milliseconden. De derde regel zet het poortje met de led weer uit, want LOW betekent 0 volt of “uit”. En daarna zie je weer een wacht-regel. En je ziet de knipper omdat de Loop steeds wordt herhaald..!

Leraar: laat de leerlingen nu weer naar de computer gaan om te kijken of dat er inderdaad staat.

Congratulations!

I managed to make your first program.

Now you can try something more difficult. You may choose: a Morse code with this led, but if you can already solder, you can also choose to mount extra LEDs.

If you don’t know how to do that, you can ask each other for help.

Choice 1. Morse code long-long-short

Now take a good look at the regular blink code. Do you see the four lines of colored words after the word Loop between the curl hooks? These are the lines that make the led blink. Crank hooks look like this:  { }

We want to double the four lines of the barrel a few times. Select the four lines and use control-c.  With control-v, you can now paste them a few times. It’s nice if you put an empty line behind it each time.

See if the code still works by sending it to the Arduino.

For each block of four lines, you can now change the waiting numbers. Try to make a rhythm in Morse; long-long-short with an extra-long pause afterward?

Choice 2. Extra leds. D2-D3, D5-D6, D8-D9

Start with the regular blink code. Do you see the line with the colored words, which is between the curl hooks after the word Setup? This is the line that says we use LED_BUILDIN.

Now double this line so that it is there three times. The first line will leave you as it was. On the second line, you replace the word LED_BUILDIN for number 2. On the third line, change LED_BUILDIN to 3.

This tells us that we also want to use port D2 and D3. Always check if the code still works by sending it to the Arduino.

Now look again at the blink code. Do you see the four lines of colored words after the word Loop between the curl hooks?

The first line in which you see the word LED_BUILDIN you also want to double it, now so it’s there twice. On the second line, you change the word LED_BUILDIN into the number 2. Is the LED switched on or off there?

After the waiting line, you will see another line in which you see the word LED_BUILDIN. Is the LED switched on or off here? You also want to double this line, so that it is there twice. On the second line, you change the word LED_BUILDIN into the same number 2 again.

Always check if the code still works by sending it to the Arduino.

Now take a led and put it in holes D2 and D3, and see if it will blink. You might have to turn the led around. When the led blinks, I always bend one leg a little so the led doesn’t fall out. So I remember that I tested this one. Now you can solder it on.

Soldering a led to the Arduino is not difficult. You set the clean soldering point so that you heat the hole. After 1 or 2 seconds you also solder a small amount of tin against the hole. If you do it right you will see that the soldering tin is sucked into the hole. Slurp!
Also, solder the second hole of the led. Cut off the protruding part of the led’s legs.

If you are working with two people on one computer, you can now program the second Arduino and test the led. If this one also blinks well, you can solder it on.

For the next led, choose D5 and D6. We deliberately skip a hole. Change the code again until this led also works and solder it on.

Do the same with D8 and D9.

Also, try to add extra waiting lines between the different led-on lines, and also between the different led-off lines.

Choice 3. RGB led.

You can choose this command after you have done the three LEDs. First, we need to find out which holes on the other side we want to use. And we need to find out which holes we need to make plus or minus.

Take an RGB led and a battery. Find out which pegs you use to turn on different colors. Should the longest leg on the plus or minus? In your program, HIGH is the plus, and LOW is the minus, should the longest leg be HIGH or LOW?

With most RGB LEDs, the longest leg must be on the plus to make light. Note: there are also RGB LEDs with the longest leg on the minus; in your program, you have to turn the HIGH and LOW.

Add the extra line in Setup to also use the four legs A0-A1-A2-A3.

Make sure in Setup that the longest leg is always HIGH. For this, you can copy a line from the Loop and then adjust it.

Put extra lines in the Loop to switch the R G B colors on and off separately. These lines can be copied from what’s already there, and adjusted further. With most RGB LEDs, LOW on these legs means that the led gives light.

Choice 4. Fade?

Can you also find a program with a fade in the examples? With this program, the led will slowly go on, and then slowly go off again. Want to give it a try?

In the code, you can read which port is used. You probably want to change this to the numbers where you mounted the LEDs.

Choice 5. RGB rainbow fade?

The Fade can also be made with the three RGB colors. For us that would be the first time. Therefore you can choose how this should be done.