• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Build Electronic Circuits

Build Electronic Circuits

Electronics explained in a simple way

  • Start Learning
    • Basic Electronics
    • Digital Electronics
    • Circuits
    • Practical Skills
      • Printed Circuit Boards
    • Microcontrollers
      • Arduino
    • Maker Lifestyle
      • Podcast
  • About Me
  • Blog
  • Products
  • Contact
You are here: Home / Microcontrollers / Microcontroller Tutorial 3/5: How To Design a Microcontroller Circuit

Microcontroller Tutorial 3/5: How To Design a Microcontroller Circuit

November 11, 2014 By Øyvind Nydal Dahl 33 Comments

In this tutorial I will teach you how to build your own microcontroller circuit. This way, you can easily add microcontrollers to your own projects. We are now at part three of this tutorial.

In part one of the microcontroller tutorial, we looked at what a microcontroller is. We saw that a microcontroller is like a small computer, and that you can use it to build amazing things like cell phones or even your own handheld game-console.

Then in part two, we looked at different types of microcontrollers, and we chose one for our purpose. We chose the ATmega32U2 because we can program it through USB and it is reasonably easy to solder at home.

In this third part of the microcontroller tutorial, we are going to design our circuit from scratch. So we need to design a schematic diagram with all the components and connections necessary to make our circuit work.

Let’s build this thing!

Bonus: Download this 5-part tutorial as a PDF that will show you step by step how to make a microcontroller board you can build at home using standard hobby tools.
ox]

What Do We Need?

How do we decide which components to connect to our microcontroller?

Let’s think about it. We need power for the chip, otherwise it won’t work. And we need a USB connection, since we are going to program it through USB. And we need some physical pins where we can easily connect things to our circuit and test it.

So, we need:

  • Power
  • USB Connection
  • Pin Connections

The Datasheet

ATmega32U2 Datasheet FrontpageTo figure out exactly which components we need, and how to connect them, we look in the datasheet of the chip.

The datasheet is a comprehensive document with a lot of technical data on how the microcontroller works and how you can control different parts of it.

If you are not used to reading a datasheet, it might feel a bit overwhelming. But after looking at a few datasheets, you will sooner or later start to understand how it is laid out.

It is not necessary to read the datasheet from start to the end. You only need to read the parts that are interesting for what you want to make.

So if you want to make a timer with your microcontroller, you read the timer section. If you want to use the UART, you look up the UART section.

One thing to notice – in the datasheet of the ATmega32U2, the table of contents is placed at the end.

Power and USB

We can choose if we want the circuit to be powered by the USB cable or with an extra power cable.

To keep things simple and with less components, let’s make this a USB powered device. This means it will only work when it is connected to the USB.

So, what does this mean? Which components do we need?

To find out, let’s look in the USB-section of the datasheet, and see what we find.

USB Module Powering Options

From the table of contents at the end of the datasheet, we find a section called USB Module Powering Options at page 186. Here we can find the following figure that show us how to connect the USB section of the chip to make it powered by USB.

USB powered microcontroller
How to connect the ATmega32U2 as a USB powered 5V device. (Source: Atmel.com)

From Design guidelines on page 189 we learn that the resistors should be 22 Ohm resistors, and that it is also highly recommended to have a 10 µF capacitor on the VBUS line. So let’s add the 10µF capacitor too.

Crystal

Older crystal oscillatorIn the image above, we can see that there is also a crystal and two capacitors connected to the XTAL1 and XTAL2 pins. Why is this?

A microcontroller needs a clock to work. Most microcontrollers have an internal RC-oscillator that creates a clock signal. And so do the ATmega32U2.

But the thing is that the USB part of the microcontroller is not able to run from that internal clock. So to make USB work, we need an external crystal.

Exactly what kind of crystal we need, we can find at page 30 in the datasheet. Here, the capacitor values are also listed.

Pin Connections and LED

light-emitting-diodeWe want to be able to connect stuff to our microcontroller circuit. So, we’ll add 16 physical pins that are connected to the I/O pins PB0-PB7 and PD0-PD7. This makes it easy to connect something to our circuit.

