Hardware Reference
In-Depth Information
Continued from previous page.
Serial.write(inByte+1);
}
// Meanwhile, keep blinking the LED.
// after a half of a second, turn the LED on:
if (millis() - blinkTimer >= blinkInterval / 2) {
digitalWrite(LEDPin, HIGH); // turn the LED on pin 13 on
}
// after a half a second, turn the LED off and reset the timer:
if (millis() - blinkTimer >= blinkInterval) {
digitalWrite(LEDPin, LOW); // turn the LED off
blinkTimer = millis(); // reset the timer
}
}
To send bytes from the computer to the micro-
controller module, first compile and upload this
program. Then click the Serial Monitor icon (the
rightmost icon on the toolbar). The screen will change to
look like Figure 1-14. Set the serial rate to 9600 baud.
Digital input
A digital input to a microcontroller is nothing more than a
switch. The switch is connected to voltage and to a digital
input pin of the microcontroller. A high-value resistor (10
kilohms is good) connects the input pin to ground. This is
called a pull-down resistor . Other electronics tutorials may
connect the switch to ground and the resistor to voltage. In
that case, you'd call the resistor a pull-up resistor . Pull-up
and pull-down resistors provide a reference to power
(pull-up) and ground (pull-down) for digital input pins.
When a switch is wired as shown in Figure 1-16, closing the
switch sets the input pin high. Wired the other way, closing
the switch sets the input pin low.
Type any letter in the text entry box and press Enter or
click Send. The module will respond with the next letter in
sequence. For every character you type, the module adds
one to that character's ASCII value, and sends back the
result.
Connecting Components to the
Module
The Arduino and Wiring modules don't have many sockets
for connections other than the I/O pins, so you'll need to
keep a solderless breadboard handy to build subcircuits
for your sensors and actuators (output devices). Figure 1-15
shows a standard setup for connections between the two.
Analog input
The circuit in Figure 1-17 is called a voltage divider . The
variable resistor and the fixed resistor divide the voltage
between them. The ratio of the resistors' values deter-
mines the voltage at this connection. If you connect the
analog-to-digital converter of a microcontroller to this
point, you'll see a changing voltage as the variable resistor
changes. You can use any kind of variable resistor: pho-
tocells, thermistors, force-sensing resistors, flex-sensing
resistors, and more.
Basic Circuits
There are two basic circuits that you'll use a lot in this
topic: digital input and analog input. If you're familiar with
microcontroller development, you're already familiar with
them. Any time you need to read a sensor value, you can
start with one of these. Even if you're using a custom
sensor in your final object, you can use these circuits as
placeholders, just to see any changing sensor values.
The potentiometer , shown in Figure 1-18, is a special
type of variable resistor. It's a fixed resistor with a wiper
that slides along its conductive surface. The resistance
changes between the wiper and both ends of the resistor
as you move the wiper. Basically, a potentiometer ( pot
for short) is two variable resistors in one package. If you
connect the ends to voltage and ground, you can read a
changing voltage at the wiper.
 
Search WWH ::




Custom Search