There are many tutorials on the web that teach you how to program various circuits with Micro Controller Units (MCU) such as the Arduino (www.arduino.cc), Texas Instruments MSP430 (www.ti.com/launchpad) and Microchip PIC Microcontrollers (www.microchip.com). However if you want to design your own circuit, here’s a short guide as to how you can make some basic circuits for your MCU.’
1. Power Supply and Programming Circuit
One of the first things that you need to do is connect the power supply and the programming circuit to your MCU. If you are using a MCU that comes with a programming board such as the Arduino and the Texas Launchpad you can skip this step. If not, I recommend that you read the datasheet for your MCU before connecting any wires from the MCU to a power supply or to a computer. There are many tutorials and YouTube videos online that will help you make these connections.
You will also need to install a programming software and system drivers for your programmer. You can find information regarding this from the place where you obtained your programming board or circuit.
2. Buttons and switches
Buttons and Switches are digital devices that can only send either a logical high or low to your MCU. It is possible to connect your button directly to your MCU input pin and one of the power rails. When the button is pressed the Logical High value will be recorded on the MCU input, however when the button is not pressed the input pin is floating around. This means that neither a High voltage or a Low voltage is given to the input pin. The value recorded by the MCU at this instance will be altered by natural factors like electrical interference.
To overcome this problem push buttons and switches are wired with either a pull up or a pull down resistor as shown in the image below. These resistors are used to connect the input of the MCU to either the High or the Low voltage when the button is not pressed. The value of the resistor should be relatively large (10kΩ). This is similar to a potential divider where the resistor representing the button swaps between infinite resistance and zero resistance.
Many MCU’s have a built in pull up or pull down resistor which can be enabled when programming the pin configuration of the MCU. When this is to be selected, the push button or switch can be wired directly from the main power supply to the pin.
3. Sensors
Most sensors are similar to similar to a variable resistor. They change their internal resistance depending on what they sense. For example the resistance of a Light Dependant Resistors (LDR) reduces when light falls on the it.
Sensors such as LDR, photo resistors, temperature sensors, and other similar input devices are connected as follows which is similar to the wiring to the button
In this situation a potential divider is formed between the fixed resistor and the sensor. The voltage as a result of the potential divider is read by your MCU. Unlike a button, the sensor is a analogue device. It should be connected to a analogue pin on your MCU to receive the complete range of values.
It is possible to connect the sensor to a digital pin. If you do this you will only receive a High or a Low input depending on the state of the sensor. I advice you to to refer to the datasheet of the MCU to find out how much voltage is required by a digital pin to register as a High or Low voltage.
4. Light Emitting Diodes (LED)
LED’s are one of the basic output devices. They are diodes which allow current to flow in only one direction. Before connecting an LED you must know how much voltage is needed by the LED for optimal glow and the rated current.
LED’s are connected via a resistor as shown in the figure below. The resistor that needs to be added in series with LED is to limit the current flowing through the LED. This is needed because of the LED’s I-V curve. According to the I-V curve, after a certain voltage drop the LED will allow almost infinite current to flow through it. This will draw all the current from your MCU and cause the batteries to drain much quickly. It may also blow out your LED.
The resistance of the resistor to be added can be calculated as follows.
- Reduce the voltage drop over the LED (Ex. 2.2V) from the supply voltage (Ex. 5V) to find the voltage drop over the Resistor (5 – 2.2 = 2.8V)
- Using Ohms law (V = IR) calculate how much resistance is needed to draw a current less than the rated current of the LED (Ex. 20mA). Remember than in a series circuit the same current flows through all the connected components (R = (2.8/0.02)Ω).
7 segment displays are connected similar to LEDs. They have an input pin which requires a positive voltage and 8 output pins which are connected to the cathode of each the LEDs on the segments.
Bi-colour LEDs are also similar. It contains three pins where one of the pins are the power supply and the other two are the cathodes for each colour.
Multiple LED’s can be connected in many ways: Two LEDs can be connected as follows where one LED will light up and the other one will switch off depending on the output of the MCU pin
If you need to control many LEDs with only a few pins on your MCU please read about Multiplexing and Charlieplexing. I will explain these circuits on another part of this tutorial.
On a Final Note
This is only the first part of the Basic Micro controller unit connections tutorial. Other parts will uploaded soon
If you are someone who is always working with electronic circuits, I have found a very useful Mobile app named “ElectroDroid” by lero . There is a free and pro version. You can use it to look up resistor colour codes and SMD values, calculate theoretical values for different circuits and many more.
If you thing this post needs more improvement please let me know by commenting below. If you think this post is useful, bookmark it or share it with someone who might need it.
Thank you for reading.