• Skip to content
  • Skip to primary sidebar
  • Skip to footer

Build Electronic Circuits

Electronics explained in a simple way

  • About Me
  • Articles
  • Products
  • Contact

Microcontroller Programming

August 28, 2013 By Øyvind Nydal Dahl 42 Comments

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.

Filed Under: Article

Reader Interactions

Comments

  1. thankgod says

    November 4, 2014 at 7:42 am

    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
    • admin says

      November 4, 2014 at 11:47 am

      Hey Thankgod,

      I am doing a microcontroller tutorial right now actually. Check it out here: http://www.build-electronic-circuits.com/microcontroller-tutorial-part1/

      Cheers!
      Oyvind

      Reply
  2. Efrtainj says

    January 1, 2015 at 4:13 pm

    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
    • admin says

      January 1, 2015 at 5:30 pm

      Hey, I’ve reset your download attempts, so you can try again now.

      Oyvind

      Reply
  3. Amar wandile says

    March 20, 2015 at 2:00 pm

    Pls give coding for boolean algebra calculator

    Reply
    • admin says

      March 20, 2015 at 3:24 pm

      Sorry, I don’t have that.

      Oyvind

      Reply
  4. venkatesh says

    June 18, 2015 at 2:15 pm

    plz
    give me program for
    any one of port pins one by one act as output circulatingly

    Reply
  5. mathew kimaiyo says

    September 11, 2015 at 9:25 am

    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
  6. Sahil sharma says

    September 29, 2015 at 5:43 pm

    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
    • admin says

      October 5, 2015 at 10:52 pm

      Hey,

      My microcontroller tutorial might get you on the right track:
      http://www.build-electronic-circuits.com/microcontroller-tutorial-part1/

      Or if you prefer to start with something easier:
      http://www.build-electronic-circuits.com/electronics-for-beginners/

      Reply
  7. JOHNS JOSEPH K says

    February 18, 2016 at 7:41 am

    CAN WE USE C++ TO CODE MICROCONTROLLERS ( EG ATMEGA328 )

    Reply
    • admin says

      February 18, 2016 at 4:38 pm

      Yes, if you have a compiler that supports it.
      Oyvind

      Reply
  8. KC says

    May 27, 2016 at 10:21 pm

    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
    • admin says

      June 2, 2016 at 6:22 pm

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

      I prefer testing in real life though…

      Best,
      Oyvind

      Reply
  9. Rodney says

    August 1, 2016 at 11:46 pm

    Thanks sir, pls email me i am very interested in programing. Am a novice for now but with u as a mentor i will go far. Plz email me

    Reply
    • mohammed says

      February 22, 2017 at 4:36 pm

      i need you also email me

      Reply
  10. Rodney says

    August 1, 2016 at 11:49 pm

    I also need ur website… pls

    Reply
  11. Edul Brian says

    September 2, 2016 at 9:17 pm

    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
  12. J° says

    October 11, 2016 at 8:26 am

    Hey is there anyone,,, who will plz send me an example or syntax or a program related to microcontroller proframing,,,, plz reply fast,,,

    Reply
  13. Reza says

    November 30, 2016 at 1:02 pm

    Hi.
    Can you help me to build a microcontroller for ultrasonic cleaners? What are the characteristics of it?

    Reply
  14. JAVAID says

    December 22, 2016 at 7:03 am

    hello sir
    we need a code for project ” automatic irrigation system running on solar enegy”
    can u please help us with the same.

    Reply
  15. vj says

    January 7, 2017 at 5:02 pm

    i want to inforamation about microcontroller in writting the program.

    Reply
    • vj says

      January 7, 2017 at 5:14 pm

      plz i need inforamation about microcontroller in writting the assembly level language program.

      Reply
      • admin says

        January 9, 2017 at 8:30 am

        Sorry I don’t have any resources on that. But you should find plenty on Google.

        Best,
        Oyvind

        Reply
  16. Vincent says

    February 16, 2017 at 5:04 am

    please i want to be good in microcontroller programming,how do i go about getting your tutor pdf or video

    [email protected]

    Reply
    • admin says

      February 20, 2017 at 4:18 am

      I have some courses on getting started with Arduino in my online membership club Ohmify: https://ohmify.com/join

      That’s a good way to start.

      Best,
      Oyvind

      Reply
  17. mohammed says

    February 22, 2017 at 4:37 pm

    i need you also email me

    Reply
  18. jennifer says

    April 18, 2017 at 5:27 am

    kindly help me with a microcontroller coding to generate pwm

    Reply
  19. Hari Satriyo Basuki says

    June 21, 2017 at 5:46 am

    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
  20. Dipesh Awasthi says

    August 9, 2017 at 4:17 pm

    Thanks for this information…….😊😊😊😊😊😊

    Reply
  21. Derrick woodall says

    November 2, 2017 at 5:38 am

    i am making a microcontroller project for health . i needed this ! Coding is the way to the future!!!

    Reply
  22. juliet says

    November 13, 2017 at 2:36 pm

    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
  23. steve nzukh says

    November 14, 2017 at 9:01 pm

    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
  24. steve says

    November 22, 2017 at 3:22 pm

    Thanks for the tutorial. . am a beginner hoping to write good programs someday. . please email me

    Reply
  25. Larry McVey says

    December 18, 2017 at 9:39 pm

    new to this all. But some of your links are dead. Or product not for sale any more.

    Reply
    • admin says

      December 19, 2017 at 3:13 pm

      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
  26. Becky says

    February 25, 2018 at 6:20 pm

    Hi sir.Help me code an intel Edison microcontroller to control the arm movement of a robot.

    Reply
  27. Jacob Hughes says

    March 28, 2018 at 10:45 pm

    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
    • admin says

      April 9, 2018 at 10:28 am

      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
  28. Sean says

    September 7, 2018 at 9:47 am

    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
  29. ajit kumar says

    October 1, 2018 at 8:08 pm

    sir how can i write a program in 8051 micro controller?

    Reply
  30. William D says

    January 30, 2019 at 1:25 am

    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

Leave a Reply Cancel reply

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

Primary Sidebar

Most Popular:

  • Electronics Explained In Simple Ways
  • Basic Electronic Components Used in Circuits
  • Blinking LED Circuit with Schematics and Explanation
  • How Transistors Work - A Simple Explanation
  • The Simple Guide To Learning Electronics For Beginners

Search:

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Footer

Site:

Home
About
Blog
Contact

Social:

Facebook
Twitter
YouTube
Google+

Copyright © 2019 · Dahl Technology · Terms and Conditions