A Beginner's Guide to Microcontrollers

41,980

464

32

About: Dabbled in dark matter, settled into engineering with a blend of inventing and teaching, always trying to solve problems + learn new things!

Intro: A Beginner's Guide to Microcontrollers

What do remote controllers, routers, and robots all have in common? Microcontrollers! These days, beginner-friendly microcontrollers are easy to use and program with just a laptop, a USB cable, and some (free) open-source software. Woohoo!! All the projects, here we come!

The catch? There are like, 4324302* different microcontrollers and it can be daunting to get started, especially if you're just getting into electronics. Where the heck do you start?!

Right here, bbies, I got chu. Whether you are looking to build some cool electronic projects, learn programming/tech, or wanting to teach others about electronics, this tutorial will help you figure out what microcontroller is right for your needs, goals, and budgets. Yay! Let's get started!

Read Time: ~ 20 min

*Ok, ok, maybe not *that* many, but definitely a few dozen!

Step 1: Wait.... What Is a Microcontroller?

Maybe you've seen this word and were like "wtf" but didn't feel comfy enough to ask*. Totally fine, here's a quick rundown:

A microcontroller is a "simple computer" that runs one program in a loop. They are designed to perform a single, specific task.

In this guide, we'll be focusing on microcontrollers that have breakout boards, or a board that makes it easier to connect to and program the microcontroller.

On a breakout board, the microcontroller pins are soldered to a printed circuit board ("PCB"), headers or other connectors are added to the PCB, and some basic firmware, or permanent software, is loaded to prep the microcontroller to receive signals.

*Questions are always good even if they are "dumb" or "n00by", just find a safe space -- like Instructables!

Step 2: What's the Difference Between the Raspberry Pi and a Microcontroller?

The Raspberry Pi is not only small and adorable, it is also a full-fledged computer! :D

Computers have microprocessors AND microcontrollers that work together to perform many tasks at once.

The microprocessor is what does the “heavy lifting” in a computer. It performs the instructions and calculations that make the computer work. Microprocessors are much faster than microcontrollers, but they need external resources like RAM, Input/Output ports, etc., whereas a microcontroller is typically self-contained.

Computers (which have inputs and outputs, storage, and processing) can run multiple programs at a time -- you can surf the Internet, reminisce with old photos, write a paper, and have like 1000 tabs open all at the same time! Microcontrollers... not so much. You can do one of those things, but not all.

To learn more about the Raspberry Pi, check out the last section of this tutorial!

Step 3: Arduino (Uno)

A robust, open-source microcontroller and programming environment designed for beginners with some knowledge of circuits.

Recommended Ages: 12+ (or kids comfy with programming and algebra)

Difficulty: Intermediate

Average Cost: ~$35

There are lots of different types of Arduino boards. This is the Arduino Uno, the best fit for beginners! There are boards that are larger, smaller, wearable, and for specialty use cases like robotics.

Being familiar with Arduino boards and programming maps well to projects and careers in computer science, engineering, and design.

Hardware Features

  • The Arduino Uno has 14 Digital Input & Output ("I/O") pins, 6 Analog I/O pins, 2 Power Out pins (3.3V and 5V), and 3 Ground (GND) pins.
  • Power input can be anywhere from 5 to 12 VDC
  • The ICSP headers allow you to connect a ton of different add-on boards called "shields".
    • For example, you can add a WiFi shield to connect your Arduino to the 'net!

Programming Language: Wiring (Combo of C++/Processing)

Example Project: Motion-Reactive Shake the Maze Game!

Purchase/Learn More: Arduino Website

Step 4: Micro:Bit

A friendly lil’ microcontroller handy for kids and folks just getting started with coding and hardware.

Recommended Ages: 8+ (or kids comfy with circuits and simple tools)

Difficulty: Beginner

Average Cost: ~$15

The Micro:Bit is a great tool to start learning how to code, teaching others, particularly elementary school students, how to code, and making simple and quick electronic prototypes.

