Notifications
Clear all

Question about Hall switches that I am planning to use as limit switches.

78 Posts
6 Users
29 Likes
3,929 Views
(@pritchs)
Member
Joined: 1 year ago
Posts: 28
Topic starter  

The project is a video camera mount that will "slide" the mount along a rail as well as pan and tilt the camera. I have my project working on a solderless beadboard, but I have run into a potential issue with the Hall switches I'm planning to use as limit switches. I hope the following makes sense!

I'm using an ESP32 if that makes any difference.

I'm using interrupts and everything seems to work well, but I have noticed that it is possible to get a Hall switch in the wrong state. I will call its normal state "high" and my interrupt is watching for a falling signal. The plan is that when the magnet gets near the sensor it changes to "low", the interrupt is triggered and the stepper motor is stopped. However, it is possible to get the switch in the "low" state when it should be "high" and when it comes near the magnet, the switch goes from low to high and no interrupt is triggered. 

I am looking for a way that I can ensure that all of the limit switches are reliably in the "high" at power-up and so will trigger their interrupt reliably. I'm sure there is a simple answer to this, but, being pretty new to all this, I haven't been able to come up with one.

Thanks in advance for any advice.


   
Inst-Tech reacted
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

Maybe switch to magnetic reed switches?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

Posted by: @pritchs

The project is a video camera mount that will "slide" the mount along a rail as well as pan and tilt the camera. I have my project working on a solderless beadboard, but I have run into a potential issue with the Hall switches I'm planning to use as limit switches. I hope the following makes sense!

I'm using an ESP32 if that makes any difference.

I'm using interrupts and everything seems to work well, but I have noticed that it is possible to get a Hall switch in the wrong state. I will call its normal state "high" and my interrupt is watching for a falling signal. The plan is that when the magnet gets near the sensor it changes to "low", the interrupt is triggered and the stepper motor is stopped. However, it is possible to get the switch in the "low" state when it should be "high" and when it comes near the magnet, the switch goes from low to high and no interrupt is triggered. 

I am looking for a way that I can ensure that all of the limit switches are reliably in the "high" at power-up and so will trigger their interrupt reliably. I'm sure there is a simple answer to this, but, being pretty new to all this, I haven't been able to come up with one.

Thanks in advance for any advice.

Hi @pritchs (Steve),  As @zander has suggested, magnetic reed switches can be used as limit switches, but they come in a variety of forms and physical shapes..Apparently your needing a normally open type( N.O. contacts) to close when the magnetic comes near. https://www.reed-sensor.com/general-reed-switch-faq/ ,The caveat is that the sensitivity of the reed switches can be 1/2" (13 mm) or so. This are also photo sensors that can do the job as well..a Diffused photoelectric sensor..see this link:

https://realpars.com/photoelectric-sensor/ for more info on the various types and how to use them..Good luck on your project.

Regards,

LouisR

 

 

LouisR


   
Ron reacted
ReplyQuote
(@pritchs)
Member
Joined: 1 year ago
Posts: 28
Topic starter  

Hi Louis,

Thanks for the reply and links. I had looked at reed switches and photoelectric sensors and had decided on the Hall's as being, potentially at least, the most reliable with maybe photoelectric being second. Reed switches, being mechanical, appear to me to be a little less reliable. All of this may not be true in reality, but is simply my understanding of the information I've seen. I grew up on a farm and from dealing with farm machinery, I always look first for what can go wrong so I can make sure it doesn't happen. 😀 Stepper motors and limit switches appear to be a good place to apply that way of thinking. 

SP


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@pritchs Hall and reed are basically equal in reliability. But if you want precision as well, the photoelectric can't be beat especially if a mask and possibly lens is used then mm accuracy is possible with not much expense.

Rereading your original post I see you are planning to use it in a slider, a simple micro switch is generally what is used for that. I have a WiFi remote pan and tilt head but without taking it apart I don't actually know how it works, but my guess would be servos.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

Posted by: @pritchs

I am looking for a way that I can ensure that all of the limit switches are reliably in the "high" at power-up and so will trigger their interrupt reliably. I'm sure there is a simple answer to this, but, being pretty new to all this, I haven't been able to come up with one.

Thanks in advance for any advice.

Have you set the starting values in your setup() routine ?

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
 

@pritchs

Posted by: @pritchs

The project is a video camera mount that will "slide" the mount along a rail as well as pan and tilt the camera. I have my project working on a solderless beadboard, but I have run into a potential issue with the Hall switches I'm planning to use as limit switches. I hope the following makes sense!

I'm using an ESP32 if that makes any difference.

I'm using interrupts and everything seems to work well, but I have noticed that it is possible to get a Hall switch in the wrong state. I will call its normal state "high" and my interrupt is watching for a falling signal. The plan is that when the magnet gets near the sensor it changes to "low", the interrupt is triggered and the stepper motor is stopped. However, it is possible to get the switch in the "low" state when it should be "high" and when it comes near the magnet, the switch goes from low to high and no interrupt is triggered. 

