Triangulating position with three hall sensors

Hello, I'm trying to create a probe for a CNC machine using hall effect sensors. I would like to create a circuit which is a simple digital output when something moves in any direction. These probes usually have three pins on which the probe sits, and when something disturbs the probe, at least one pin is disconnected. It's pretty easy to build them with simple continuity of the pins but, due to how I want to deploy and undeploy the sensor I would like to make it with hall sensors.

Another desire is to have the probe not require any adjustments/trimming. Also, if I can built this without using the arduino (which is already controlling motors and such) that would be great, but I might have to build a circuit and finish it off with some code, not sure.

So, ... I know I don't want latching switches (that's what I got from Sparkfun and it doesn't work for this application, going to get something else). Then there are "switches" which just turn on when a magnet is close enough, I guess you can trim a resistor to determine where the trigger occurs. But then there are linear ones, which is what I think i need. These output an analog voltage determined by how close is a magnet. So...

There are three hall sensors, and when the probe is pushed, at least one of them will move, and due to the triangular geometry, two of the sensors will have their voltage go down, while one will have its voltage go up. So here's my question, The starting voltage for each of the sensors will not be exactly the same, due to positional errors. So i think i want to measure differential voltage between pairs of sensors.

Now what? Maybe it's not so bad to just put this in the loop on a little ATtiny and compare the differences to the differences a few milliseconds before to detect the change, but again, if you can think of a way to get a digital signal out - something changed! that would be terrific.

I should say that the title of this isn't exactly right. Don't really need to know the distance or position exactly, just that it changed.

Shall I reply to myself twice :slight_smile:

So one more thing. Since these are analog sensors, I guess there's no way around at least one sensitivity threshold, which maybe would be set using a resistor somewhere. But, bonus if it didn't need that.

From your description so far, what I think you are planning is to have 3 Hall sensors at the corners of an equilateral triangle, and a magnet in the middle of the triangle. The Hall sensors are on the probe and the magnet is stationary. At rest, the Hall sensors see equal magnetic fields, assuming that one of the poles of the magnet is facing up towards the space between the 3 sensors. If the probe is moved in the X and/or Y direction, the sensors will no longer see equal fields. If the probe is moved in the Z direction (away from the magnet), the sensors will all see a lower field. Is this correct?

While you could probably handle differences between the sensors using analog electronics and some potentiometers, I think it will be easier using a microcontroller. You can use a 2-step calibration procedure. In the first step, position the probe well away from the magnet, and store the 3 analog input readings in EEPROM. Call these values Z1, Z2, Z3. In the second step, put the probe in position above the magnet, and store the readings in EEPROM again. Call these readings S1, S2, S3. Subsequently, for any 3 readings R1 R2 R3:

Relative amplitude A = ((R1 + R2 + R3) - (Z1 + Z2 + Z3)) / ((S1 + S2 + S3) - (Z1 + Z2 + Z3)

Sensor 1 imbalance = (R1 - Z1) - (A * (S1 - Z1))

and similarly for sensor 2 and 3 imbalance. You just have to decide how low an amplitude or how high an imbalance means you have moved away too far from the reference point.

Somehow this makes me think of the start of a very useful/unique type of sensing application. I will follow this hoping for more details of the application and hardware/software solutions. dc42 seems to layout a possible solution overview pretty well.

I've played with several hall sensors over the last five years or so, and yes they come in many (sometimes confusion) flavors. I played with the simple digital switch sensors that required a active pull-up on it's signal output pin. It would switch low (conducting) when a field of a certain guass strength, no matter if north or south fields sensed. I've read of switch types that only set if a certain strength and magnetic polarity is senses and only reset if a certain strength and of the reverse magnetic polarity is later sensed, thus it acts as a latching magnetic switch sensor. And of course I've played with the simple analog output types and they worked fine. I suspect for maximum accuracy or sensitivity one might want to have a temperature sensor near the end of the probe and it's value in software used to compensate for any calibration errors due to temperature variation, which I'm sure there is some.

Lefty

Hey dc, what you described is exactly the plan. Actually I think I could get away with only 2 sensors, where, when they change from the quiescent state, either they change relatively positively, negatively or not at all. I know this is the Arduino forum so sorry for asking how to avoid using one :slight_smile: But, I have to run wires to the sensor either way, and have some 5v pins available, so why not just go ahead and use an attiny or something.

So, ... I guess the task is to select one. ideally, it would be one which doesn't strictly need any external pieces, crystal, resistors, caps, etc, other than the sensors, and which has at least 3 analog pins. I'll probably put an LED or two on it in dead bug style. Don't need particularly high frequency I wouldn't think. One caveat is I'll need an automotive version, since the operating temp might be in the 70C range.

What about this one? ATtiny45

Is that enough memory to run typical Arduino operating system? Would there be limitations on the number of commands I could run?

Is that enough memory to run typical Arduino operating system?

There is no operating system on an arduino unless you choose to use one of the real time OS that are about. Personally I would rather chew my own leg off than use an OS on the arduino.

OK, I misspoke :slight_smile: Not sure what I'm referring to exactly , but I've seen a few projects - such as a famous tutorial from MIT where a tiny is used and not all Arduino functions are supported (?) I assumed that was because the "OS" - bootloader? was a stripped down version to fit in the smaller available space on these smaller ICs. On reading again, it seems that there are attiny libraries for the Arduino programming environment, which don't have full support for typical Arduino commands. I guess that's not an OS, but maybe helper functions downloaded to the AVR so it can run sketches in the Arduino style?

but maybe helper functions downloaded to the AVR so it can run sketches in the Arduino style?

No it is the fact that the ATtiny has less hardware peripherals built into the chip than the ATmega328 used in the Uno. It is the functions that make use of these hardware peripherals that can not be implemented in the ATtiny. In some limited cases it might be possible to side step these hardware peripherals and do a software implementation of the hardware but it will not be as good an implementation as having the hardware.
For example the lack of a UART means that you can't use serial communications unless you use software serial, with all the limitations that implies.

OK, so I guess I need to figure out which additional hardware I might need if any. The attinys have flash and eeprom (less of it of course). If, for example, as was suggested, I need to store the original values of the hall sensor readings so that they can later be compared, the code will need to be able to write to eeprom or progmem. The functions listed as supported in the MIT example doesn't include anything for writing or reading from flash. Does that mean it won't work?

You can't write to flash with any code that runs outside the boot loader segment but you can read it from anywhere.
I would have thought that writing to EEPROM would work though.

hi guys,

I am working on a project that will have a similarity to this one.
May I ask for an update on this project status?
Did it get working?
Was accurate positional information able to be derived from the 3 hall sensors?

Gavin786