Introduction: The OR Gate With Arduino

Picture of The OR Gate With Arduino

/*Arduino_OR_Logic_Gate.
Actually the circuit connection is the same as the previous AND...just a small change and thats all.
In 3 states there is an output to the LED ...try it and confirm the truth table below.

|A|B|Y|
|0|0|0|
|1|0|1|
|0|1|1|
|1|1|1|
*/

int buttonPin1 = 2;
int buttonPin2 = 3;
int LEDred = 8;
int buttonStatus1 = 0;
int buttonStatus2 = 0;

void setup() {
pinMode(LEDred, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop(){
buttonStatus1 = digitalRead(buttonPin1);
buttonStatus2 = digitalRead(buttonPin2);

// check if the either the first button is HIGH, OR the second button is HIGH, then turn on the LED
// else turn the LED off

if (buttonStatus1 == HIGH || buttonStatus2 == HIGH )
{ digitalWrite(LEDred, HIGH);
} else { digitalWrite(LEDred, LOW); }
}

Comments

About This Instructable

182views

1favorite

License:

Bio: An Electrical Engineering Teacher in Athens Greece. Most of these small projects here, are constructed for enhancing the learning of the use of Arduino as ... More »
More by PanosA6:Toggle switch with Relay using ArduinoUniversal Logic Gates Implementer with ArduinoMost simplest toggle switch with Arduino
Add instructable to: