0% found this document useful (0 votes)
131 views

Arduino Projects Experiments Part4

The document describes building an OR logic gate circuit using an Arduino microcontroller, a pushbutton switch, and a photocell. The circuit causes a green LED to turn on when either input is true - when the pushbutton is pressed or light levels go low, simulating darkness. The circuit diagram and Arduino code are provided. The circuit can be used as a simple automatic night light that turns on when it gets dark or the button is pressed.

Uploaded by

denydi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Arduino Projects Experiments Part4

The document describes building an OR logic gate circuit using an Arduino microcontroller, a pushbutton switch, and a photocell. The circuit causes a green LED to turn on when either input is true - when the pushbutton is pressed or light levels go low, simulating darkness. The circuit diagram and Arduino code are provided. The circuit can be used as a simple automatic night light that turns on when it gets dark or the button is pressed.

Uploaded by

denydi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Figure 6-10.

The Arduino AND Logic Gate circuit schematic diagram

60

Make: Basic Arduino Projects

Figure 7-4. The OR Logic Gate circuit symbol

Figure 7-5. The OR Logic Gate Truth Table

The Arduino OR Logic Gate


You can build a digital computer OR Logic Gate circuit using the Arduino microcontroller and a few electronic components from the Ultimate Microcontroller
Pack. The green LED turns on when either the pushbutton switch OR the photocell
is TRUE. You can easily build the logic circuit using the Fritzing wiring diagram shown
in Figure 7-6. You can build this basic digital computer circuit on MakerShield, as
shown in Figure 7-1.
Did you notice that the Fritzing wiring diagram looks like the AND Logic Gate circuit
of Chapter 6? Thats because it is. The cool thing about using an Arduino (or any
other computer, really) is that often you can use the same physical circuit and make
it do different things, simply by changing the computer code. In this case, either
pressing the pushbutton switch OR placing your hand over the photocell will turn
on the green LED.
This cool gadget can become an automatic LED night light. If your home loses power
because of an electrical storm or the area substation is not operating, this device
can function as an automatic light source. The photocell is electrically wired to detect
darkness. When night falls (or when the power fails), the signal at pin D4 becomes
TRUE, and the Arduino microcontroller turns on the green LED, as in Figure 7-7. Or,
if you just want to turn the light on when it isnt dark out, you can just hit the pushbutton switch. This makes the signal at pin D3 TRUE, which again causes the Arduino
microcontroller to turn on the green LED.

64

Make: Basic Arduino Projects

Figure 7-6. The Arduino OR Logic Gate Fritzing wiring diagram

Chapter 7: The OR Logic Gate

65

Example 7-1. The Arduino OR Logic Gate sketch


/*
The Arduino OR Logic Gate
Turns on an LED connected to digital
pin 7, when pressing either a pushbutton switch or covering a photocell
attached to pins 3 and 4.
27 Jan 2013
Revised 4 September 2013
by Don Wilcher

*/
// 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;

// the number of the LED pin

// variables will change:


int AStatus = 0;
// variable for reading the A pushbutton status
int BStatus = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(Cout, OUTPUT);
// initialize the pushbutton pins as inputs:
pinMode(B, INPUT);
pinMode(A, INPUT);
}
void loop(){
// read the state of the pushbutton value:
AStatus = digitalRead(A);
BStatus = digitalRead(B);
// check if the pushbuttons are pressed
// if it is, the buttonStatus is HIGH:
if (AStatus == HIGH || BStatus ==HIGH) {
// turn LED on:
digitalWrite(Cout, HIGH);
}
else {
// turn LED off:
digitalWrite(Cout, LOW);
}
}

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

Chapter 7: The OR Logic Gate

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.

Figure 7-8. The Arduino OR Logic Gate block diagram

Figure 7-9. The Arduino OR Logic Gate circuit schematic diagram

68

Make: Basic Arduino Projects

Figure 8-4. The Up-Down Sensor Fritzing diagram

74

Make: Basic Arduino Projects

Figure 8-5. The Up-Down Sensor circuit schematic diagram

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;

// variable for tilt control switch status

void setup() {

Chapter 8: Tilt Flasher

75

Figure 8-6. The Up-Down Sensor built on a MakerShield

Chapter 8: Tilt Flasher 77

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.

Figure 9-2. A typical RGB LED with pinout names

80 Make: Basic Arduino Projects

You might also like