go_away

Author Topic: Help required for arduino based RPM sensor using hall effect and magnets  (Read 14320 times)

0 Members and 1 Guest are viewing this topic.

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Hi all, I am trying to make a RPM sensor for my bot. I am using Arduino and this hall effect sensor that i got:
http://www.freetronics.com/products/hall-effect-magnetic-and-proximity-sensor-module
I have made a small bench setup to prove the concept. See attached snap. I am using 8 equidistant magnets around the perifery of the sprocket. Here is the arduino program:

const int ledPin = 13;
volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;

void rpm_fun()
 {
      rpmcount++;
      digitalWrite(ledPin, HIGH);
      delay(50);
      digitalWrite(ledPin, LOW);
 }
 
void setup() {
  pinMode(ledPin, OUTPUT);     
  Serial.begin(9600); 
  attachInterrupt(0, rpm_fun, FALLING); 
}

void loop(){
 
   if(rpmcount>=5) {
      rpm=(60000*rpmcount)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      //Serial.println(rpmcount,DEC);
      rpmcount = 0;
      Serial.println(rpm,DEC);
   }
}

Here is the problem:
At slow speeds this setup works and i can read correct rpm value on the serial monitor. But at higher speeds, the hall effect sensor does not detect the magnet or the arduino doesnt get the interrupt. The magnets are very powerfull and work from even 15mm away. I have tried this with 4 and 1 magnet around the periphery but at higher speeds the magnet is not detected.

What can be causing this? Is the hall sensor not switching at high enough frequency? Am I messing something in the setup? I have tried changing the distance between the magnet and the sensor but no difference.

Offline garrettg84

  • Robot Overlord
  • ****
  • Posts: 187
  • Helpful? 8
  • Armchair Roboticist Extraordinaire
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #1 on: December 23, 2011, 02:41:04 PM »
Do you think it is possible you are hitting your interrupt too quickly and either not finishing the previous interrupt or even over-running/corrupting the stack? I don't know how fast your wheel is spinning.

Around what RPM does it start messing up? Is this proportional if you went with 1 magnet instead of 4?
-garrett

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #2 on: December 23, 2011, 05:23:28 PM »
Thanks Garrett...after your questions and chatting with me bro ... this is the issue that i have been able to find:

the AH180 has a Tperiod of 150ms. That gives me  8Hz only. So i think with more magnets this wont work. I tried this with one magnet and got max 240rpm measured. This is 4Hz. So: The sensor is not capable to switch fast enough. And with only 1 magnet rpm wont be reported for ages.

If I try to insert magnets as SNSNSN - with alternating poles facing the sensor, will that cause faster switching? The magnets I have rt now are spherical so not easy to find a pole. I will have to purchase flat magnets which I have from here:
http://www.ebay.com.au/itm/290647205699?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

Are there any other hall effect sensors that have a quicker switching time? I was pointed to a "Quadrature hall effect sensor" any idea how to implement that?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #3 on: December 23, 2011, 09:16:10 PM »
the AH180 has a Tperiod of 150ms. That gives me  8Hz only. So i think with more magnets this wont work. I tried this with one magnet and got max 240rpm measured. This is 4Hz. So: The sensor is not capable to switch fast enough. And with only 1 magnet rpm wont be reported for ages.

It's typical top frequency is 13.3Hz/75ms (guaranteed at least 8Hz/125ms), so it is extremely slow.


If I try to insert magnets as SNSNSN - with alternating poles facing the sensor, will that cause faster switching?

Not really, it's the Hall device that sets the top speed.


Are there any other hall effect sensors that have a quicker switching time? I was pointed to a "Quadrature hall effect sensor" any idea how to implement that?

Plenty... Sparkfun has got a US1881 at just under a buck a piece (i.e. 1/10 the price of the one you've got and it's roughly 1000 times faster) - not extremely fast, but it has got a 10kHz top limit, so reading each cog on your 26T wheel, you could read up to 23kRPM - likely way over the recommended speed for that cog wheel.


Edit: Just studied the datasheet a little further. The US1881 is a latching Hall switch, so it's not easy to use for cog detection, as it has to see shifting South- and North poles.

Instead, spend a little more ($1.62) at Digikey for OH090U - It doesn't need the reverting magnet field, just a single pole will do and it's even faster than The Melexis device.



