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?