Wednesday, April 25, 2012

Circuit to understand the working of a xnor gate

The same circuit that was built in the post "Circuit to understand working of and gate"can be made to work as a xnor gate too, just by modifying the program.

The xnor gate is high only when all of its inputs are the same which is just the negation of an xor gate. Here is the modified program to implement an xnor gate, which is just adding a negation to the if condition in the program for xor gate.



Note: The truth table and animation of xnor gate can be found in the post "Animation of a xnor gate"

Now the led3 should turn on only when both the inputs are high and should remain off when he inputs differ.

Circuit to understand working of a "xor" gate

The same circuit that was built in the post "Circuit to understand working of and gate"can be made to work as a xor gate too, just by modifying the program.

The xor gate is high only when one of its inputs is high but not both. Here is the modified program to implement an xor gate using the same circuit.



Note: The truth table and animation of xor gate can be found in the post "XOR gate animation"

Now the led3 should turn on only when one of the inputs are high and should remain off if both inputs are low or both inputs are high.

Circuit to understand working of a "nor" gate

The same circuit that was built in the post "Circuit to understand working of and gate"can be made to work as a nor gate too, just by modifying the program.

The nor gate is negation of the or gate, hence we just need to add a negation to the "if" condition in the previous program of or gate in the post Circuit to understand working of and gate Here is the modified program:



Note: The truth table and animation of nor gate can be found in the post "NOR gate animation"

Now the led3 should turn on only when both the inputs are low and should remain off in all other conditions.

Circuit to understand working of a "nand" gate

The same circuit that was built in the post "Circuit to understand working of and gate"can be made to work as a nand gate too, just by modifying the program.

The nand gate is negation of the and gate, hence we just need to add a negation to the "if" condition in the previous program of and gate. Here is the modified program:



Note: The truth table and animation of nand gate can be found in the post "NAND gate animation"

Now the led3 should turn off only when both the inputs are high and should remain on in all other conditions.

Tuesday, April 24, 2012

Circuit to understand working of an "or" gate

The same circuit that was built in the post "Circuit to understand working of and gate"can be made to work as an or gate too, just by modifying the program.

Here is the modified program:



The only change is in the "if" condition where the inputs are being "ored" in this program.

Note: The truth table and animation of or gate can be found in the post "animation of an or gate"

Now the led3 should turn on, when either of the switches, switch1 or switch2 are turned on and also when both the switches are turned on.

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.


Circuit:

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.



Working:

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.

Program:

and:



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.

Thursday, April 19, 2012

Serial Leds using arduino

In this post we will see how we can use arduino to make a set of leds glow in a serial fashion that is one after the other.

We will use

  • 4 leds
  • 1 push button
  • 1 1kohm resistor(Value picked randomly)
  • Arduino uno board.



Connect the anodes of the 4 leds to 4 digital I/O pins on the board say pin numbers 2,3,4 and 5.

Connect the one side of the push button to digital I/O pin 7 .

Connect the other side of the switch to ground through the 1K resistor.

Connect the cathodes of all the leds also the the ground, you can add a 220 ohm resistor while connecting to the ground.

The bread board and the schema connections are shown in the figures below.

In the program :

Pins 2,3,4, and 5 will be set as outputs

Pin 7 will be set as input.

The push button is used to control the order in which the leds glow i.e. 1,2,3,4 or 4,3,2,1.

We write two functions,direction1 and direction2, to light up the leds. One for each direction/order.

In both the functions we start by writing a HIGH to the first pin, pin 2 or pin 5, and wait for one second before writing a low.

Next we do the same to the pin next to it i.e. pin 3 or 4 .

We repeat the steps for all the four pins and again start from the first one.

In the loop, we keep checking for the input from push button.

On receiving a HIGH from the push button, the HIGH is noted by the chaging the value of variable alt.

Using the value of alt we change the direction of leds by calling the relevant function, i.e. if alt his HIGH led would glow in one direction else in the other direction.

serial_leds:



Load the above program into arduino and connect the power. We should see the leds lighting up one after the other, to change the direction press and hold the push button atleast for 5 seconds as the control comes back to the loop only after finshing the function it is executing.

Tuesday, April 17, 2012

Alternating between a buzzer and an led using a push button and arduino

In this post we will control a led and buzzer using a push button and aroudino uno, turning them on alternately i.e. on one push of the button led is turned on buzzer is turned off and in the next push the led is turned off and buzzer is turned on.

Here are the circuit connections in the breadboard view and the schema view.


The led is connected to digital I/O pin 7 which will be set as digital output

The buzzer is connected to digital I/O pin 3 which will also be set as digital output

The digital I/O pin 2 acts as the input and is connected to the switch.

Each time the push button is pressed it sends a high on the pin 2 which on being read as high, pin 3(buzzer) is set to the value of the variable alt, which starts with a HIGH, and the pin 7(led) is set to negation of alt( !alt ) which will be LOW.

In the next iteration alt starts with LOW and the opposite happens, led gets a HIGH, the buzzer gets a low.

Thus the output switches between the led and buzzer on each push of the button.

Here is the program for the same.

buzzer_led:



