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()