I am fairly new to electronics and am having some issues with a project I am trying to build that requires a 3x3 matrix of digital reed switches triggered by magnets.
I think I am seeing some issues with the circuit. The output is not as expected. When there are no magnets on the board, the code featured below prints:
1 1 1
1 1 1
1 1 1
And when a magnet is detected on top of a sensor, the state of it turns to 0. However, there are some instances where placing a magnet next to a sensor either doesn't trigger the change from 1 to 0, OR it may trigger others in the same row to turn to 0 even if there is no magnet present. I assume from that that the issue is not in the code, but with the circuit I have built. I may be missing some components like resistors or diodes somewhere maybe?
Here is a schematic and my current code for reference:
I am still seeing the same issues as before after trying the code you posted here.
The code seems to work totally fine if I have one magnet present in the grid, the corresponding grid point will change from 1 to 0 just fine.
However, once I put more than 1 magnet in the grid at a time, the readings start to get wonky and grids that don't have a magnet present change from 1 to 0. Any idea why I might be seeing this? If the hardware aspect is fine, maybe it's the magnets?
For correct operation with more than 1 magnet at the same time, the pin control is different. I haven't used the 'Keyapd' library but according to that https://playground.arduino.cc/Code/Keypad/
it supports reading more than 1 button at a time and as @ruilviana you recommend it will probably be easiest for you.
Hey, thanks for the guidance here. I'll need to tweak the code a bit from the MultiKey example the library provides, but at a high level this will probably work. However, the current 3x3 board I'm building is actually prototype for a 8x8 grid that will have up to 16 magnetic pieces active at a time. The Keypad library looks to only support up to 10 active keys at a time.
Do you know if I can have 2 custom keyboards operating at once to get all 16 key states? Or do you know of a library or solution that can support up to 16 keys at once?
EDIT:
After further testing, it seems that this program gives me a similar issue as the other ones. Sometimes if I place a magnet on grid id 0 for example, the output suggests that the entire row or column is activated.
Looks like a chessboard. Have you thought about connecting reed relays without using pin multiplexing? However, with an 8x8 board, you will need 64 pins. In this case, you can use 8 serial registers (type 8 parallel in's to 1 serial out, such as 74HC166 or 74HC165) connected in cascade and control all 8 with about only 4 pins. You will need to add a pull up or pull down resistor to the every reed relays at the inputs of the registers.
Thanks. I was recommended this once before, but wasn't sure how to approach it due to my limited understanding of electronics and how to properly connect this kind of circuit. Are there any resources you can suggest for this? I'm also not too sure about how to program for this either... Would they be plugged into digital outputs that can output a message like 00000001 to indicate that the last input in the row has a magnet present
We were all beginners. The important thing is that you want to learn.
Start with the 'shiftIn' and 'shiftOut' commands. The difference in these commands is that 'shiftOut' is for more outputs and is most often used with 74HC595 and 'shiftIn' is for multiple inputs (as for your case) and is most often used with 74HC165.
Yes, the data will be something like that, in the presence of a magnet it will 0 or 1 , depending on whether you use pullup or pulldown resistors.
Circling back around after various tests, just wanted to reach out and say thanks so much for your help and guidance! I was able to finish up a prototype with 16 inputs and am on to building the full 64-input chessboard grid.
Thanks! The circuit seems to be working with the full 8x8 grid for the most part. I think now I am seeing some issues that may have something to do with the strength of the magnets or some issue of the sort. Sometimes if I place a magnetic piece next to a square that already has a piece on it, there's no response from the board indicating that the square has a magnet present. It is only when I remove the adjacent piece that the board it finally registers that a magnet is present. Each sensor is placed about a 1.5 inches away from each other and 5-7mm below a layer of hollowed out wood (the chessboard is about 1 inch thick, I hollowed out holes to place the sensors). I'm using two of these magnets embedded into the bottoms of the pieces: https://www.amazon.com/gp/product/B07B3SDRCP/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&th=1
I have no experience with magnets. Still, I have a guess. Maybe it depends on how the poles of each magnet are oriented? For example, in a certain orientation, the magnetic field weakens due to the influence of the neighboring magnet. You can try when the magnets have equally oriented and counter-oriented magnetic poles. As I said, I have no experience with magnets and I can't think of anything else.