Microcontroller Lab - SARCNET

School Amateur Radio Club Network
School Amateur Radio Club Network
School Amateur Radio Club Network
School Amateur Radio Club Network
Title
Go to content
Microcontroller Lab
This activity introduces the concept of a microcontrollers and programming and provides practice in its use.
Introduction
We think the best way to get into microcontrollers and programming is to get hands-on experience right from the beginning. Unlike other computers, microcontrollers work directly with all your electronic devices, sensors and actuators. So, to get started, we connect an LED to show how easy it is to control something. Setting up your Arduino microcontroller and the Arduino Integrated Development Environment (IDE) is also straightforward. We like to see our students doing the downloading and installation too. Entering a simple program, in Arduino language this is called a sketch, compiling it and uploading it, is also very instructive. The lesson is that we don't have to learn to program before seeing what a microcontroller can do. Infact there are many complete example programs to choose from. You can load and run them without any programming experience whatsoever.

Of course, this is just the begining. We can use this simple microcontroller setup to learn how to write our own programs and we can use it for many different electronics projects. Once we have completed this activity, we invite interested students to attend our Microcontroller Workshop and our Object Oriented Programming Workshop. These hands-on workshops introduce them to the C and C++ programming language. We found that teaching students, some as young as 5 years old, how to program using OOP techniques and C++ is just as easy as teaching them to write "spaghetti" code in C. The advantages of OOP in terms of modularity, reuseability, maintainability, extensibility and portability should never be underestimated. Learning how to program correctly, from the start, is really going to save students completely re-leaning the proper techniques later. We say no to "scratching" around and we get going with C++ on day 1.
Preparation
We provide an Arduino compatible ProMicro microcontroller on an electronics prototyping board with a USB cable for connection to your laptop computer. The parts for this are readily available on eBay.

You will need:
  1. Arduino Compatible Pro Micro. Solder the header pins (provided) to it so it can be inserted into the prototyping board.
  2. A 400 hole solderless breadboard. We call it a prototyping board.
  3. A Light emitting diode
  4. A 470 Ohm resistor
  5. A Type A to Micro USB cable
  6. A laptop computer with Internet connectivity
Activity
  • CAUTION: The micro USB socket on the Pro Micro PCB is very delicate. Pressing down on the connector, on the left, will easily snap the socket off the PCB, rendering it useless. Never press down on the connector. Never mount the Pro Micro PCB at the top of the prototyping board.
  • Connect the components as shown in the diagram below.
  • The long lead of the LED goes to pin 9 - If you look inside an LED you will see a post and anvil structure. The post is always positive.
  • Download and install the Arduino IDE from here to your laptop computer.
  • After you have done that, plug the Pro Micro into your Laptop using the USB Cable.
  • Wait for the USB drivers to be fully installed.
  • Open the Ardunio IDE on your laptop.
  • Select: Tools | Board: Arduino Leonardo
  • Select: Tools | Port: COMx (Arduino Leonardo)
  • Select: File | Save As: example
  • Select File | New. Add the following text to the sketch template provided. Check highlighting, spelling and semicolons.

const int LED = 9;

void setup() {
 // put your setup code here, to run once:
pinMode(LED, OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:
 digitalWrite(LED, HIGH);
 delay(100);
 digitalWrite(LED, LOW);
 delay(100);
}

  • Press the verify button. You should see "Done compiling" and the following information:

Sketch uses 3956 bytes (13%) of program storage space. Maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes for local variables. Maximum is 2560 bytes.

  • Press the upload button. You should see the TX and RX LEDs on the Pro Micro flash three times. Then: "Done uploading".
  • The LED connected to pin 9 should be blinking, 100ms on and 100ms off.


Arduino Pro Micro on Prototyping Board
Arduino Pro Micro Pinouts


Homework
  1. What changes would you make to the program to make the LED flash on for 200ms and off for 800ms?
  2. What changes would you make to the program to flash two LEDs, LED1 and LED2 (the second one connected to pin 8), such that when one is on the other is off and vice-verse.
  3. In the Arduino IDE Right-Click on any words highlighted in orange: Select Find in Reference to learn more about what they mean.

Back to content