You can make quadrature output by mounting two Halls somewhat offset, so one output is phase delayed with respect to the other - 90° lead/lag will be the easiest to handle in software, but it doesn't have to be very precisely 90° (even 1° can be used if you read them by interrupt (one output interrupts the controller, which then read the other - the interrupt gives the frequency/speed and the direction info is read from the other output - whether it's read as "0" or "1".


In your photo, the sprocket seems to have the magnets mounted very irregularly and if that's the case, more than 1 count per revolution won't help you much, as you need a full revolution for precision.

If the sprocket is made of steel, you only need one magnet for bias and can then read each cog on the sprocket (if you mount the Hall device on the same axis, so they pass the Hall in close proximity).

IR could be used for reading each coq as well.
« Last Edit: December 23, 2011, 09:39:22 PM by Soeren »
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #4 on: December 24, 2011, 03:08:22 PM »
As usual ... Soeren ... thanks a bunch for the pointers. I will look to buy the OH090 sensor.
The sprockets are plastic. I tried to insert the magnets at 45 degrees, but in hurry, one or two got a bit off. Being plastic, i had to use the magnets for the hall sensor to work. I will look at IR as well.

Again ... thanks for the input.
Cheers

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #5 on: December 24, 2011, 06:56:52 PM »
It turns out ... these sensors are much more expensive here in Australia than in US. So I went for these: http://www.ebay.com.au/itm/280729328481?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

The data sheet show that rise and fall time is 2microsec as compared to 1microsec for the other one. Hope these work.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #6 on: December 25, 2011, 12:36:47 AM »
Hi,

It turns out ... these sensors are much more expensive here in Australia than in US. So I went for these: [...]
The data sheet show that rise and fall time is 2microsec as compared to 1microsec for the other one. Hope these work.
They should work, but the page says:
Quote
This seller does not post to Australia.
So drop him an email before you order

OTOH...
Quote
Item location: SZ, China
Posting to: United States, Europe, Canada, Australia, Mexico
Excludes: Alaska/Hawaii, US Protectorates, APO/FPO, Africa, Asia, Central America and Caribbean, Europe, Middle East, North America, Oceania, Southeast Asia, South America

He seems a bit ambivalent about shipping to Europe as well and you either get 10 or only 5 of them ???


The sprockets are plastic. I tried to insert the magnets at 45 degrees, but in hurry, one or two got a bit off. Being plastic, i had to use the magnets for the hall sensor to work. I will look at IR as well.
Since the wheel is plastic, you cannot just read each cog by a hall switch, but it will be easy with an IR-fork (slotted opto-coupler).
The slot has to be wide enough for the cogs with whatever clearance the (stability of the) setup demands of course, but they do come in "all" kinds - if you have an old ball mouse, you could get both the IR-LED and the photo transistor from that and you just need to add 2 resistors to get it running.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #7 on: January 19, 2012, 10:01:27 PM »
ok ... i got these sensors
http://www.ebay.com.au/itm/280729328481?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I connected the ground to ground on the arduino, VIN to 5 V on the arduino and output to the pin 13 on the arduino.

The problem I am having is a bit weird.

This sensor seems to be very sensitive. Even if i take my hand near the wires that are connecting the sensor to the arduino, i get a reaction at pin13. But if I take a magnet near the sensor nothing seems to happen. I tried showing both poles to both the sides of the sensor but same results. Whereas if I take my hand or a screwdriver near the wires i get a very repeatable reaction????

Any views?

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #8 on: January 20, 2012, 02:37:24 PM »
Problem solved..... turns our the wires were not copper.....after using proper copper wires it all works great. The sensors are very responsive and was able to measure upto 1000 rpm easily and as slow as 4 rpms.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #9 on: January 20, 2012, 03:35:50 PM »
Hi,

Problem solved..... turns our the wires were not copper.....after using proper copper wires it all works great. The sensors are very responsive and was able to measure upto 1000 rpm easily and as slow as 4 rpms.
Glad you solved it, but I am not sure you did?

The thing is, that you need a pull up resistor on the output (or enable internal pull up if available), as it's an open collector output.

The material of the wires shouldn't change anything, as long as they're conductive (and not extremely long).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #10 on: January 20, 2012, 11:42:18 PM »
you nailed it.... i wrote this code for the pin2 to which the output is connected: digitalWrite(2, HIGH). This pulls up the internal resistor
AND I changed to wires to copper at the same time .... and thought thats what cured it but aparently it was the line of code.
« Last Edit: January 20, 2012, 11:44:41 PM by omkar »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #11 on: January 21, 2012, 12:06:10 AM »
Hi,