Compile and load the above program into the aroudino board and on each press of the button the buzzer and led should turn on alternately.

Monday, April 16, 2012

Making push button work as a switch using arduino

In this post we will look into how we can user a push button like a switch, i.e. it turns on a circuit on one push and turns off the circuit in the next using an arudino uno board.

The circuit that we will use is the same one used in "Controlling a buzzer with a push button" but the program will be modified.

In this program we will have boolean variable,alt,which will be used to control the output at pin 3. Let us say we set the variable "alt" to HIGH intially.

Each time the push button is pressed the variable is used the set the output at digital I/O pin 3 :

Then the value of the variable is negated :

Thus value of alt changes to LOW.

In the iteration when the push button gets pressed again the negated value is applied to the pin 3, changing the value at pin 3 from HIGH to LOW.

The same steps are repeated again and again.

The output at pin3 thus will keep switching between the HIGH and LOW states at each press of the push button, just like the operation of a normal switch. Here is the program for same In the above program, there is a delay after the digitalWrite becuase otherwise the processor will loop through the interations at a very fast rate and we will not be able to view the desired operation.

Also note the delay if of 1 second so if the pushbutton is pressed more than once with in a second the output behaviour can not be garunteed.


Friday, April 13, 2012

Controlling a buzzer with a push button using arduino

Here is a small example of how we can control a buzzer using a push button using the arduino uno. This is just an small extension to the example of button available at ardunio site http://arduino.cc/it/Tutorial/Button.

We connect one side of the push button to 5V by connecting one of the two legs to the 5V pin on the board.

The other side of the push button is connected to the ground using a 1K ohm resistor.

The same end of the resistor which connected to ground is also connected to the digital I/O pin 2

The digital I/O pin 3 is connected to the positive leg of the buzzer and the negative leg is connected to the ground.

The following breadboard and schematic figures show the connections.

Program:

The pin2 acts a digital input.

The pin3 acts as digital output.

Whenever the push button gets pressed a high is sent to pin2 which is read as as input and whenever a high is read on pin2 a high is sent on pin3 which turns the buzzer on. Hence making the buzzer beep whenever the push button is pressed.

Thursday, April 12, 2012

4 legged Push button: Working

4 legged push buttons are quite often used in circuits of embedded systems.

But some times , especially for beginners, it gets confusing to understand how should the button be connected and which leg is meant for which connection.

Here is small animation that tries to make the internals a little clear.

A 4 legged push button connected on breadboard can be viewed as shown below.

The legs 1 and 2 are shorted internally in the button and so are the legs 3 and 4.



So when the button is pressed, we are internally shorting all the 4 legs together, meaning, when the button is pressed all the 4 legs are connected to each other and when the button is not pressed, the legs 1 and 2 are connected to each other and 3 and 4 are connected to each other. (Please note the numbering is hypothetical and are not mentioned on the switches).

If it still gets confusing, we can use a multimeter to find out which legs are shorted internally.

Keep the multimeter in the mode where it beeps when shorted and just connect one pin of the multimeter to one of the legs and touch the other pin to all the other 3 legs. On touching which ever other pin the multimeter beeps that is the pair which are shorted and so is the other pair.

Hope using a push button becomes much more easier now .

Wednesday, April 11, 2012

Animation of xnor gate

An XNOR gate is a one whose output is high only when all its inputs are the same, i.e. either all the inputs are low or all the inputs are high. In all other cases, when the inputs don't match, the output remains low. It can be looked at as a combination of a XOR and NOT gate.
It is represented by the symbol
The following truth table and animation depict the operation of the XNOR gate.

Monday, April 9, 2012

Animation of XOR gate

An XOR gate, which stands for exclusive or, is a gate whose output is high only when one of its inputs is high but not all are high. In the conditions of all the inputs being high or low the output is also low. It is represented using the symbol
The following truth table and he animation depict the operation of an XOR gate.

NAND gate animation

A NAND gate can be viewed as a combination of an and and not gate. Thus the output is low only when all the inputs are high else the output remains high for all other input conditions.
The NAND gate is represented using the symbol.
The following truth table and the animation depict the operation of NAND gate.

nor gate animation

A NOR gate is a gate that acts like a combination of an or gate a not gate
The output of the NOR gate is high only when all its inputs are low, in all other conditions the output of the NOR gate remains low.

The NOR gate is represented by the symbol:
The following truth table and the animation depict the working of a NOR gate.

Animation of Not gate

NOT gate is a basic gate whose output is always the inverse of the input, that is if the input is "1" the output would be "0" and if input is "1" output would be "0". There is only one input to the note gate and is represented using the following symbol.



The following truth table and the animation depict the operation of a not gate.



Sunday, April 8, 2012

Animation of an or gate

An or gate is a basic gate whose output goes high when any one of its input is high, and the output is low only when all the inputs are low.

The or gate is represented using the symbol :

The following truth table along with the animation depicts the working of a two input or gate.


Friday, April 6, 2012

Animation of an and gate

An and gate is a basic logic gate whose output goes high only when all its inputs are high and in no other condition.

An and gate is represented using the symbol



The following truth table and animation depict the operation of a two input and gate.


Follow by Email