Microcontroller Programming

Microcontroller programming can seem a bit tricky because there are many confusing choices to make. I remember how I felt in the beginning. With all the available compilers, IDE’s, programmers and programming methods – no wonder you get confused!

So, let’s break it down.

Microcontroller Board ATmega32u4 from Sparkfun

I struggled a lot when I was learning the microcontroller basics. I followed different tutorials and ended up with lots of different software on my computer, which made it confusing. And I had to use an external board for programming the chip.

All of this made it hard to understand what I actually needed to make it work.

So to make microcontroller programming as simple as possible for you – here is an overview of what you need to do.

The Basics Of Microcontroller Programming

A microcontroller does not know what to do by itself. It’s your job to tell it what you want it to do.

So, you need to:

  • write program code on your computer
  • compile the code with a compiler for the microcontroller you are using
  • upload the compiled version of your program to your microcontroller

Arduino programming is a bit easier if you want to start really simple.

Write your program code

The first step is to write your program code. This is usually done is C. But some compilers support other languages as well. Find out what other people who are using the same microcontroller are doing.

Microcontroller programming code

It doesn’t matter what software you use to write code. You can even use Notepad for this step. I like to use a really simple editor. But one that supports syntax highlighting makes the coding a bit easier. For Windows, my favorite is Notepad++

Compile your code for your microcontroller

Before you can upload your program to your microcontroller, you need to compile it. This means converting the code from human-readable code to machine-readable code.

Use a compiler that supports your microcontroller and compile your code into machine-code for your chip. A popular compiler for Atmel AVR microcontrollers is avr-gcc.

After compilation, you will have one or more files containing machine code. Then you need to upload these files to your microcontroller.

Upload the compiled file(s) to you microcontroller

Usually, it’s one program file and a file for EEPROM and/or flash that you need to upload.

You need a physical connection from your computer to your microcontroller. Either you can use a dedicated programmer (such as the AVRISP for AVR microcontrollers), or if you have a USB programmable chip you can program it with a USB cable (my preferred method).

And you need a program for uploading the file(s). For AVR chips, you can use AVRDUDE.

Next Step

With the main steps of microcontroller programming fresh in mind, it’s time to start building. If you are starting out, I would recommend starting with a microcontroller board. Arduino is the simplest, but there are many more available.

I’ve aslo written a very popular 5-part Microcontroller tutorial that takes you through the steps of building your own USB-programmable microcontroller board from scratch.

More Microcontrollers Tutorials

48 thoughts on “Microcontroller Programming”

  1. Hi…, am thankgod, thank you for your post, but am having a problem with programming. i don’t know how to write a programme, please can you send me any tutorial maybe with videos, pictures and programming software. Thanks in Anticipation.

    Reply
  2. I bought your ebook Getting started with Electronic and went to my email to click the link that you sent me and appeared a windows with 3 downloads and I click them and only reached to download one of the 3 downloadable ebooks

    Reply
  3. i am doing a microcontroller project to allow me trace the location and speed of my car via gps and gsm, pliz take me through programming,

    Reply
  4. sir i want to make digital screen for writting in college. So that there is no use of paper . I dont know how can i start and how to write code in c language to make digital board .

    Reply
  5. Hi there. Thanks for sharing this – I’m a complete beginner but found your article interesting and easy to understand. I do have a question – how “testing” work, if I want to use a programmed microcontroller in a simple robot? Would one normally have to compile the code and upload it in order to see if the robot does what the code needs it to do? In equivalent terms, if I were to program a webpage, I can see rather quickly if the code is laying out the page correctly – what’s the best way to “test” when it comes to microcontrollers?

    Reply
    • Hey KC,
      For testing without actually testing in real life, you can use emulators.

      I prefer testing in real life though…

      Best,
      Oyvind

      Reply
  6. Thank you sir, is time i start microcontroller programming, i really need to…, help me achieve my dreams am a novice, but i believe i can do it with you as a tutor, thanks again.

    Reply
  7. The big problem is (especially for me) is C++ programming. I can draw and make any electronic circuit, analog and digital, but I can not programming. Is there any C++ tutorial programming?
    I really want to start to learn how to make a program and how to upload to the Microcontroller.
    If we can not make a program even as simples as just to switch on the LED, and do not know how to upload the program then that is dead circuit, the circuit does not work as we want/design.
    To understand programming we have to know logical thinking and the meaning of any what we want to write would you mind to copy your answer to my email?
    Thanks for the tutorial.

    Reply
  8. hey admin, thx for the great explanation. i too i am a beginner in micro-controller programming. working on a project of regulating light intensity and this requires use a programmed micro-controller. how can i do this…thx again in advance.

    Reply
  9. I am in my forth and am starting my project anytime , dreaming to do sth on microcontroller. I have knowledge of many languages but I don’t know which is the best plz advice me.

    Reply
    • Hey Larry,

      If you find dead links, please let me know about them so I can fix. I have so many pages now that it’s impossible to go through everything manually…

      Best,
      Oyvind

      Reply
  10. Hey There!
    I Would Really Like To Learn How To Make Something Type Some Text On It’s Own, Without Me Touching It At All. Something Like A Rubber Ducky USB But Without The USB. I’m Really Not Sure On How I Do This. What Do You Recommend.

    P.S: I Have Hardly Any Experience In Coding. So Can You Recommend The Simplest Answer Please.
    ~ Jacob Hughes

    Reply
    • Type some text on a computer? If you don’t want to use USB, I guess the only other option is Bluetooth. The simplest way that I can think of to make that happen would be to use an arduino and a bluetooth module.

      Best,
      Oyvind

      Reply
  11. Many of these comments were quite entertaining. I started in C# and paired it with unity game design. But I absolutely fell in love with C. C is so simple and to the point. And I designed robots as a kid but never built any. I think it’s time to build and program some robots!

    Reply
  12. I have a problem that I am trying to figure out. I have a clock that works from remote control but i have two different remotes the only problem is the zero and minus buttons are switched on the remotes but the clock only works correctly with one remote with the zero on the right side and the minus sign on the left side but the remote I want to use has the zero on the left side and minus button on the right side all the other buttons work correctly how can i program the clock microcontroller to read the remote i need to use?

    Reply
  13. How or why is this guy responsible to help any of you write specific code for your specific projects. Do your own research and if you dont like programming, Find something else to do or be prepared to pay him for his time. Probably about $100 per hour

    Reply
  14. In my project, I want to use micro controller board instead of 1 monitor and 1 CPU. I am thinking about using Raspberry Pi. Is it fine? I want more information to proceed in this direction. Could anyone please help me?

    Reply
    • Hi Kush,
      Rapsberry Pi isn’t a microcontroller board. But since you want to add monitor, I’m guessing you’re not actually looking for a microcontroller board. Raspberry Pi works fine with a monitor.

      Reply

Leave a Comment