I'm new to Arduino projects, but i do have a programming background. However I do not have a good understanding of electrical components. Anyway, I have a tic tac toe board Arduino project. Each of the 9 possible spots on the board has an A3144 hall sensor that can sense the presence of a magnetic X. When the player places an X, the board responds with its own lit up O. This continues back and forth until either the player or the Arduino wins. I had this working well a couple weeks ago when I was using a regular Arduino Uno.
But I have tried to move it to a (faux) Nano and have had lots of issues. When using an Uno, i used the "DigitalWrite(, HIGH)" to trigger the internal pull-up on all 9 sensors. But with the Nano, I get unexpected and inconsistent results using the same code. Some sensors work, but others (for no apparent reason) do not. The only thing i can imagine is that trying to do "DigitalWrite(, HIGH)" on 9 different inputs is more than the Nano can handle.
So, to fix that, i have tried to use a 10 K Ohm resistor on a few of the sensors so that i don't have to use the internal Pull-up function. Since I'm not using a breadboard anymore, I've tried to solder the resistor between the sensor to input pin and 5v/VIN leg. Unfortunately, i couldn't find a good example of how to do this when soldering (as opposed to using a breadboard), so I did what made sense to me. But no matter what, these sensors with resistors are NOT registering HIGH (with no magnet present). Could anyone look at my wiring of the sensor and tell me if this is NOT a valid way to integrate a resistor with a hall sensor?
I'm using a bit of a PCB board to hold each sensor. The holes have metal around each hole, but they're not connected to one another. The hall sensor is added to one side of the PCB board. Its legs are put through 3 holes of the board. The hall sensor is bent over to be fairly flat so that side can be attached to my tic tac toe box. On the other side, the legs are soldered with power, ground, and input pin wires from left to right when looking at the side of the A3144 that has writing on it. The 10K resistor is soldered between the outer legs/wires. See attached images. Am i missing something?
Any help would be greatly appreciated! I've spent far too long on this to give up!!
Yes, the Soldering is covered with the shrink wrap. Attached are images of soldered connections. This one is particularly ugly. But i don't believe they contaminate each other (solder from power doesn't touch solder area from ground).
I am not exactly sure how to test with an Ohm meter. I will have to look that up, or if you have any quick suggestions on how and what exactly to test on a hall sensor, i'd appreciate it!
The Relevant Code is below. The problem occurs instantly when the program runs. The hall sensors with the resistors are not reading HIGH as they should. So it immediately sees 3 LOW readings and causes the program to go into error mode since only one value can be changed at a time. The sensors with their internal pull-up turned on (DigitalWrite(HIGH), all register HIGH when the program runs.
const int hall11 = 6; // THIS ONE HAS RESISTOR
const int hall12 = 4; // THIS ONE HAS RESISTOR
const int hall13 = 3;
const int hall21 = 9;
const int hall22 = 8; // THIS ONE HAS RESISTOR
const int hall23 = 7;
const int hall31 = 12;
const int hall32 = 11;
const int hall33 = 10;
const int BLANK = 0;
const int X = 1;
const int O = 2;
int gameCnt;
int gameLoc[3][3];
int gameState[3][3];
void setup() {
for (int i=0;i<3; i++) {
for (int j=0;j<3;j++) {
gameState*[j] = BLANK;*
}*
}*
gameLoc[0][0] = hall11; // THIS ONE HAS RESISTOR*
gameLoc[0][1] = hall12; // THIS ONE HAS RESISTOR*
gameLoc[0][2] = hall13;*
gameLoc[1][0] = hall21;*
gameLoc[1][1] = hall22; // THIS ONE HAS RESISTOR*
gameLoc[1][2] = hall23;*
gameLoc[2][0] = hall31;*
gameLoc[2][1] = hall32;*
gameLoc[2][2] = hall33;*
Serial.begin(9600); *
Serial.println("starting");*
for (int i=0;i<3;i++) {*
for (int j=0;j<3;j++) {*
// DECLARES ALL SENSOR LOCATIONS AS INPUT*
_ pinMode(gameLoc*[j], INPUT);_
_ if ((i==1 && j==1) || (i==0 && j==0 ) || (i==0 && j==1)) {_
_ // EXCLUDE PINS 4, 6, AND 8 FROM WRITING HIGH SINCE THEY HAVE RESISTORS ATTACHED*_ * Serial.print("not writing high to "); * _ Serial.println(gameLoc*[j]); } else { // WRITE HIGH TO REST OF PIN INPUTS FOR INTERNAL PULL UP* digitalWrite(gameLoc*[j], HIGH); }*_
* }* * }* } // END SETUP void loop() { * int cnt = 0;* * int foundJ =-1;* * int foundI =-1;*
* for (int i=0;i<3;i++) {* * for (int j=0;j<3;j++) {* * int tmp = HIGH;* _ tmp = digitalRead(gameLoc*[j]); Serial.print("read "); Serial.println(gameLoc[j]); *_
_ if (tmp == LOW && gameState*[j] == BLANK) { Serial.println("found low here - they put X on blank spot"); cnt++; foundJ=j; foundI=i; } else if (tmp == HIGH && gameState[j] == X) { // ERROR STATE* * Serial.println("found high here - they removed X from board - invalid move"); errorState(); } else if (tmp == LOW && gameState[j] == O) { // ERROR STATE* * Serial.println("found low here - they put X over O - invalid move"); errorState(); } } } *_
* if (cnt>1) {* * //ERROR STATE -- THEY ADDED MORE THAN 1 X AT A TIME - invalid move* * //THIS IS WHERE MY PROGRAM IS GOING INTO ERROR MODE BECAUSE OF THE SENSOR WITH RESISTORS* * errorState();* * } else if (cnt==1) {*
First thing is to correct the posting of your code. You did not use the code tags correctly, and the code been modified by the posting. and <\code> are not proper code tags.
But I have tried to move it to a (faux) Nano and have had lots of issues. When using an Uno, i used the "DigitalWrite(, HIGH)" to trigger the internal pull-up on all 9 sensors. But with the Nano, I get unexpected and inconsistent results using the same code. Some sensors work, but others (for no apparent reason) do not. The only thing i can imagine is that trying to do "DigitalWrite(, HIGH)" on 9 different inputs is more than the Nano can handle.
This is not correct. I don't know what trouble shooting you did at this point, but I would go back to this point and sort it out.
It is preferred to use pinMode(pin, INPUT_PULLUP) to engage the internal pullup resistors. It is one command instead of two, and you can not make any mistakes.