0

I am trying to use GPIO pin to get input from the sensonr, after connecting the sensor I noticed I have a lot of noise ( fluctuating signals between 0 and one). After further troubleshooting I noticed some abnoral phonamena. My Raspberry Pi input pin shows constant "1" input when nothing is connected to the pin, however as soon as I connec a jumper wire to the pin ( currently using GPIO pin 27, but I test this with other pins like GPIO 20 and GPIO21 with the same result) input signal keeps fluctuating between 0 and 1.) I also moved the Raspberry pi to different location in case I was getting this signal from nearby cable and it didnt help.

Here is the code that I am using with different output,if I remove the jumper wire I get the first plot ( which means there is no noise), and as soon as I connect the jumper wire I get the second plot. Anyone has any idea why this is happening? Is my raspberry pi damaged? I have done this before and didnt have this issue.

from datetime import datetime
import matplotlib.pyplot as pyplot
import RPi.GPIO as GPIO

RECEIVED_SIGNAL = [[], []]  #[[time of reading], [signal reading]]
MAX_DURATION = 15
RECEIVE_PIN = 27


if __name__ == '__main__':
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(RECEIVE_PIN, GPIO.IN)
    cumulative_time = 0
    beginning_time = datetime.now()
    print ('**Started recording**')
    while cumulative_time < MAX_DURATION:
        time_delta = datetime.now() - beginning_time
        RECEIVED_SIGNAL[0].append(time_delta)
        print(GPIO.input(RECEIVE_PIN))
        RECEIVED_SIGNAL[1].append(GPIO.input(RECEIVE_PIN))
        cumulative_time = time_delta.seconds
    print ('**Ended recording**')
    print (len(RECEIVED_SIGNAL[0]), 'samples recorded')
    GPIO.cleanup()

    print ('**Processing results**')
    for i in range(len(RECEIVED_SIGNAL[0])):
        RECEIVED_SIGNAL[0][i] = RECEIVED_SIGNAL[0][i].seconds + RECEIVED_SIGNAL[0][i].microseconds/1000000.0

    print ('**Plotting results**')
    pyplot.plot(RECEIVED_SIGNAL[0], RECEIVED_SIGNAL[1])
    pyplot.axis([0, MAX_DURATION, -1, 2])
    pyplot.show()

Constant signla wihtout jumper wire Noisy signal after connecting jumper wire

2

Until a voltage is applied to a GPIO it will float between high and low.

https://www.mouser.com/blog/dont-leave-your-pins-floating

3
  • 2
    Yes, and to emphasize what "float" means to a new user, it does not mean that the voltage will be zero and it does not mean that the voltage will always alternate between a logic 1 and logic 0. Aug 14 at 17:15
  • Thank you so much for the quick answer, I read about floating while ago and totally forgot about it. Now I am going to see what is the best way to remove noise for RF433 receiver as I dont think I can use pull up/down resistor on that. But at least I dont have the floating issue when nothing is connected to the pin. Aug 14 at 18:10
  • You will get noise on a RF433 receiver until there is a signal present. Not much you can do about that. I use a glitch filter with pigpio. See abyz.me.uk/rpi/pigpio/examples.html#Python__433_py
    – joan
    Aug 14 at 21:01

Your Answer

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

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