Another thing we should add, is an LED. This way, we can easily check if the circuit and our code works. To control the current through the LED, we also add a current limiting resistor in series with it.

Push-Button for Reset

It is very common to have a reset button on a microcontroller circuit. This makes it easy to reset the microcontroller without having to unplug the USB cable.

From page 47 of the datasheet we can read:
«The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length.»

So we need to make sure the reset pin is normally pulled high, and only pull it low when the reset button is pushed.

To do this, we use something called a pull-up resistor. This is a resistor connected between the reset pin and VCC (5 volt) – which “pulls” the reset pin high.

We connect the reset button in a way so that the reset pin is connected to ground (0 volt) if the button is pushed.

Which value should this resistor have? A good value is around 10k Ohm. Sparkfun has a good article on how to choose a value for the pull-up resistor.

The Complete Microcontroller Circuit Diagram

If we combine all the parts that we’ve discussed above, we’ll end up with the following circuit diagram. You’ll notice that some parts seems to not be connected to the rest. But, when there is a name on a wire, it means this wire is connected to all the other wires with the same name.

Microcontroller Tutorial ATmega32U2 circuit with values

Designing a Circuit Board and Getting it Made

Wow, it’s all coming together now. All we have to do now is to create a circuit board. So, that’s exactly what we’ll do in the next part of the tutorial.

Next up, we need to create this circuit and have it made.

Bonus: Download this 5-part tutorial as a PDF that will show you step by step how to make a microcontroller board you can build at home using standard hobby tools.

Click here to continue to part 4 in the microcontroller tutorial >>

Filed Under: Microcontrollers

Reader Interactions

