Wrong digitalread

Hi :slight_smile:
I use an Arduino mega 2560 and I use it to read digital high (sensor 5v) and LOW 0V
but I ran in to a huge problem, when I use port 30< then it return high even if the port receives 0 volt. When I try to make the following test, read on ex. 52, the it return 1 event i nothning i connected. if I do the same on port 30 i return 0 which i should but when I touch og connect a resistor the i return 1. how can that be? shouldn't it be possible to read HIGH an LOW on every digital port?
best regard
Nikolaj

Disconnected inputs will read randomly HIGH or LOW. If you want a pin to read as HIGH when 'not connected to anything' you should use a pull-up resistor, either external or internal (pinMode(x, INPUT_PULLUP);). If you want a pin to read as LOW when 'not connected to anything' you should use an external pull-down resistor.