Genuino Mega- Some pins couldn't be used

Hi all,

I am using an ethernet shield together with a genuino mega 2560 to read sensor outputs so i set all pins as input. When block sensor i will get a “0” and unblock sensor i will get a “1” in return.

I was learnt that pin 10, 50, 51 and 52 cannot be used as they are specially for ethernet connection. However, i found that there are more pins cannot be used for sensor output reading like pin 4, 13, 20, 21, 53, A0 and A1. The values i get from those pins are always fixed and never change no matter i block or unblock my sensor.

Could anyone please help? Thank you. (sketch is attached)

Read_Sensor_Trial2.ino (10.2 KB)

Most of those are covered by the Ethernet Shield description:
“Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won’t work.”

20 and 21 are the I2C pins. The Ethernet Shield doesn’t use them.

A0 and A1 aren’t connected on the official Ethernet Shield.

13 is the onboard LED. Perhaps the Ethernet Library uses that for signaling of some kind? It should work fine if you set it as an input and put a signal on it.

Perhaps your sketch has an error. If you show it, someone might be able to suggest a fix.

Hi John,

I am glad that you are willing to read through my post and questions. I have attached my code.

p/s: i have replaced pin 4 and pin 53 with pin 63 and 64, yet pin 4, 13, 20, 21, A0 and A1 is still not working.

Read_Sensor_Trial2.ino (10.2 KB)

The code looks OK to me. Are you saying that the inputs are not responding when you connect them to Ground (0) or +5V (1)?

You can reduce your code size quite a bit by using the array you have set up:

            for (int sensor = 0; sensor < 50; sensor++) {
              client.print("Sensor ");
              client.print(sensor + 1);
              client.print(" is ");

Hi John,

I am connecting my sensor signals into those pins. Please kindly have a look on my attached diagram.
When i block my sensor, i should read a “0” and when unlock sensor i will read a “1”. All other pins working fine except those mentioned pins. Those pins give me a “1” no matter i block or unblock my sensor. This is abnormal.

Sensor Wiring DiagramV1.1.pdf (667 KB)

Have you tried removing the Ethernet Shield to see if, perhaps, it is using those pins for something? Just use Serial to see if those few pins work without the shield in place. That could point to some undocumented connections.

If those pins STILL don’t work with the shield off you could try connecting them directly to +5V or Ground to see if the input pins are faulty. If they go LOW for Ground and HIGH for +5V then there is a problem with your sensors. Perhaps the pull-up resistor is too strong?

Hi John,

Thanks for your suggestions and advice. Really appreciate your help.