Continuing Electronics Prototyping microcontrollers, LEDs, switches
In this tutorial we continue with the Project 1 series completing the prototype with an Atmega16 microcontroller, switches, LEDs, and various resistors.
At the end of each tutorial, there is a link to open a printable version of the tutorial.
If you have any suggestions on improving this or other tutorials, would like to see another added or even have one ready that you would like to add to the site, send the webmaster an email with the description and, if applicable, a copy of the tutorial you wish to submit.
There is no fee for submitting a tutorial nor is there a fee paid to the submitter. This site is to make available free information and is maintained through affiliate advertising.
With a functioning power supply and a fresh 9 volt battery, we will begin assembling the remainder of the circuit. It is very important to have a good 9 volt power supply as a weak supply will cause the microcontroller to act unpredictably.
Consulting the pin diagram in the data sheet, we see the VCC pin is pin number 10. VCC is the positive voltage to be applied to the microcontroller. In this case, it is 5 volts. The pin labeled AVCC is the positive reference voltage for the analog input. We will not go into the analog functions in this manual so it is not necessary to connect the pin. The ground is pin 11 labeled GND.
The reference diagram for the connections is shown in figure 8.1.
Figure 8.1
Connect a jumper between pin 11 and the horizontal ground circuit and another jumper between pin 10 and the horizontal positive voltage circuit. Notice I chose black for the ground jumper and red for the positive jumper. It is not necessary, but it helps to visualize the paths in your circuit if the jumpers are color coded.
Figure 8.2
Powering the Microcontroller
Next, we will connect the two LEDs required by our project to the microcontroller. To determine the direction of LEDs, each case has a marking identifying whether the one end is the anode or cathode end. I have found that looking for the larger element in the LED is simpler. The larger element within the LED is always the anode tied to the ground circuit. Looking closely even at a tiny 1206 surface mount packaged diode, you can still see the larger element within the diode.
Figure 8.3
Figure 8.4 contains a reference schematic for the LED connections.
Figure 8.4
The diodes and the microcontroller need to be protected from excessive current as a diode is similar to a jumper wire when the current is flowing in the correct direction. Therefore, we will start by installing 220ohm resistors. Install the first resistor to PortB.0 which is located at pin 2 according to the pin reference diagram located in the microcontroller's data sheet and is shown in figure 8.5.
Figure 8.5
Connect the second 220 ohm resistor to PortB.1 located at pin 3.
Figure 8.6
Now the LEDs need to be connected between the resistors and the 5 volt positive power circuit. Insure the anode lead is connected to the resistor and the cathode is connected to the positive circuit. I chose a red LED and a green LED to illustrate the difference between LED1 and LED0. Install the first LED.
Figure 8.7
Follow with the second LED.
Figure 8.8
LED Circuit
Adding the Switches
Connecting the switches will seem more complex than the rest of the circuit only because there are four switches needed. I have used push button MOM switches (momentary on). You can use DIP switches (dual inline pin), MOM, or whatever you have available. If the pins for the switches will not fit in your prototyping board, just solder lead wires from the switch and insert the lead wires in the correct positions. The schematic for the final portion of the circuit is shown in figure 8.9.
Figure 8.9
Insert your four switches. Space them in a manner to allow you to push the buttons without interfering with other portions of the circuit.
Figure 8.10
Insert the first two jumpers from the switches to the horizontal ground circuit as shown in figure 8.11.
Figure 8.11
Insert the two ground jumpers for the remaining two switches.
Figure 8.12
Install a jumper wire from PortB.2 (pin 3) to the open circuit next to your first switch as shown in figure 8.13.
Figure 8.13
Install a jumper from the second switch to PortB.3 (pin 4).
Figure 8.14
Install a jumper from the third switch to PortB.4 (pin 5).
Figure 8.15
Install the final jumper from the fourth switch to PortB.5.
Figure 8.16
Finally, install a 1.5Kohm resistor between each of the jumpers and the second terminal of each of the switches as shown in figure 8.17.
Figure 8.17
Testing the Circuit
When the circuit is finished, plug in the battery and start pushing the buttons. If the circuit operates as it is supposed to operate, you have successfully assembled a prototype circuit.
If the chip responds erratically to the button pushes, you may not have an appropriate power source. You can, instead of a 9 volt battery, use a 9 volt wall transformer power supply. If you use a wall transformer, you should add two 100uf radial capacitors at the circuit closest to each of the positive pins of the voltage regulator. This should prevent power spikes which may occur from the alternating current.