I have 64 hall effect sensors (magnetic field sensors) (DRV5023AJQLPG) connected to an Arduino MEGA 2560. For that, I use 48 digital pins and 16 analog pins as digital input pins. The program in the Arduino continuously reads out those 64 digital input pins (in a for-loop) and sends out a serial byte, to a laptop via a usb cable, whenever one of those input pins changes between LOW and HIGH. I also use the ATmega2560’s internal pullup resistors to prevent irregular readouts of the input pins when the sensor is not giving a 0v output (i.e. when it isn’t measuring a strong enough magnetic field).
Everything is working fine when I only physically connect up to 16 of the sensors. The laptop then only receives bytes that correctly tell when a sensor measures a state-change.
However, when I start connecting more of those 64 sensors, then the laptop starts receiving irregular streams of bytes, erroneously suggesting that all the connected sensors measure changing magnetic fields (HIGH and LOW readouts).
I can think of two reasons why these irregular readouts occur: 1. Either, the ATmeag2560’s internal pullup resistors arent working as I think they should. 2. Or, the arduino board and >16 hall effect sensors combined are pulling to much current.
Pullup resistors not working? When testing with only 16 sensors connected, it is a stable, properly working setup. When I explicitly don’t use the pullup resistors in the program then the setup does start behaving irregular, also with just 16 sensors. So the internal pullup resistors seem to be properly activated by the program.
Arduino + 64 sensors draw to much current? Besides powering the Arduino board and sensors via the usb cable (providing 500mA), I’ve also tried external power sources that provide 1 or 2A. I’ve also powered the Arduino board via an external 5v, +1A voltage regulator, bypassing the Arduino’s onboard voltage regulator. This all doesn’t seem to make a difference in the system’s irregular behaviour. When measuring those setup’s current usage (with amperage meter) it didn’t go above 250mA.
Calculating the combined current usage (using datasheet info), I came to this:
- sensor operating current: 2,7 mA
- sensor output current when in ‘active’ state: 0,25 mA
- TOTAL current of 64 sensors (3mA*64=) 192 mA
- Arduino MEGA current (approx) 150 mA
- TOTAL current of 64 sensors + Arduino MEGA: **342 mA**
So, both the calculated and measured current usage seem within the range of what can be handled by mentioned power sources.
I’m kinda stuck now. Can anyone suggest anything that might cause this problem? Or point to incorrect thinking of me? Thanks for any responses.
'Schematic' (only showing first 8 sensors connected. The ArduinoMEGA is connected to a computer via a usb cable with disabled power line):
Top-side: the hall effect sensors and Vcc an GND rails:
Bottom-side: ArduinoMEGA + the 64 red sensor output lines to the input pins:
Below is the Arduino code:
/*
Arduino to Pd protocol
Placing or removing a chess piece sends only one byte.
There’s no other serial data being communicated.
event: byte value:
placing a chess piece on a square: 0-63
removing a chess piece from a square: 64-127
ArduinoMEGA pin to byte value mapping:
byte pin
0 6
1 7
2 8
3 9
…
46 52
47 53
48 A0 (analog 0)
49 A1
50 A2
…
62 A14
63 A15
*/
byte prevSquares[64]; // array that holds previous readouts
byte i; // variable used in for-loops
byte sensorValue; // variable temp storing of digitalread
void setup() {
Serial.begin(9600);
for (i = 0; i < 64 ; i++) {
pinMode(i+6, INPUT_PULLUP); // activate pullup resistor
}
for (i = 0; i < 64 ; i++) {
prevSquares[i] = digitalRead(i+6);
}
}
void loop() {
for (i = 0; i < 64 ; i++) {
sensorValue = digitalRead(i+6);
if (sensorValue != prevSquares[i]) {
// chess piece was placed or removed from square
if (sensorValue == 0) {
// chess piece was placed
// send serial byte (0-63):
Serial.write(i);
}
else {
// chess piece was removed
// send serial byte (64-127):
Serial.write(i + 64);
}
//update prevSquares array:
prevSquares[i] = sensorValue;
}
}
}