Comments


  1. clinton says

    November 12, 2014

    nice tutorial,,,,is there any way we can use this component for temperature controller for an electric heater to switch ON/OFF automatically

    Reply

    • admin says

      November 13, 2014

      Absolutely =) But how to do it depends on how you control the heater.
      Oyvind

      Reply

  2. Alfredo says

    November 13, 2014

    Thus a nice tutorial. Is there a way to use the micro-controller to control a light switching system?

    Reply

    • admin says

      November 13, 2014

      Absolutely =) But also here, how to do it depends on how you control your light system.
      Oyvind

      Reply

  3. Matthew says

    November 13, 2014

    Would you mind if I put a link to your website on my website?

    Reply

    • admin says

      November 14, 2014

      Go ahead =)

      Oyvind

      Reply

  4. Matthew says

    November 14, 2014

    Can you give us a list of all the components you are using to build this?

    Reply

    • admin says

      November 14, 2014

      You can see all the components in the schematic diagram.
      Maybe I’ll list them in the next part.

      Oyvind

      Reply

  5. sibusiso says

    November 14, 2014

    Thank you, I believe its the best thing you contributed.

    How to make a simple radio control for a toy car.

    I really enjoyed the tutorial, it is eye- opener to me as a beginner in this field.

    Yakudala

    Reply

  6. Chibuike Bright says

    November 14, 2014

    Please can i have your book ordered in Nigeria, please to be totally and
    richly blessed with it

    Reply

    • admin says

      November 21, 2014

      Yes, it’s an ebook, so you can download it anywhere in the world. You can buy it here: https://www.build-electronic-circuits.com/products/getting-started-with-electronics

      Cheers!
      Oyvind

      Reply

  7. Jayr says

    November 15, 2014

    Hi
    This is an smd micro, i’ve noticed.
    How am i going to solder it to the board. Why not choose a through hole device.
    Regards.

    Reply

    • Matthew says

      November 16, 2014

      I know I’m not Oyvind but here is a link on “How to smd solder with a soldering iron”

      Reply

    • Matthew says

      November 16, 2014

      sorry last comment did not work this is the link

      Reply

    • Matthew says

      November 16, 2014

      I am so so sorry I’m not good with HTML this is the link you need to learn how to Smd solder with just a soldering iron

      Hope it helps

      Reply

    • Matthew says

      November 16, 2014

      How to Smd solder

      Reply

    • admin says

      November 16, 2014

      I think the link Matthew is trying to post is this one: https://www.build-electronic-circuits.com/smd-soldering/

      Thanks for trying Matthew :)

      The reason I chose an SMD chip was because there are no through-hole AVR chips with USB. It’s really not that hard to solder. And a lot of chips come only in SMD packages, so I recommend learning it sooner than later.

      Oyvind

      Reply

  8. jc villa says

    November 20, 2014

    looking forward for the next part on mcu tutorials. TY.

    Reply

  9. peter ayodeji says

    November 20, 2014

    thanks
    pls, will you tutor us on programing micro-controllers?

    Reply

    • admin says

      November 21, 2014

      That will come in part 5.

      Cheers!
      Oyvind

      Reply

  10. shan says

    November 28, 2014

    nice

    Reply

  11. Markus says

    September 25, 2015

    I cannot find the capacitor values on page 36 of the datasheet. Page 186 in the datasheet suggests a crystall of 16MHz if the power supply exceeds 4.5V. Since we have a USB connection with a 5V signal voltage, should we not use the 16MHz crystal?

    I was also wondering about the maximum power of the 22 Ohm resistors that we use for the USB D+,D- connections. USB 2.0 has a maximum current of 0.5A, thus a maximum power of P=U*I=R*I*I=(22*0.5*0.5)W=5.5W. This current would never be demanded by the circuitry, but is there any hint about the current or power that the resistors has to withstand?

    Reply

    • admin says

      September 26, 2015

      Hey Markus,

      Great questions. I like that you are diving into it properly.

      Looks like crystal and capacitor values are on page 30 now.

      Page 186 suggest a crystal of MAX 16 MHz for 5V. But less is also ok.

      About the max power of the 22 ohm resistors: The resistors are on the data lines. The 0.5 A is the max power from the VBUS line. I’m not sure how much power the resistors need to be able to handle, but since I’ve never seen it specified I assume 1/4W resistors are good enough.

      Cheers!
      Oyvind

      Reply

  12. PRAKASH says

    October 18, 2016

    does this micro-controller can be programmed using keil or only AURDINO

    Reply

    • admin says

      October 19, 2016

      I’m not familiar with Keith. Arduino does not work without changing the bootloader I think…

      Reply

  13. Lester de Guzman says

    November 7, 2016

    Is it necessary to memorize what VCC, UVCC, AVCC etc. and to know it’s meaning? it makes me a lit’l confusion about the diagram.

    Reply

    • admin says

      November 8, 2016

      These power different parts of the chip. You can find information about these pins in the datasheet. But often, they can all be connected to one power source.

      Best,
      Oyvind

      Reply

  14. Justin A says

    November 15, 2016

    Is it possible for circuit to be powered by an external power source such as a button battery as well as be programmable through USB?

    Reply

    • admin says

      November 16, 2016

      If the circuit uses very little energy, then it’s possible. For this one, I doubt it.

      Reply

  15. Dhaval Taneja says

    May 21, 2017

    As soon as you(admin) reached at the 3rd part of the tutorial, where you, started talking about the usage of resistors and capacitors, I kind of started getting a hunch of complexity, because I am not good at basics (why, where, how and what type of resistors and capacitors do we use) in multiple applications/circuits.
    If you clear my doubt that I will be very helpful for me to pursue my career.
    Regards
    Dhaval Taneja

    Reply

    • admin says

      May 22, 2017

      Here’s a place to start:
      https://www.build-electronic-circuits.com/basic-electronic-components

      Best,
      Oyvind

      Reply

  16. Zac says

    November 15, 2017

    Great tutorial, I plan on starting it soon.. but my question is, what kind of USB should I use? (Micro, Mini, Type A/B, etc)? Or doesn’t it matter?

    Reply

    • admin says

      November 19, 2017

      You should use Type B as that is the type used on non-host devices. But it doesn’t matter if you choose mini or micro.

      Reply

Leave a Reply Cancel reply

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

Primary Sidebar

Search:

Footer

Topics

  • Basic Electronics
  • Digital Electronics
  • Circuits
  • Practical Skills
  • Microcontrollers
  • Maker Lifestyle
  • Newsletter Archive

Social:

  • Facebook
  • Twitter
  • YouTube

Copyright © 2021 · Ohmify AS · Terms and Conditions · Privacy Policy