Arduino – Day… Uno – Connecting the micro-controller to the computer

Created at: February 17, 2017; Last update: February 22, 2017

Well… It seems that I’ve come to take an interest into Arduino micro-controllers. And they look great. At least the version I bought seems to be ready to be included into really serious projects, having with it some sort of plastic cover that allows me to fix it with screws.

In this new endeavor I thought not to be original and buy an… original version of Arduino and not some sort of Chinese manufactured micro-controller – although I did hear they are compatible with the original and are cheaper. Arduino is open-source. In other words, although is a product made in Italy, the circuitry is “public”. So, if you have  the components, you can yourself build from zero this micro-controller.

What do we need

I bought myself a micro-controller from a romanian retailer. But you can buy yours from wherever you wish. There’s a list of distributors on Arduino’s website: http://www.arduino.org/buy/distributors. For my basic needs, which includes Arduino Uno, some led bricks, sensors, a mini breadboard and some connectors, I spent about 80 euros. You should also buy a “printer cable” (ACS-CAB-05 Cable USB Male A – Male B) in order to connect to your PC, and a charging cable.

Installing

Installing the drivers went pretty straight-forward, although if you look on the internet you might find out of date installation instructions that are no longer necessary or are referring to older versions of the micro-controller or of the software.

So… Once you get to this page: https://www.arduino.cc/en/Main/Software, you either download the Windows installer or click on the Windows Store version of the same IDE (of course you can download any other operating version software you might need, be it Linux or Mac, but I am using Windows for these tutorials).

TAKE NOTE: If you’ve installer the Windows Store version, you will have to run the program as an admin. If not, you may find out that the program doesn’t transfer the data unto the micro-controller.

Once you’ve installed the IDE, you will be asked if you want to also install the drivers for Arduino. Of course you want to install them or else your PC might not recognize the micro-controller when you connect it.

If you will open the IDE you will notice that it looks pretty simple. Well… it is for a MICRO- controller after all…

Connecting the Arduino micro-controller to the PC

You can connect the Arduino micro-controller to the PC by using a “printer cable”. You can see how the cable looks in the picture below.

Once connected to the micro-controller, the computer should look by itself the necessary drivers that were installed with the IDE. During the driver install you should watch the install process in order to see to which COM port it connected.

If you missed the used COM serial port that the computer is using, there’s no problem. You can go to the Device Manager and look into the Ports list, and you will see in there what COM is used by Arduino. As you can see, in my case COM3 was used:

Once the program and the drivers are installed, we can open the IDE. This is an interface through which we can tell the micro-controller what to do:

As you can see, every Arduino program (or rather “sketch”) has to sections. A “setup()” section, in which we can tell the micro-controller what it must initiate and do when it is started. This section is ran only once. It’s like the BIOS in our computers. It only runs on the initialization or when the reset button is pressed (you can see below the reset button):

The “loop()” section will run again and again as long as the micro-controller is connected to electricity.

Before going further we must make sure the connection between the computer and Arduino is established. We do this by visiting inside our IDE the Tools menu and then Board (which should be Arduino / Genuino Uno). Also we must verify in Tools>Port to see if the correct port is used by our IDE.

Once we did all these we can try our first sketch. A sketch is the program that we can upload into the Arduino for it to work as we want it to work.

And then He said “Blink”… and the micro-controller blinked…

Our first sketch will tell the micro-controller to blink an embedded led:

Pretty simple, huh?

In the setup() section we’ve told the micro-controller to use pin 13 in order to send something into the outside world (OUTPUT). Because there is nothing connected to the pin 13, and the fact that from the factory pin 13 is already connected to a led, this will allow Arduino to light up that led.

In the loop() section we are asking the micro-controller to “write” something to pin 13 (HIGH), wait for 1000 milliseconds (which means one second), after which to stop sending voltage (that… something I was talking before) to that respective pin, and then wait for another second. Being a loop, once it finishes what we told it to do, it will run again the loop.

OK. How do we tell the micro-controller what to do? Assuming that Arduino is connected to our computer, once we’ve wrote the sketch we click on Sketch>Verify/Compile…

And if everything went alright, we can click on Sketch>Upload, which should upload the compiled sketch into the micro-controller’s memory. If this went according to plan, the micro-controller should go on and off every other second. If this doesn’t happen, push the reset button on the Arduino board. The reset should tell the micro-controller to reload the program from its memory (the setup() section) and run the loop() section.

Did you see red???

Do not worry. First make sure you have selected the right micro-controller and port inside your IDE. If there’s no problem in there and you still see errors, that means that you installed the Windows Store version of the IDE. So save the file, close the program, and run it as administrator:

Now everything should be OK. Run it and be amazed by the (not that…) psychedelic lights.

Homework

“What??? Homework??? Already???” Yes. But it’s a simple one. Just change the sketch a bit so that the led should be on for one second and then be off for three seconds. Good luck!

Leave a Reply

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

No spam? * Time limit is exhausted. Please reload CAPTCHA.