I am looking for a way that I can ensure that all of the limit switches are reliably in the "high" at power-up and so will trigger their interrupt reliably. I'm sure there is a simple answer to this, but, being pretty new to all this, I haven't been able to come up with one.

Thanks in advance for any advice.

Steve,

Dont forget that every time the interrupt is triggered, on low to high, the triggering pin will need to be reset to low, otherwise it will never fire again

I also like @zander 's suggestion to perhaps use a photocell.

Ron B

 

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@ronbentley1 That is news to me about having to reset the pin. Doesn't mean it's wrong but news. I thought those interrupts were pulses, always a rising and a falling as well as a changed result. In tghe ISR code you specify rising, falling, changed IIRC. Are we talking about the same thing?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@pritchs Hi Steve, I am also a photographer. Are you building the pan and tilt as well as the slider? I have a Cam Ranger for WiFi pan and tilt but plan on building some game cameras and maybe I might want tiny pan and tilt mechanisms for those as well. Can/will you share your entire project?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
 

@zander 

Ron, the devil is in the detail of the controlling code, which we haven't seen. I was just throwing out a consideration.

Interrupt management can be tricky at the best of times, but what is essential is that the real world state is always properly referenced by the supporting code and vice versa.

Regards

Ron B

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Inst-Tech and Ron reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

Posted by: @ronbentley1

@pritchs

Dont forget that every time the interrupt is triggered, on low to high, the triggering pin will need to be reset to low, otherwise it will never fire again

I'm sorry Ron, I don't understand this.

As I understand it, a Hall sensor reacts to the local magnetic field, so shouldn't it automatically change when the field is added or removed ?

Similarly, a reed switch only closes (or opens) depending on the local magnetic field so again, one would expect that the addition (or removal) of the field would cause an automatic reset in the pin.

Can you please explain the conditions where the pin would need to be reset in the sketch ?

 

Anything seems possible when you don't know what you're talking about.


   
Inst-Tech and Ron reacted
ReplyQuote
(@pritchs)
Member
Joined: 1 year ago
Posts: 28
Topic starter  

Hi Will,

If you are talking about the interrupt pin that the switch is attached to, no I haven't. I have assumed, and possibly incorrectly, that the Hall switch controls that pin and my setting it high or low at setup would have no effect on what the switch does. 

The way the switches operate is they initially hold the interrupt pin high. When a magnet is brought near them, they force the pin to a low state. When the magnet is withdrawn, the pin is returned to a high state

Here is the scenario as I see it, and feel free to correct me if I am wrong. In the following, I am equating the state of the switch and the interrupt pin as being the same. Being able to set the switch to a specific state on the fly would be helpful, but I'm not sure setting it in setup would help much. Again, I could be wrong.

==================

The project is mounted on an aluminum bar and moves back and forth powered by a stepper motor and controlled with a joystick. Limit switches prevent the project from making contact with the mounting hardware etc. at the ends of the bar.

The switch is normally high at boot.

The project moves down the bar and a magnet mounted in the end hardware comes near the switch. The switch forces the interrupt pin low, kicking off an interrupt that stops the stepper motor.

When the project reverses direction, the magnet moves away and the switch returns to a high state.

Some unforeseen event takes place that changes the switch to a low state. (Kicking off the interrupt which I would have to deal with in code.)

The project moves back toward the switch and the magnet comes near the switch, changing it to a high state which does not kick off the interrupt.

The stepper motor does not stop and crashes into the end of the slide.

==================

I'm not sure this would ever occur in normal use, but I have seen them fail to switch states when I was manually moving a magnet to test their operation. In fact, it seemed pretty easy to do but that could have been my hand-eye coordination and in the real world with everything mounted so as to maintain the correct orientation it might never happen. I just don't want it to happen and tear things up. 😀 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6972
 

@pritchs Add a micro switch as a fail safe.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ron bentley reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@pritchs 

It sounds like you're struggling way too much. If you're using a stepper motor then just install 2 regular limit switches (one at each end of the track). Use the one at the "start" to position the stepper on power-up before use and the one at the other end for collision avoidance.

They're quite stable and easier to use than having to worry about a magnet's position and orientation.

By the way, are you using a belt or leadscrew drive for the carriage ?

Anything seems possible when you don't know what you're talking about.


   
Inst-Tech and Ron reacted
ReplyQuote
ron bentley
(@ronbentley1)
Member
Joined: 2 years ago
Posts: 385
 

@will 

Not really, my comment was born out of my experience with switches triggering interrupts.

As I said to zander's post, the devil is in the detail of the design (controlling code).

I think the use of a photocell might provide a simpler and more reliable solution here?

Ron B

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Inst-Tech reacted
ReplyQuote
Page 1 / 6