Understanding Gates – OR Gate
Lab: Basics of Data and Program Circuitry
Video Runtime: 10:33
In software, the OR operator in a conditional expression is true when either decision is true. In circuitry, it works the same. When either input is on, then the OR gate turns on.
Your key takeaways are:
- OR works the same in circuitry as it does in code
- OR (shown as
||
in code) works in “parallel” - If both input states are “false,” then the circuit computes to “false”
- Else, the circuit computes to “true”
Study Notes
An OR Gate consists of inputs wired in parallel, meaning that the output will be “on” when one or both of the inputs are in an “on” state. Logically you can use pseudocode to visualize the gate’s process:
if ( this OR that ) then do something
Using the if
statement, if either or both of the states on either side of the OR
operator are true, then the if
evaluates to true and thethen
portion of the block will be executed.
Wired in Parallel
In circuitry, the OR gate’s input switches are wired in parallel. Let’s look at a simulator:
Relay Logic
The relay logic in the image below shows you two separate relay circuits which are wired in parallel through the contacts within the relay. The switches are simulating the input signal feeding into the relay’s coil.
When the input is “on”, the relay coil is energized, which turns the relay to an “on” state. The contact within the relay is pulled into the “on” state” via magnetism.
When either inputs are “on”, then respective relay is “on.” This means power can flow from the voltage source through the “on” relay’s contact, to the output, and then to ground. The light will then turn “on.”
Let’s picture this in pseudocode:
if ( input1 OR input2 ) then turn on the light
If input1 or input2 are “true”, the if
evaluates to true which fires whatever is within the then
code block.
Truth tables
Switch 1 | Switch 2 | Light bulb |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 1 |
The condensed truth table:
OR | 0 | 1 |
---|---|---|
0 | 0 | 1 |
1 | 1 | 1 |
Relating circuit to code
To help you understand the OR Gate circuit, let’s look at it in relationship to code. In the following PHP code block, the ||
is the same as an OR Gate.
<?php | |
function maybe_show_top_bar( $is_ok_to_show ) { | |
if ( is_page() || $is_ok_to_show ) { | |
showTopbar(); | |
} | |
} |
Just like the two switches controlling the state of the same light bulb, if either of the two conditions in the code is true, it will cause the function to execute.
You get WET when you swim. Stay DRY when you code.
Episodes
Total Lab Runtime: 01:53:22
- 1 Lab Introductionfree 02:20
- 2 Understanding Switch Logicfree 13:36
- 3 Introduction to Pseudocode and Truth Tablesfree 16:28
- 4 Understanding Gates – NOT Gatefree 10:10
- 5 Understanding Gates – AND Gatefree 15:07
- 6 Understanding Gates - OR Gatefree 10:33
- 7 Understanding Gates – XOR Gatefree 10:42
- 8 Understanding Gates – NAND Gatefree 07:10
- 9 Understanding Gates – NOR Gatefree 06:34
- 10 Basics of Memory Circuit – S-R Latchfree 04:41
- 11 Basics of the Adder Circuitfree 16:01