Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 1 month ago.
DigitalIn displaying a 1 when the pin is not connected to anything
Hi,
I am trying to write the code for a tilt switch, using the DigitalIn function. I have connected 3.3V to the tilt switch and the other pin to pin A0 on my Nucleo F401RE microcontroller. For some reason i am reading random 1's even when A0 is connected to nothing. To set up the pin i used:
DigitalIn capsize_input (A0);
then in my code i used:
if (capsize_input.read() ==1) {
meas = capsize_input.read();
printf ("Kayak has capsized, digital reading: %i\r\n", meas);
}
Is there something i am doing wrong, i am reading mostly zeros, but the occasional 1 at random, which is frustrating as i only want it to read a one when the tilt switch enables the 3.3v to flow to the pin.
Thanks Lewis