In this lesson, you will learn how to use the Arduino microcontroller to manipulate a digital output device, in this case an LED. Each digital output device has two possible states, HIGH and LOW, usually corresponding to whether the device is on (HIGH) or off (LOW). The HIGH and LOW states are represented by voltages. The Arduino uses 5 volts to represent HIGH and 0 volts to represent LOW. So to turn on an LED, we instruct the Arduino to send a "HIGH" (or 5V) signal to it. To turn it off, the Arduino sends a "LOW" (or 0V) signal to the LED. To have your Arduino output voltage (i.e., send the voltage signals) to an LED, you need to know which Arduino pin the LED is connected to, and then set up that pin for output. We do this using the function pinMode( PIN#, MODE), where MODE is either OUTPUT or INPUT and PIN# is the number of the pin being used (13, in this example): Once the pinMode is set (and the LED connected properly to that pin), we can instruct the Arduino to turn on the LED by sending a HIGH (5V) signal to that pin, or turn it off by sending a LOW (0V) signal to the pin. To do this, we "write" the signal to the pin by using the function digitalWrite(PIN#, STATE), where STATE is either HIGH or LOW: The pre-placed code blocks in the Workspace show how to put it all together, and the picture on the left below shows how the Barobo RGB LED module should be connected to the Arduino for this activity. To enlarge the picture, click the "Large Grid" button at the bottom left in the buttons below the grid: In particular, connect the LED module to pins 11, 12, 13, and GND on the Arduino as shown, so that the pin labeled "R" on the RGB LED module (the red LED) is plugged into pin 13 on the Arduino, the "G" pin (green LED) is in pin 12, the "B" pin (blue LED) is in pin 11, and the "-" pin is in the GND, or ground, pin.
|
Use the Arduino to turn on the red LED in the Barobo RGB LED module, wait two seconds, then turn it off. |
Use the Step button to step through the code blocks one at a time to get a better understanding of how it works. |
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
|
|||||||||||
|
|||||||||||