The Micro:Bit is a collaboration between Microsoft and the BBC to bring educational computers into classrooms around the world.

Hardware Features:

  • The Micro:Bit has 3 Digital and Analog I/O pins, 1 Power Out pin (3.3V), and 1 Ground (GND) pin
  • Power input should be 3 - 5 VDC via micro USB cable or battery pack connector.
  • It also has lots of onboard inputs, outputs, and sensors!
    • 5x5 (25) LED matrix
    • Two (2) Pushbuttons (A, B)
    • Radio Transmitter and Receiver
    • Accelerometer
    • Compass
    • Light and Temperature Sensors
  • For more I/O pins, grab a Micro:Bit breakout!

Programming Language: Block-Based or Javascript (www.MakeCode.org); can also use CircuitPython

Example Project: Text Messenger Puppet!

Purchase/Learn More: Micro:Bit Website

Step 5: Circuit Playground Express

A versatile microcontroller great for kids and folks just getting started with coding and hardware.

Note: There is also the Circuit Playground Classic -- the hardware is nearly identical, but this board is programmed in the Arduino IDE.

Recommended Ages: 8+ (or kids comfy with circuits and simple tools)

Difficulty: Beginner

Average Cost: ~$25

The Circuit Playground Express, or CPX, is a helpful tool to learn how to code, teach others how to code, and make quick prototypes for beginners to experts alike.

The Circuit Playground Express is a powerful and versatile microcontroller created by Adafruit Industries.

Hardware Features

  • The CPX has 7 Digital/Analog Input & Output ("I/O") rings that are also capacitive touch!
    • 1 "true" Analog I/O ring
    • 2 Power out ring (3.3V)
    • 3 Ground (GND) pins
  • Power input should be 3 - 5 VDC via micro USB cable or battery pack connector.
  • There are also tons of onboard inputs, outputs, and sensors!
    • 10 Mini Neopixels (can be all colors)
    • 2 Pushbuttons (A, B)
    • 1 Slide Switch
    • Infrared Transmitter and Receiver
      • Can receive/transmit remote control codes, send message between CPXs, and act as a distance sensor
    • Accelerometer
    • Sound sensor and mini speaker
    • Light and Temperature Sensors

Programming Language: Block-Based or Javascript (www.MakeCode.org); can also use CircuitPython and Wiring (Arduino IDE)

Example Project: Minecraft Gesture Controller!

Purchase/Learn More:Adafruit Industries

Step 6: Makey Makey

An interactive introductory microcontroller great for young kids and folks new to electronics and coding, especially for those who want to play with technology without having to build circuits and code.

Recommended Ages: 5+ (or kids comfy with simple tools)

Difficulty: Beginner

Average Cost: ~$50

The Makey Makey is a great first step into electronics and technology -- no programming required! Connect alligator clips to the pads and then connect any somewhat conductive material, like hands, fruit, or metal objects, to trigger certain keyboard and mouse keys.

The Makey Makey is an Arduino-compatible board, meaning that you can also reprogram it using the Arduino Integrated Development Environment ("IDE").

