1

If I setup a pin's output to HIGH or LOW, would current flow through it or not?

In this example, when I set output to HIGH then the LED turns off. I expected the other way around.

The python code I have written is

import RPi.GPIO as GPIO
import time

try:
    outputPins = [11,12,15,16,18,22,3,5,24]
    GPIO.setmode(GPIO.BOARD)

    for pin in outputPins:
        print('setting output mode for pin',pin)
        GPIO.setup(pin,GPIO.OUT)

    while True:
        for pin in outputPins:
            #print('turning ON pin ',pin)
            GPIO.output(pin,GPIO.LOW) <-- I expected that HIGH will turn the LED ON
            time.sleep(0.1)
            #print('turning OFF pin ',pin)
            GPIO.output(pin,GPIO.HIGH) <-- I expected low to turn LED off
            time.sleep(0.1)

    #print('out of loop')
    #time.sleep(10)
    #GPIO.cleanup()
except KeyboardInterrupt:
    GPIO.cleanup()

enter image description here

Reason I expected LOW to turn off LED is because in this diagram, LOW turns off LED

enter image description here

The code is

import time

ledPin = 11    # define ledPin

def setup():
    GPIO.setmode(GPIO.BOARD)       # use PHYSICAL GPIO Numbering
    GPIO.setup(ledPin, GPIO.OUT)   # set the ledPin to OUTPUT mode
    GPIO.output(ledPin, GPIO.LOW)  # make ledPin output LOW level 
    print ('using pin%d'%ledPin)

def loop():
    while True:
        GPIO.output(ledPin, GPIO.HIGH)  # make ledPin output HIGH level to turn on led - Here HIGH TURNS ON LED
        print ('led turned on >>>')     # print information on terminal
        time.sleep(1)                   # Wait for 3 second
        GPIO.output(ledPin, GPIO.LOW)   # make ledPin output LOW level to turn off led
        print ('led turned off <<<')
        time.sleep(1)                   # Wait for 3 second

def destroy():
    GPIO.cleanup()                      # Release all GPIO

What am I missing? Has it got to do something with serial or parallel connections? Why does the first circuit doesn't use GND?

I can see differences in the circuits (eg. 1st one is connect to 3V while second one is not). But I can't figure how internally with RPI, things are getting controlled

0

1 Answer 1

3

Setting an output pin HIGH outputs ~3.3V; LOW ~0V.

Both have limited current sourcing/sinking capability ~16mA.

What happens (and what current flows) depends on the external connections.

In general current potentially will flow out of a HIGH pin and into a LOW pin.


Incidentally, the way you have wired 3.3V — resistor — LED — GPIO is the way most engineers would connect the circuit.
This requires the GPIO to be LOW to turn the LED ON.
This seems to confuse many beginners.

3
  • Thanks. That is how I understood as well. I suppose the difference between the two circuits is that in the 1st one, the power (3.3v) is already provided to positive end of the LED. The negative end (connected to GPIO pins) is low (by default?) and thus circuit completes and led is on low value of GPIO. When the GPIO is made high (3.3v?), the circuit breaks as both ends have high voltage now (3.3v) & led switches off. In the 2nd diagram, the positive end is connected to GPIO and negative to 'gnd'. There is no current till the GPIO is made high. Thus high in 2nd diagram switches on LED. Correct? Commented Aug 21, 2021 at 14:52
  • "When the GPIO is made high (3.3v?), the circuit breaks as both ends have high voltage now" -> Yes.
    – goldilocks
    Commented Aug 21, 2021 at 15:04
  • @ManuChadha NOTHING "breaks" current will only flow if there is a potential difference. As I stated in Comments you need to learn some basic circuit theory.
    – Milliways
    Commented Aug 21, 2021 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.