Learning how to program a microcontroller for the first time does not need to be a difficult task. Programming your first microcontroller can literally take only minutes by using an Arduino. The Arduino is a microcontroller development platform that allows you to quickly and easily start programming microcontrollers. It has a much shorter learning time than a stand alone microcontroller as many things such as initialization are hidden from the user so that you can concentration on building a working circuit faster.
As you become more familiar microcontroller programming and want more control over them one would naturally gravitate towards programming microcontollers directly using an “In Circuit Serial Programmer” (ICSP). The Arduino Uno board has an ICSP header should you want to go this way later on down the track, but for now we will get started programming microcontrollers the easy way. With just a few steps you will be programming in no time.
Firstly there are a few requirements you’ll need before you get started:
- PC/laptop/Mac with a spare USB port
- Arduino UNO board (or a third party arduino compatible board)
- USB cable to suit
- Arduino IDE software insalled on the PC/laptop/Mac.
Step 1 – Download and install the IDE
Download the IDE software to your PC/Laptop/Mac from the following link:
Locate the downloaded file on your PC/Laptop/Mac and double click to install and follow the install instructions when prompted.
Step 2 – Connect the board to PC/laptop/Mac
Using the USB cable connect the square plug into the board and then connect the rectangular plug to the spare USB port on your PC/Laptop/Mac. The green power LED on the board should light up. The computer should now automatically install the USB driver. The computer should popup a message once it is installed. If you are using a third party arduino compatible board and the driver does not install automatically you may need to go to the manufacturers website to download the driver.
Step 3 – Start the IDE Software
Start the IDE by double clicking the icon on your desktop. To get the computer to communicate with the board you will need to select the correct com port in the IDE settings. Do this by going into the “Tools” menu then select “Port” and finally select the com port that says Arduino.
Step 4 Upload a program.
Once you have selected the correct com port, you can upload one of the example programs to make sure the board is operating correctly. On the menu bar click on:
File -> Examples -> 01.Basics -> Blink
This will load up a new sketch called Blink that will blink the on board LED, on then off every second. Now you need to upload the sketch to the board by clicking on the upload button located just under the main menu bar or by going to the main menu bar and selecting Sketch -> Upload. The upload should take a few seconds to complete. A message on the blue bar at the bottom of the IDE should read “Done Uploading”. Then a few seconds after the sketch is successfully uploaded, the on board LED should start blinking once every second. If the upload was not successful then try uploading a second time.
This is your first microcontroller program. Congratulations !
Now that you’ve got your first sketch uploaded and running, it’s time to start experimenting to get a feel for programming. You can start by changing the delay time. In the code, change the two delay times to 2000. This will make the LED blink every two seconds.
Now try a delay of 500 which will speed up the blink rate to a 1/2 second.
Are you excited ? I am, because this is just the very beginning of what this powerful little microcontroller (ATmegea328) can do. The arduino platform has made it so easy to get started with using microcontrollers that you can get your projects up and running in such a short time compared to building your own microcontroller circuit, then programming a with a separate programmer which you may wish to do as you become more advanced. But the platform is brilliant to get start and also for quick prototyping.
Where to from here ?
If you liked this post, we would appreciate it if you could share it with a friend.
Before you move on, I would love for you to suggest some topics you would like to see covered on the Smartmicrocontroller.com website this year by leaving a comment in the comments section in the youtube channel, or send us a message through one of the social media links on the about page.