Hardware Features

  • The Makey Makey has six (6) capacitive touch pads on the front of the board:
    • Four control the keyboard arrow keys,
    • One controls the spacebar, and
    • One controls the left mouse click.
    • On the back of the board are header pins for more controls (also capacitive touch):
      • Six (6) pins that map to letters,
      • Four (4) pins that map to arrows,
      • Two (2) pins that map to mouse keys, and
      • One (1) pin that maps to the spacebar key.
      • There are also three (3) general I/O pins, a 5V power pin, and a ground pin.

    Programming Language: Not applicable for beginners; can write Scratch programs (block-based); can reprogram in Wiring (Arduino IDE)

    Example Projects

    Beginner: Floor Piano

    Intermediate: Interactive Survey Game!

    Purchase/Learn More: Makey Makey website

    Step 7: Other Common Boards

    There are waaaay too many microcontrollers to cover in one tutorial. If you have a super specific specialty need, there is probably a microcontroller for that (just like apps!). To get a feel for some of the other boards not mentioned in this tutorial, peruse the inventories of SparkFun Electronics and Adafruit Industries and/or ask folks in the field!

    Here are a few of my favs:

    Particle Photon

    Similar to the Arduino Nano, the Photon is a WiFi connected microcontroller that can be programmed wirelessly. The easiest setup uses a (free) smartphone app, but if can also be programmed directly via USB in almost the same language as Arduino*.

    Recommended Ages: 12+ (or kids comfy w/ circuits and coding)

    Difficulty: Intermediate

    Cost: ~$20

    For more info and to get the Photon setup, visit the Particle online store here.

    Programming Language: Wiring (more or less)

    Example Project

    IoT Industrial Scale

    *Wiring is the code framework, so most Arduino code will work without modifications. Can also write in C/C++ or ARM assembly

    Adafruit HUZZAH ESP8266 Breakout

    A super small, super cheap (and currently very popular in the IoT* community) WiFi microcontroller. You'll need an FTDI or console cable. You can use the Arduino IDE to program this board or NodeMCU's Lua Interpreter.

    Recommended Ages: 14+ (or kids comfy w/ hardware & software)

    Difficulty: Intermediate++

    Cost: ~$10

    For more info, visit the HUZZAH Adafruit product page.

    (SparkFun also has a similar board, the "ESP8266 Thing", which you can find here for ~$15.)

    Programming Language: Lua (sorta like Python) or Wiring (Arduino IDE)

    *IoT stands for "Internet of Things", which is the term that refers to connecting and controlling various hardware devices, like sensors and household electronics, to the Internet.

    Adafruit Trinket M0

    A teeny tiny yet powerful microcontroller that blurs the lines between computer and microcontroller (it has an ATSAMD21E18 32-bit Cortex M0 processor). It can be programmed with Circuit Python or in the Arudino IDE.

    Recommended Ages: 14+ (or kids comfy w/ hardware & software)

    Difficulty: Intermediate

    Cost: ~$9

    For more info, visit the Adafruit product page for the Trinket M0.

    Programming Language: CircuitPython or Wiring (Arduino IDE)

    There are a TON of other M0 boards, similar in scope to the Arduino Zero connectable microcontrollers. If this doesn't suit your needs or your fancy, search around on the Adafruit and SparkFun websites!

    Step 8: Wearable Microcontrollers

    There are also a handful of microcontrollers designed for wearable projects!

    What makes these special is that they can be washed, so you don't have to rip them out of the awesome project you made (but do remove the battery!).

    Wearable microcontrollers also have special I/O pins that make it easier to sew into clothing and stitch circuits with conductive thread. Here are a few of my favs:

    Adafruit FLORA

    A circular sewable microcontroller with 14 inputs and outputs. Can be washed (but def remove the battery).

    Recommended Ages: 12+ (or kids comfy w/ circuits and coding)

    Difficulty: Intermediate

    Cost: $15

    Programming Language: Wiring (Arduino IDE)

    For more information, visit the Adafruit FLORA product page.

    Arduino Gemma

    A lil' tiny sewable microcontroller with 3 inputs and outputs. Perfect for hiding, connecting to small objects, and creating jewelry.

    Recommended Ages: 12+

    Difficulty: Intermediate

    Cost: ~$5

    Programming Language: Wiring (Arduino IDE)

    For more information, visit the Arduino Gemma product page.

    Arduino Lilypad

    A circular sewable microcontroller with 14 available inputs and outputs.

    Recommended Ages: 12+

    Difficulty: Intermediate

    Cost: ~$25

    Programming Language: Wiring (Arduino IDE)

    For more information, visit the SparkFun product page for the Lilypad.

    Step 9: Raspberry Pi 3

    The Raspberry Pi, or Pi for short, is a credit-card sized computer* that runs a special version of Linux and can be programmed to control hardware.

    Recommended Ages: 12+
    Or kids comfy with coding and algebra

    Difficulty: Intermediate (easy as a computer)

    Average Cost: ~$35

    The Raspberry Pi computer, or Pi for short, can be used as a “standard” computer or as a controller for all sorts of hardware projects. It is a great first computer for kids to use and learn to code on, and is widely used by hardware experts to build all sorts of electronic projects, from robots to 3D printers to home automation systems!

    The Raspberry Pi has changed the way we build electronics! There are a few different versions, the most recent is the Raspberry Pi 3 and the Pi Zero, a miniature version of the Pi 3 for just $10.

    Hardware Overview

    • The recommended Operating System (“OS”) is a special version of Linux called Raspbian.
    • The Pi has 40 General Purpose Input and Output (“GPIO”) pins.
      • 26 Digital I/O pins (no Analog I/O)
      • 4 Power Out pins (two 3.3V and two 5V)
      • 8 Ground (GND) pins
      • 2 Specialty Pins (I2C ID EEPROM, advanced use only)
    • The Pi also has most standard computer features:
      • 4 USB Ports
      • 1 Ethernet port
      • 1 HDMI port
      • 1 Audio Jack
      • 1 Camera Module Port

    Programming Language (for GPIO pins): Python or C++

    Since this is a full computer, you can program in whatever language you want, including programming other microcontrollers!

    Example Projects

    IoT Pet Monitor!

    Impact Force Monitor

    Purchase/More Info: Raspberry Pi Foundation

    *The Pi can be used similar to a standard microcontroller AND can also control microcontrollers! Basically, the Pi is super awesome and I *have* to include it even tho it is technically a computer :)

    Step 10: Final Thoughts

    If you are just getting started and want to build all sorts of projects, I'd recommend the Circuit Playground Express. It's super easy to get up and running and has a ton of onboard gadgets.

    If you are super interested in computer networking, AI, or connecting things to the Internet (e.g. making a "Smart Home"), I'd suggest the Raspberry Pi.

    If you want a sturdy, stable, and reliable board to build a wide variety of projects, go with an Arduino.

    If you still have no idea where to start and are totally intimidated, start with the Micro:Bit -- it's only $15 and has plenty of snazzy things on it to play with. Plus, if you get one for your friend, you can send lil' messages back and forth :)

    The best advice I can give you is to find a project you are passionate about and build it! There are tons of tutorials online so search around for someone who has built the same or similar project. Build off of their findings and adjust as you please!

    And of course, leave any related questions in the comments and I'll do my best to help!

    Happy hacking!

    Share

      Recommendations

      • Metalworking Contest

        Metalworking Contest
      • Tiny Home Contest

        Tiny Home Contest
      • Furniture Contest 2018

        Furniture Contest 2018

      32 Discussions

      0
      None
      jayrro

      4 weeks ago

      Nice introduction of the MCU's, but I expected more from this instructable. For example which languages you can use to program them - like Basic, python, C, asm, Pascal... Then how you can connect pins, what is difference between digital and analog i/o pins or ports. I've definitely changed the header of this instructable for something like "which microcontroller to use?"or "What mcu's are out there"

      1 reply
      0
      None
      jenfoxbotjayrro

      Reply 26 days ago

      Good suggestions! I wanted to keep the writing to a minimum, on this tutorial, but I will add in the programming languages.

      0
      None
      garnetshaw

      4 weeks ago

      Excellent article.

      0
      None
      kjbrand

      5 weeks ago on Introduction

      Add another to the pile: the STM32F103C8T6 - what they call the Blue Pill. It's under $4 on Bangood and very fast - 72MHz, 64K Flash, 37 I/O. Great tutorial videos on YouTube.

      2 replies
      0
      None
      jenfoxbotkjbrand

      Reply 5 weeks ago

      Right -- there are more microcontrollers out there than one person could possibly keep track of. The goal of this tutorial was to provide an overview on the most common and easily accessible microcontrollers.

      0
      None
      Omniventjenfoxbot

      Reply 4 weeks ago

      Hi,

      Yes, it's impossible to know them all, considering the speed at which new variants hit the market. For a hobbyist, it's better to just go with a few models, which also makes it easier to get good prices from large(-ish) orders. Buying e.g. PIC10F chips from MicroChipDirect can get you like.3 to 4 chips/$ when you buy them by the hundreds
      (and you do, as their quite steep shipping fee is probably meant to scare off those who aren't serious ;)

      The ever changing landscape of microcontrollers also means new programming chains (if you look outside Arduinos and such)

      .

      I won't turn this into a "hey, you missed ARM etc.", but I do have a few corrections though:

      Arduinos, Pi's etc. are microcontroller _boards_

      A _breakout board_ is a PCB that makes it easier to use SMD chips of any kind. (e.g. in a solderless breadboard)

      .

      The forerunner to microcontrollers we called Minimum Systems, which held CPU, (UVEP)ROM and RAM, with optional periferal adapter and Timer-Counter chips etc. for special functions, some of them smaller than the larger Arduinos (and packed so hard that there was no place for a speck of dust ;)

      .

      A microcontroller is not a one-job chip either, just like with a (single core) CPU - The early pre-Windows PC's could run one job at a time, then along came Win 1,0 and all computer guys had a ROFL moment. Around Win 3.1 it started to look usable for multitasking, but it was really just a shell for (MS/PC)DOS.

      Software can add multitasking to all but the smallest microcontrollers - just add a RTOS or build your software with State Machines for simulated or Time Slice multitasking (and you even have multi-kernal microcontrollers that are born for multitasking (The Propellor is an early-ish example), although I personally prefer to just add the amount of microcontrollers needed, to make both the hardware and the software handling easier and modular.(Master/Slave setup).

      .

      Have a nice day :)

      0
      None
      Willys36

      5 weeks ago

      I was excited to read your Instructable and was getting into it until I saw that you had to be 8 yrs. old to understand this stuff. Bummer. I am 69 and a 45 yr practicing engineer so there is no hope I can comprehend what you are saying.

      2 replies
      0
      None
      jenfoxbotWillys36

      Reply 5 weeks ago

      Welp, I guess you'll just have to unlearn a few things!

      0
      None
      der_fisherman

      5 weeks ago

      Hi, I read your reply and it appears that you have not been able to check the PICAXE offerings out yourself.

      Firstly, they were designed for school children, also to cut the costs dramatically of using Arduinos and similar, plus making them simpler to use. They start at around US$3, and, as I have found out, myself are very robust, so that children can use them safely...

      Also, they can use "Shields" from other products if needed.

      From Wikipedia:-

      PICAXE is a microcontroller system based on a range of MicrochipPICmicrocontrollers. PICAXE devices are essentially Microchip PIC devices, with pre-programmed firmware that enables bootloading of code directly from a PC, simplifying hobbyist embedded development (not unlike the Arduino and ParallaxBASIC Stamp systems). PICAXE devices have been produced by Revolution Education (Rev-Ed) since 1999.

      https://en.wikipedia.org/wiki/PICAXE

      I am not trying to "force you" in any way, but I do feel that your excellent instructable would be even better for your "followers" , it they were also covered. For around $20 you can start, with many "parts" from other types also usable with the PICAXE versions, but your choice of course!

      I was fascinated by electronics at at early age and later worked for many years in the computer industry in Europe. Being retired, PICAXE is my choice of chip nowadays at almost 72 years old.

      It is not new to instructables, see here:- https://www.instructables.com/howto/PICAXE/

      I wish you a great day.

      Regards

      Andy

      PS. No need to reply unless you wish to....

      0
      None
      kjbrand

      5 weeks ago on Step 3

      What a great resource for our makerspaces! Teachers have heard of one or many of these microcontrollers and I'm always struggling to draw a 'map' of the MCU Terrain! Thanks!

      BTW: Do you think algebra is really necessary? I've done coding for most of my career (I'm 65) and never thought numeracy of that type was needed.

      Kim

      1 reply
      0
      None
      jenfoxbotkjbrand

      Reply 5 weeks ago

      Very glad to hear this will be helpful for your teachers! That was exactly what inspired me to write the tutorial .

      Full algebra isn't necessary, but folks do need to understand what variables are and how to use them when working with the Arduino programming language (Wiring -- combo of C++ and processing) or other object-oriented languages. I've run into this with 9 and 10 years olds before -- if they don't understand variables it makes it very difficult (although not impossible). I'd say working one-on-one or in a very small group with students it's possible to teach younger kiddos Arduino, but in a large class it would be challenging. Hope that helps!

      1
      None
      dreisn

      5 weeks ago

      Congrats on your "Instructable".

      Just to add a few info:

      Like SteveJ73 stated "microcontroller" is the chip in the board and not the whole board.

      The main difference between microcontroller (MCU) and microprocessor (MPU or CPU) is that microcontroller is a microprocessor that runs on internal (inside chip) memory which contains the Firmware. Microcontrollers use external memory (they have to load the Software from a Non-Volatile media) like HDD or Flash Chips.

      Also, usually MPUs are just that!... a simple MPU, while MCUs commonly have several other functions "in-chip" that may be connected or not to the internal CPU like serial ports, RTC, ADCs, etc...

      Some time ago, it came another wave of devices that started to dominate the market: the SoCs (System on Chip) that merge the good in MCUs with the good in MPUs: It's a CPU with several side systems like Graphics processor, peripherals controllers, etc... and, like the name says it's all in the same package/chip.

      These are the chips that are used in (almost) everyone's phone, tablets and even Computers... and are the chips that power the Raspberry Pi.

      Thanks

      1 reply
      0
      None
      jenfoxbotdreisn

      Reply 5 weeks ago

      All good info, although not necessarily appropriate for beginners. Thanks for sharing.

      1
      None
      der_fisherman

      5 weeks ago

      Great instructable which will help many.

      Also,if you update your text here, may I suggest that you add in the system called PICAXE as well.

      The chips are the cheapest on the market that can still be easily and very cheaply connected to a PC via a USB or a serial port connection, for programming and debugging.....

      All the NEEDED software is free to download.

      All the HUGE manuals are free to download.

      Chip prices are in the pocket money range....

      Available in most countries...

      They run an extensive version of their own BASIC, easy to understand and will run on practically and old PC or Laptop, most old Window OSs, even really old ones, as long as there is a simple text editor.

      Thy may even work on other OSs, I haven't tried. Once you have a the old laptop and the download cable, the interface is just a few resistors that can be included on the breadboard or printed circuit! I use them mostly on breadboads.

      The Microprocessors start at 8 pins up to 40 pins, with many even high speedsup to 64 MHz!

      http://www.picaxe.com/What-Is-PICAXE

      Enjoy and many thanks for your great instructable!

      Andy

      2 replies
      0
      None
      jenfoxbotder_fisherman

      Reply 5 weeks ago

      Thanks for the feedback and suggestion. IMO, Picaxe are too advanced for complete beginners, but they are a good board for folks to transition into. Perhaps you can write up a tutorial on them!

      0
      None
      JohnC430der_fisherman

      Reply 5 weeks ago

      thanks for the info. however all i see is the chip. whats needed is the whole board with the interfaces required to input and output the programs and make it do stuff.

      0
      None
      RaymondR6

      5 weeks ago

      You have a error in this statement:

      "Computers (which are microprocessors).." Computers are NOT microprocessors! They can use microprocessors are the main unit (also known as a CPU), but need more than a microprocessor to be a full "computer". There were many computers in the market way before Intel produced the first 4-bit microprocessor in 1971.

      I work with all sizes of computers since 1972 when they had physical transistors and held just kilobytes of memory, from the IBM System 360/30 (with 16 KB RAM and 10 MB disk) , and the Arduino and Raspberry Pi now.. So don't mix a "computer" with just a "processor" or a "controller". Each one is different, no matter the size from mainframe to midrange, mini, and micro.