Arduino I/O Demystified

The Arduino interface board has a single row of connectors or pins on each side of the board. These are used mostly for inputs, outputs, and power. Figure 5-1 shows a simple illustration of the Arduino Uno interface board. Your board might be a little different.

images

Figure 5-1. Arduino illustration

As shown in Figure 5-1 and printed on the interface board, there are 14 pins on one side of the board marked Digital that are numbered from 0 to 13. Of these, two are used for serial communications through USB for programming, debugging, and other forms of communication. These pins are numbered 0 and 1, and are marked RX <- and TX -> respectively. Anything connected to these pins may affect or be affected by serial communications. Pin 13 has a resistor and LED (marked L) connected to it on board so that it can be used for testing, diagnostics, and other forms of blinking. Six of the digital pins can also act as analog outputs using pulse width modulation (PWM). These are pins 3, 5, 6, 9, 10, and 11 on the Arduino Uno and are marked on the interface board with the tilde symbol (~). On the other side of the board are six additional I/O pins labeled as Analog In, numbering A0 through A5. These pins are connected to the microcontroller’s analog to digital convertor (ADC) for interpreting incoming analog signals, although they can also be used as additional digital inputs and outputs.

Each I/O pin operates on a range of 0 to +5 VDC, or volts direct current. A range of 0 to +2V is said to be off or LOW while anything over about +3V is said to be on or HIGH. Generally, a circuit connected to one of the Arduino I/O pins needs to have a high or positive side connected to power (+5 VDC), some form of load, and a low or negative side connected to ground (GND). How a circuit is physically connected to the Arduino or in which direction determines how the I/O pin can be used and which side of the circuit is connected to the Arduino. Each pin can either source, or provide a positive biased current, or sink, to provide a negative biased current, up to 40 milliamps each. Typically, most Arduino circuits are designed so that they source current, as shown in Figure 5-2, although there are times where sinking current is necessary, as shown in Figure 5-3.

images

Figure 5-2. An example of sourcing current

images

Figure 5-3. An example of sinking current

In comparing these two schematics, you should notice there is a difference in whether or not one side of the drawing is connected to +5 VDC or to GND and that this connection affects the direction of the LED. LEDs and a few other components are polarized, meaning that they only work in one direction, or with the correct polarity. By sourcing current, the Arduino I/O pin acts as source for +5 volts, providing a high-side positive supply of current. On the other hand, by sinking current, the Arduino I/O pin acts like a connection to ground, providing a low-side or negative current.

While each pin can provide about 40 milliamps of current, this is just about enough juice for one or two LEDs to work on each pin safely. Drawing more than 40 milliamps or exceeding +5v on any pin may either damage the microcontroller or the connected device. To safeguard against this happening, it is generally a good idea to connect output pins to other devices using one of two components, the first of which is a current limiting resistor used to drop or limit the current needed by the device. Playing it safe, a 1 kilohm resistor is a common value for current limiting for general applications, although we can get away with less resistance, as with our earlier LED schematics where we used a 220 ohm resistor to get more brightness out of the LED without damaging anything. Alternatively, we could use transistors or other switching components to switch larger current loads, like motors, solenoids, or strings of LEDs that exceed the maximum 40 milliamps of current and/or operate at voltages greater than +5v.

images Note While it is possible to damage the microcontroller from connecting things wrong, it is a surprisingly tough little chip and is fairly hard to completely ruin. More often than not, it will be okay after removing power to it and disconnecting the offending circuit. Sometimes, however, it is possible to end up with a dead pin that will no longer work, but only in catastrophic situations will the entire chip release the magic smoke.

It is important to remember that any time our circuit has a connection to ground that this must be common to the Arduino and every connected device or things will behave very erratically. What this means is that the ground pins of the circuit must somehow connect to the ground pins on the microcontroller. Likewise, any time we use a pin for an input that is not actually connected to anything, it is called a floating pin and we will get seemingly random and strange results as the pin picks up electrical interference and noise from the surrounding environment or from nearby circuits.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.185.180