Magnetic Sensor Grid
In this intructable, I will show you how to make a sensor matrix using magnetic sensors and my learning process along the way. We will be using NeoPixel's programmable LEDs to change colors when the magnetic sensors detects a magnet. We will also make a 3D printed case and cover to hold the grid and LEDs in place. I made a 4x4 grid, but it is very simple to scale up the size.
One issue with this design is that the arduino nano doesn't handle the amount of power in this project very well, so you might see some glitching lights when it detects a magnet.
Supplies
To make a 4x4 grid, the supplies needed are listed below:
Prototype
First I created a small scale version of the grid using cardboard. In order for the matrix to know where each sensor is, they are interconnected by columns and rows. Having the reed switches set diaganoly helps give enough space for each row and column to solder. It's important that the separate metal wires aren't touching so I kept part of the rubber around the each wire to reduce the risk of short circuiting.
I connected the grid and the LED strip to an arduino and you can see that when one of the reed switches detects a magnet, the LED its tied to and the LEDs next to it change color.
TinkerCAD and 3D Printing
To make the case for the grid, I decided to use Tinkercad. I find it an intuitive resource that anyone can use to get started in 3D modeling. Its important that there is a small lip on the inside of the case for the grid to hang onto. After that comes the the top of the case, which also has a small lip near the edge of it so it can fit snug into the case. When I finished the modeling, I set it up in Prusa Slicer to 3D print.
Some problems I had early on was making the inside wide enough to hold together all the wires inside, so I had to reprint it a few times to get it right.
Dimensions for my case:
4.5 in x 4.5 in x 1.5 in Outside
3.8 in x 3.8 in Inside
4.2 in x 4.2 in Inner Lip
PCB Board
For a 4in. x 4in. grid I cut my PCB Board into a smaller size. I used plier cutters to split them apart. The process is the same as the prototype but larger in scale. Just make sure that each reed switch is soldered properly to the connecting wires, other wise they will easily break off and become a headache later. It's fine if this side of the board looks ugly because it will be facing inside of the case.
Soldering the LEDs
This was the most time consuming part of the project. Mostly due to the fact that each NeoPixel had to be individually soldered to fit in the 4 x 4 grid. I also set up the Neopixels in a parallel circuit to be more power efficient. It is also important that the data in (Din) part is the first thing that is soldered. The data out (Do) part should lead into another LED's data in portion. Keep that pattern repeating and all the NeoPixels will be connected and functioning.
But in order for NeoPixels to light up, the power, the ground, and the data pin all need to be connected to the arduino. This makes it a little difficult to test if your circuit works in a parallel circuit due to the fact that the data pins need to be soldered in a series circuit.
To make the parallel work, I used one common wire for the power and one common wire for the ground. To connect it to the LEDs on the other side of the board, I soldered a smaller peice of metal wire to the common wire and threaded it through to the other side and soldered it to the LED. Make sure there is something like tape covering the wires to avoid short circuiting.
After doing that, you can connect all the wires to you arduino nano. I used the smallest wires I could find so they could all fit into the box.
NOTE: This is my second build for this project. I had to remake the grid because I accidentally put the first magnetic switch and the first NeoPixel on opposite sides of the grid. This lead to a megnetic switch detecting the magnet and changing the color of a completely different LED.
The circuit diagram was taken by andrei.erdei in this project. His project is bigger but the idea is exactly the same.
The Code
You can download my code as a frame work
I used the FastLED library to communicate with the Neopixels and I used The Keypad Library to create the matrix needed for the magnetic switches.
If you want to know how to install libraries on your arduino you can look at a guide here
I currently have it set up so when a reed switch detects a magnet, it changes the color of the corresponding LED next to it along with each LEDs directly next to it. I mentioned earlier that the Arduino Nano I'm using doesn't handle the amount of power required very well, so I encourage you to change the code to something smaller in scale to see if that helps.