Raspberry Pi Lab

NOT Logic

by on Jan.07, 2014, under Code, Digital Logic, Electronics

not-symbol-transparentSo when building electronic circuits, there may be times when you want the circuit to behave opposite of the input it received.  For this we need a logical NOT gate.

A NOT gate is a simple concept.  Whatever the input, the output is the opposite.

To demonstrate this concept, I’ve created a circuit in which the LED is always on unless it receives a HIGH signal from the GPIO.  Here is the circuit I used…

not-gateThe LED gets power directly from the 5v rail.  R1 is the limiter that prevents the LED from being blown out by too much voltage.  The LED stays lit because the transistor at Q1 does not have an input signal.  Therefore Q1 is “open.”  When the GPIO is changed to HIGH, the transistor closes and allows the flow of electrocity to by-pass the LED straight to ground.

The R2 resistor could be a variety of sizes.  In fact, you could, probably get by without it at all.  The 2N222A transistor I used is rated for a typical 40v and 600 mA.

The Python code on the RPi is equally simple.  All we need to do is set the #23 pin to HIGH and the LED goes off.  If you want it to blink, add a pause and then set the #23 pin to low and pause again.  Repeat.

Here’s the code…

#!/usr/bin/env python

# The circuit that goes along with this program is
# wired in such a way that the LED is always on unless
# a HIGH signal is received from the Rpi.
 
import RPi.GPIO as GPIO
 
DEBUG = 1
 
GPIO.setmode(GPIO.BCM)
RED_LED = 23
GPIO.setup(RED_LED, GPIO.OUT)
 
if DEBUG:
   print "LED turned OFF"
while True:
   GPIO.output(RED_LED, True)

 

:, , ,
1 comment for this entry:
  1. r00t

    It was suggested by a Facebook reader that I should look into seperating the NOT logic circuit from the LED driver circuit. That is, use one transister to drive the logic gate and a seperate transistor to drive the LED.

    I’m working on figuring that out out and will post a new article when I get it working.

    Comments are always welcome. I’m learning this as we go. So if you have something to add, please chime in.

Leave a Reply

You must be logged in to post a comment.

Archives

All entries, chronologically...

Our Partners

Please take a minute to visit our partners

Looking for something?

Search the Site

If you can't find what you are looking for, please leave a comment somewhere, subscribe to our feed and hopefully your question will be answered shortly, so please visit again!