Tuesday, April 24, 2012

Circuit to understand working of and gate

In this post we will look at a small circuit using arduino which can be used to understand the working of the basic logic gates.

We will require

3 Leds
3 Resistors 220 Ohms or higher (Value picked radomly)
Arduino uno board
Breadboard and wires.
2 buttons or switches.


Connect the anode of 2 leds(led1,led2) to the +5v and cathode to one end of the button.
Connect the second end of the buttons to ground through the resistor.
From the end of the button which is connected to the resistor connect one of the switch to digital I/O pin2 and one to digial I/O pin 3.
Connect the anode of third led(led3) to digital I/O pin 7 and the cathode to ground through the resistor.
The bread board as well as the schema view of the connections are shown in the figure below.


The two switches connected to pins 2 and 3 through the leds act as inputs and the third led connected to pin 7 act as the output.

Woking as And gate :
In an AND gate the output is high only when both the inputs are high.
Note: Truth table along with animation can be found in the post "Animation of an and gate"
Thus the led3 should light up only when both switches are closed that is both led1 and led2 are glowing.



In the main loop there is an if condition which ands the two inputs of switch1 and switch2 thus making the circuit work like an and gate.

Thus only when both switch1 and switch2 are closed the led3 three will light up. If only one of the two switches is close the led3 does not light up.

The same circuit can be extended with any number of inputs by just modifying the if condition in the program.

No comments:

Post a Comment

Follow by Email