AND I changed to wires to copper at the same time ....
Great that it work :)
But I'm getting curious here... What were the original wires, if not just tinned copper?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #12 on: January 21, 2012, 05:22:37 AM »
yes ... breadboard tinned jumper cables

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #13 on: January 21, 2012, 08:35:34 PM »
Hi,

yes ... breadboard tinned jumper cables
OK, tinned copper is usually better (and a little heavier on the wallet), as unprotected copper oxidizes relatively fast and then need to be cleaned to solder well.

The electrical characteristics is the same though, as long as the frequency is not high enough to make the skin effect pronounced (i.e. radio frequencies).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #14 on: January 22, 2012, 02:15:30 PM »
ok here is the working setup:
A3144 Hall effect sensor RPM bench trial with graph

Offline handyspacko

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #15 on: January 26, 2012, 05:06:13 PM »
Hello Omkar,

can you please make a how to, to make that wonderfull graph to work with your code. Is it Excel with the PLX-DAQ? How did you do that? sorry for my short and maybe wrong English. I am a German, but i can understand 90% of English. I had the same problems with the sensitive, but the internal pullup has worked for my, thanks Soeren

Offline omkarTopic starter

  • Jr. Member
  • **
  • Posts: 46
  • Helpful? 1
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #16 on: January 26, 2012, 07:12:50 PM »
hi... here you go.

I used Visual Basic Express 2010 for all of this. The Arduino code outputs whatever the sensor readings are as follows (sorry no comments in here as limited space):

//////////ARDUINO PROGRAM//////////////
 volatile byte rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);
   digitalWrite(2, HIGH);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop()
 {
   if (rpmcount >= 4) {
     rpm = (7500*rpmcount)/(millis() - timeold);
     timeold = millis();
     rpmcount = 0;
     Serial.print(rpm,DEC); //this is what is read by the VB program.
   }
 }

 void rpm_fun()
 {
   rpmcount++;
 }
///////////END////////////

Now, in VB:
1. Start new "Windows Application Project"
2. Insert a "chart" from the Data toolbox and this is where things are a bit tricky but follow exactly as shown below
3. In the properties for the just added chart object, goto Chart - > ChartArea and click on the "..." where it says Collections.
4. Make a note of the "chartarea1" name or add another chart area and rename it to whatever you want. Click ok to get out of this.
5. Now goto the Chart->Series properties. Either Add your own series or use the existing one. Change the chart type for the series to spline and chart area name as the one from step 4 (chartarea1).
6. You can choose what color/line width etc in the Appearance section of the series properties.
7. Click ok to get out of this.
8. On the main form add a textbox to display live values and name it txt_speed (or whatever).
9. Here is the VB program for the form (go to this by doubleclicking on the form):


''''''''''''''''''VBPROGRAM''''''''''''''''''''''''''''''''
Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    Dim WithEvents serialPort1 As New IO.Ports.SerialPort
    Delegate Sub myMethodDelegate(ByVal [text] As String)
    Dim myD1 As New myMethodDelegate(AddressOf myShowStringMethod)


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            With serialPort1
                .PortName = "COM21"
                .BaudRate = 9600
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
                .DtrEnable = True
                .RtsEnable = True
                .ReceivedBytesThreshold = 1
                .Encoding = System.Text.Encoding.ASCII
                .NewLine = Chr(13) + Chr(10)
            End With
            serialPort1.Open()
            serialPort1.DiscardInBuffer()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Sub myShowStringMethod(ByVal myString As String)
        Txt_CURSPEED.Clear()
        Txt_CURSPEED.AppendText(myString)
        Chart1.Series(0).Points.Add(myString) ''''''''''''''This is the line that actually adds live data to the chart as it is being read from the serial stream''''''''''''''''''
    End Sub
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort1.DataReceived
        Dim message As String = serialPort1.ReadExisting()
        Invoke(myD1, message)
    End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''END'''''''''''''''''''''''''''''''''''''''''''

Hope this helps.
Cheers


Offline handyspacko

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Help required for arduino based RPM sensor using hall effect and magnets
« Reply #17 on: January 27, 2012, 08:22:20 AM »
Thank you really much Omkar . Now, it works like a charm. Yesterday i have experimental give the PLX-DAQ programm a chance, its works yes, but not how i wish. This is much better and i understand every step. thank you. I searched for a long time for something like this.

 


Get Your Ad Here

data_list