0

Hi I am controlling a 1960's Lego train trough a motor controller that uses the PWM of the Raspberry pi3 and I have 4 IR sensors that are externally powered with a 3.3V constant power supply, I used python to program the sensors and motor controller, and when I control the motor controller with the raspberry pi the input pins THAT I HAVE SET TO INPUT give out 1V and as input in the code it gives me a constant HI input read and I clean the GPIO pins with the command GPIO.cleanup() after everything.

The code that I am using:

## import RPi.GPIO

import RPi.GPIO as GPIO


## set numbering to board

GPIO.setmode(GPIO.BOARD)


## setup GPIO pins

GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.IN)
GPIO.setup(13, GPIO.IN)
GPIO.setup(15, GPIO.IN)
GPIO.setup(37, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
GPIO.setup(40, GPIO.OUT)


## setting up Pulse Width Module

p = GPIO.PWM(37, 100)
p.start(0)

while True:

    ## updating sensors

    sensor1 = GPIO.input(11)
    sensor2 = GPIO.input(12)
    sensor3 = GPIO.input(13)
    sensor4 = GPIO.input(15)

    p.ChangeDutyCycle(85)

    if sensor1 == 0:
        print('1')

    if sensor2 == 0:
        print('2')

    if sensor3 == 0:
        print('3')

    if sensor4 == 0:
        print('4')

How can I fix it? and why is it doing that?

  • If those are analog sensors that is a problem. – goldilocks Apr 17 '18 at 18:01
  • but they have worked before, but I will check. – Hein Apr 18 '18 at 4:14
  • But would that effect the raspberry pi to output 1v ? – Hein Apr 18 '18 at 4:22
  • If the pin is set as an input, its state is generally determined by what it is attached to. If it is not attached to anything (e.g., if you read a bare input with a voltmeter, which is basically attaching a digital input to an analog input), it has high resistance and an indeterminate voltage, aka a high-Z state <- As per the second paragraph this is the third state in three state logic, the others being low and high. Outputs are either low or high, inputs that are not pulled up or down are high-Z. – goldilocks Apr 18 '18 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.