Arduino Projects Experiments Part4
Arduino Projects Experiments Part4
60
64
65
*/
// constants won't change; they're used here to
// set pin numbers:
int B = 3;
// the number of the B pushbutton pin
int A = 4;
// the number of the A pushbutton pin
const int Cout =
7;
After uploading the Arduino OR Logic Gate sketch to the Arduino microcontroller,
the green LED is off. Pressing the pushbutton switch or placing your hand over the
67
photocell will turn on the green LED. To completely test the Arduino OR Logic Gates
operation, remember to use the TT shown in Figure 7-5.
The block diagram in Figure 7-8 shows the building blocks and the electrical signal
flow for the Arduino OR Logic Gate. Circuit schematic diagrams are used by electrical
engineers to quickly build cool electronic devices. The equivalent circuit schematic
diagram for the Arduino OR Logic Gate is shown in Figure 7-9.
68
74
You can build the Up-Down Sensor on a MakerShield, as shown in Figure 8-6. The
MakerShield allows you to carry it in a shirt pocket, computer bag, or purse for
convenience. Example 8-1 can be uploaded to the Arduino after entering the code
into the IDEs text editor screen.
Example 8-1. Up-Down Sensor sketch
/*
Up-Down Sensor with Flashing LEDs
Flashes green and red LEDs at pin 8 when the tilt control
switch attached to pin 3 is tilted. The green LED wired to
pin 8 turns turns solid when no tilt condition is detected.
05 Feb 2013
Don Wilcher
*/
// constants won't change; they're used here to
// set pin numbers:
const int tiltPin = 3;
// the number of the tilt control switch pin
const int ledPin = 8;
// the number of the LED pin
// variables will change:
int tiltState = 0;
void setup() {
75
Circuit Theory
Figure 9-2 shows a typical RGB LED with the wiring pinout names. There are three
pins, one for each color, and one common pin for positive attachment to a power
supply. Like the ordinary LED, the positive and negative pins are wired to the positive
and negative points of a DC (direct current) circuit. To illustrate, Figure 9-3 shows
three SPST (single pole, single throw) switches wired to control red, green, and blue
LEDs. Closing the contacts on SPST switch SW1 will allow the batterys (VBattery)
current to flow through the red LED, turning it on. The other switches (SW2 and SW3)
will turn on the green and blue LEDs as well. The individual colors can be lit sequentially or at random using the three SPST switches. The Arduino microcontroller
will provide a sequential switching order, allowing the red, green, and blue LEDs to
turn on accordingly.