Arduino Forum

Using Arduino => Programming Questions => Topic started by: Joes on Jan 18, 2013, 06:00 pm

Title: what input pin is it using?
Post by: Joes on Jan 18, 2013, 06:00 pm
hi there just looking into using a hall sensor on my arduino and came across this code below, i dont know if im being blind but where does it state which input pin its using?

Code: [Select]



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);
   }
}
Title: Re: what input pin is it using?
Post by: AWOL on Jan 18, 2013, 06:03 pm
Code: [Select]
attachInterrupt(0, rpm_fun, FALLING); 
Right there, pin 2.
Title: Re: what input pin is it using?
Post by: cmiyc on Jan 18, 2013, 06:07 pm
http://arduino.cc/en/Reference/AttachInterrupt
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 18, 2013, 06:30 pm
There's a delay(50) in the ISR. Not a good idea.

Title: Re: what input pin is it using?
Post by: Joes on Jan 18, 2013, 07:04 pm
o ok i see thanks for that link one problem i can see is i am using an arduino uno and i will eventually need 3 hall inputs so how will i overcome that?

Quote

There's a delay(50) in the ISR. Not a good idea.

yes there is where it is blinking the led i dont actually need that led how can i get rid of that function as ive noticed if i remove void rpm_fun() i get a error
Title: Re: what input pin is it using?
Post by: PeterH on Jan 18, 2013, 07:31 pm

yes there is where it is blinking the led i dont actually need that led how can i get rid of that function as ive noticed if i remove void rpm_fun() i get a error


You could remove the blinking by taking out the two lines of code that write HIGH and LOW to the ledPin, and the delay between them.
Title: Re: what input pin is it using?
Post by: Joes on Jan 18, 2013, 07:34 pm
ok so basically leave it there but take the internals out of it.

would this work or am i barking up the wrong tree?

Code: [Select]



volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;
int rpm1 =1;


void setup() {
  Serial.begin(9600); 
pinMode(INPUT, rpm1);
}
void loop(){
 
   if(rpm1>=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);
   }
}
Title: Re: what input pin is it using?
Post by: CrossRoads on Jan 18, 2013, 07:36 pm
"i will eventually need 3 hall inputs so how will i overcome that?"

You can have an interrupt on any pin, they are called PCINT.
See NickGammon's writeup on them here
http://www.gammon.com.au/forum/?id=11488
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 18, 2013, 07:59 pm
You can keep the blinking led.
Move the blink part outside of the ISR. Set up a global byte variable and make it volatile to use as a blink flag, maybe call it bFlag. When the ISR runs, set that to 1 in the ISR. Then in loop() set up an if ( bFlag ) { } that makes the led blink and sets bFlag = 0.

So your ISR increments rpm count and flags the blink, it runs in next to nothing flat and is ready to service the next interrupt that fast.

IIRC you can set up any I/O pin to interrupt on Level Change. But look into things, maybe you don't need to use interrupts at all. Most things don't at 16 MHz.

You'd do better to learn how to use timers to run multiple tasks without using blocking code.
This is Nick Gammon's site, he's a master at explanations.
http://www.gammon.com.au/forum/?id=11411




Title: Re: what input pin is it using?
Post by: PeterH on Jan 18, 2013, 09:20 pm

would this work or am i barking up the wrong tree?


Wrong tree entirely. You have completely removed the interrupt handler now.

In your original sketch, this interrupt handler was called when you got a falling edge on pin 2:

Code: [Select]

void rpm_fun()
{
      rpmcount++;
      digitalWrite(ledPin, HIGH);
      delay(50);
      digitalWrite(ledPin, LOW);
}


These are the lines of code that turn ledPin HIGH, wait 50 milliseconds and then turn it LOW again:

Code: [Select]

      digitalWrite(ledPin, HIGH);
      delay(50);
      digitalWrite(ledPin, LOW);


If you take those three lines out it will no longer flash the LED and will no longer have that unwise delay() in the interrupt handler.
Title: Re: what input pin is it using?
Post by: Joes on Jan 18, 2013, 10:17 pm
hi thanks for your replies on that link http://www.gammon.com.au/forum/?id=11488 there is a lot of stuff on that website to get your head wrapped around lol i have come up with this compiles fine but somethings telling me im missing something here?

Code: [Select]



volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
{
// handle pin change interrupt for D0 to D7 here
}  // end of PCINT2_vect


void setup ()
  {
  Serial.begin(9600); 
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

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);
   }
}



p.s i dont wont the led output
Title: Re: what input pin is it using?
Post by: UKHeliBob on Jan 18, 2013, 10:35 pm

somethings telling me im missing something here?

How about something to update rpmcount ?
Title: Re: what input pin is it using?
Post by: Joes on Jan 18, 2013, 10:40 pm
Code: [Select]



volatile int rpmcount;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
{
   rpmcount;
// handle pin change interrupt for D0 to D7 here
}  // end of PCINT2_vect


void setup ()
  {
  Serial.begin(9600); 
  // pin change interrupt (example for D0)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

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);
   }
}



better?
Title: Re: what input pin is it using?
Post by: Grumpy_Mike on Jan 18, 2013, 10:44 pm
Quote
better?

No try:-

Code: [Select]

rpmcount++;
Title: Re: what input pin is it using?
Post by: PeterH on Jan 18, 2013, 11:47 pm
You started with a sketch that did more or less what you wanted, in a fairly simple way - no messing with hardware registers and so on.

Why have you thrown that away and started again with a more complex approach?
Title: Re: what input pin is it using?
Post by: Joes on Jan 18, 2013, 11:52 pm
o yes of course

here i am now with the 3x hall input's

Code: [Select]



volatile int rpm1count;
volatile int rpm2count;
volatile int rpm3count;
int sensorState = 0;
unsigned int rpm;
unsigned long timeold;


ISR (PCINT2_vect)
{
   rpm1count++;
   rpm2count++;
   rpm3count++;
// handle pin change interrupt for D0 to D7 here
}  // end of PCINT2_vect


void setup ()
  {
  Serial.begin(9600); 
  // pin change interrupt (example for D0,1,2)
  PCMSK2 |= _BV (PCINT16);  // want pin 0
  PCMSK2 |= _BV (PCINT17);  // want pin 1
  PCMSK2 |= _BV (PCINT18);  // want pin 2 
  PCIFR  |= _BV (PCIF2);   // clear any outstanding interrupts
  PCICR  |= _BV (PCIE2);   // enable pin change interrupts for D0 to D7
  }

void loop(){
 
   if(rpm1count>=5) {
      rpm=(60000*rpm1count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm1count = 0;
      Serial.println("rear left");
      Serial.println(rpm,DEC);
   }
   
      if(rpm2count>=5) {
      rpm=(60000*rpm2count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm2count = 0;
      Serial.println("rear write");
      Serial.println(rpm,DEC);
   }
   
      if(rpm3count>=5) {
      rpm=(60000*rpm3count)/(8*(millis()-timeold)); //the 8 changes to 4 if 4 magnets are used.
      timeold = millis();
      rpm3count = 0;
      Serial.println("rear prob");
      Serial.println(rpm,DEC);
   }
}



Quote


You started with a sketch that did more or less what you wanted, in a fairly simple way - no messing with hardware registers and so on.

Why have you thrown that away and started again with a more complex approach?


for a start i need 3 hall inputs as stated above but on the original code i could only run 2
Title: Re: what input pin is it using?
Post by: Grumpy_Mike on Jan 19, 2013, 12:06 am
So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.
Title: Re: what input pin is it using?
Post by: Joes on Jan 19, 2013, 05:51 pm
Quote


So you have three sensors and you increment all three counters when any one goes off!!!

You don't use the pin change interrupt like that anyway.



ok could you show me a beter way of doing it?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 19, 2013, 05:58 pm
Just check the pins with a port read at the start of loop() and don't fart around with delays or other blocking code. A fast loop() can read and evaluate, and report/store data for 3 pins many times per millisecond. Is > 1000 checks per second fast enough?

Title: Re: what input pin is it using?
Post by: Joes on Jan 19, 2013, 06:28 pm
i could do it in a port read like you said but this will be linking up with some other code i already have, there is no delays in it will it still be fine as this might be seeing some high rpm's?
Title: Re: what input pin is it using?
Post by: Grumpy_Mike on Jan 19, 2013, 07:42 pm
Quote
ok could you show me a beter way of doing it?

Better than "totally wrong and will not work at all", is easy.

This project:-
http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html (http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html)
Uses the pin change interrupt to monitor 6 pulse inputs. Maybe looking at that code would help you.
Title: Re: what input pin is it using?
Post by: Joes on Jan 19, 2013, 08:48 pm
now im more confused looking at that lol any one got a simple example thay can post?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 01:42 am
New to forum, check your private messages... look upper right under the Search box.
Title: Re: what input pin is it using?
Post by: Joes on Jan 20, 2013, 10:22 am
yes and i do not have any new messages?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 12:10 pm
OOOOPS! Sorry, wrong thread!

How many reads/second will the high rpm's require? Assuming 1 magnet on a shaft at 10000 rpm I get ~167 reads/second giving 6 milliseconds per cycle though the sensor will be high for a much shorter time.
An Arduino running spare code can make digital reads with minor processing in under 5 microseconds. I have sensor code that does a digital read, unsigned long increment and unsigned long compare ( if statement ) is just over 1 usec per while loop. I give an extra 60 cycles for 5 usecs.

The code you showed in the first post has no foot-dragging parts and uses millis for timing.

You know that if you pass a magnet under a coil that the speed of the magnet will affect how much power is induced in the coil? So maybe you don't have to count rpms.

Title: Re: what input pin is it using?
Post by: Joes on Jan 20, 2013, 05:07 pm
well my hall sensor is going to be an abs sensor on a car so theres quite a few triggers per revolution havent counted exactly but were looking at about 60, and the revolutions will depend on how fast the car is. so what do you think?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 07:30 pm
ABS as in the braking system? So rpm is rpm of the wheel?

Do you have multiple sensors or multiple magnets activating a single sensor?

Title: Re: what input pin is it using?
Post by: Joes on Jan 20, 2013, 07:47 pm
Quote

ABS as in the braking system? So rpm is rpm of the wheel?

yes

Quote

Do you have multiple sensors or multiple magnets activating a single sensor?


3x sensors with approxmatly 60 triggers per revolution


basically what im trying to do is for my arduino to look at 2 of the sensors and pick the fastest travelling one and compare it against the 3rd one if it is going slower than the 3rd sensor then to execute another piece of code
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 08:35 pm
3 sensors on 1 wheel? Well, it's for ABS... how to know what they measure?

Do they all measure rotation of the same wheel?
Do you have data (including time and maybe speed) from any 1 sensor?

A 28" diameter wheel turns about 12 times a second at 60 mph (88 f/s).

12 rps x 60 magnets is only 720 pulses per second, but again how long are the pulses? The hall sensor only detects the magnet for a limited time, not 1/720th of a second so you have less time than that to catch the signal.
That stated, you might be able to use pulseIn to know the speed of the wheel from just one magnet going by one (but maybe not just any one) sensor.

If I was trying to find answers, I would collect related data first.
Title: Re: what input pin is it using?
Post by: Joes on Jan 20, 2013, 09:30 pm
no 3 sensors one on the left wheel and one on the right and one on the prop shaft what is on 1 to 1 ratio

if i have to use a different sensor so we now what it is that is fine
maybe somthing like this;
http://uk.rs-online.com/web/p/magnetic-pickups/2355706/?searchTerm=235-5706&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E2C5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D3233352D353730362677633D4E4F4E4526


this is the trigger wheel
http://img.photobucket.com/albums/v626/shaheenramsay/9N/ABSSpeedSensor.jpg
or i can use somthing like this to
http://www.millersmule.com/MillersMuleStore/45-177-thickbox_default/trigger-wheel-mounting.jpg
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 10:34 pm
That first link --- anyone who pays that much for a Hall sensor has more money than knowledge. Holy cow, what a ripoff!

You have sensors in place though I'm not clear what you want the data for... is it to know speed?

Again, I would gather data and see which is suitable before even starting to design a final package.
Title: Re: what input pin is it using?
Post by: Joes on Jan 20, 2013, 10:43 pm
ok then what sort of data should i be gathering?
like travelling down the road with one of the sensors connected to an oscilliscope? (which i dont have lol)
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 20, 2013, 11:23 pm
I would use an Arduino to read 1 sensor on 1 pin to maybe fill an array at the tap of a button with timestamps showing state change times **just to see if I get useful data**.

If I didn't have a laptop to save those to then maybe I'd have them go to SD or EEPROM for later retrieval. Perhaps I'd think of a way to get speedometer data in there or just write that on paper.

You could have it read a pin and light up one of a row of leds to show data within different ranges. You don't have to be exact, just look for a suitable match to what you need.

What have you tested already? Do you need more complete or better data?
What can I say? I still don't know what this is for anyway.
Title: Re: what input pin is it using?
Post by: Joes on Jan 21, 2013, 07:28 pm
sounds like more code i dont understand, or know how to write lol currently havent done any testing but i do have a sensor and trigger wheel to play around with.
basically this is for a 4wd system in a car i have written a code already to control it manually but i want to now be able to conrtol it automatically so to look at the 2 rear wheel speeds and pick the fastest travelling one and compare it to the speed of the propshaft and if it is going slower execute it into another piece of code to lock the diff up.
Title: Re: what input pin is it using?
Post by: PeterH on Jan 21, 2013, 07:39 pm

look at the 2 rear wheel speeds and pick the fastest travelling one and compare it to the speed of the propshaft and if it is going slower execute it into another piece of code to lock the diff up.


That seems unnecessarily complex. Unless your diff has broken you know that the propshaft speed is proportional to the average of the two wheel speeds so all you need to do is look at the ratio of the two wheel speeds.
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 21, 2013, 07:53 pm
If the car is not going in a straight line the outer wheel will turn faster than the inner wheel.

I have been assuming that you have done at least a few of the example projects that came with your IDE. They do require some hands-on to teach basics.

Suppose you hook up the sensor and wheel you have and see what you can get from that?
The sensor is digital right? It's either on or off, LOW or HIGH, 0 or 1?

So write code to read the sensor and if it is HIGH you turn a led on (UNO has built-in led on pin 13, I dunno about the MEGA) and if it is LOW you turn the led off. Then turn the wheel and see how the led flickers. If it does not then it's time to check the wiring and the code.

All that does is to ensure that you can read the sensor and get meaningful data.

Title: Re: what input pin is it using?
Post by: Joes on Jan 21, 2013, 08:09 pm
Quote

That seems unnecessarily complex. Unless your diff has broken you know that the propshaft speed is proportional to the average of the two wheel speeds so all you need to do is look at the ratio of the two wheel speeds.


i disagree the car is normally a front wheel drive car, when slip is detected it will lock up the rear diff (as it doesnt have a centre diff) to transfer the power to the back wheels. in its original state the car will decide how much lock to put on by looking at the outside temperature, steering angles, throttle position, G force meter and overall speed. so this will be a simple system compared to the original

Quote
If the car is not going in a straight line the outer wheel will turn faster than the inner wheel.


yes it will this is why i want the arduino to pick the fastest moving wheel

Quote
I have been assuming that you have done at least a few of the example projects that came with your IDE. They do require some hands-on to teach basics.


yes i have so my knowlege is very limited


Quote
Suppose you hook up the sensor and wheel you have and see what you can get from that?
The sensor is digital right? It's either on or off, LOW or HIGH, 0 or 1?

So write code to read the sensor and if it is HIGH you turn a led on (UNO has built-in led on pin 13, I dunno about the MEGA) and if it is LOW you turn the led off. Then turn the wheel and see how the led flickers. If it does not then it's time to check the wiring and the code.


yes i would of thought so i will have to try that
but i am on the understanding that it is a hall sensor
i will do that and let you no what i get



Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 21, 2013, 08:28 pm
Be aware that there is more than 1 kind of hall sensor. Some are digital switches (yours probably is) and some are analog sensors (that can be read digital too). All react to magnetic fields.

This is time to play and try different things to see what works and what comes out. You will gain knowledge that you can be sure of just by experimenting.

Be sure to put a resistor in the path between 5V to sensor to digital pin unless the sensor already has one. A 1k resistor should keep your Arduino pin safe, even 2.2k is not too much for digital.

Title: Re: what input pin is it using?
Post by: Joes on Jan 21, 2013, 08:57 pm
Quote

Be sure to put a resistor in the path between 5V to sensor to digital pin unless the sensor already has one. A 1k resistor should keep your Arduino pin safe, even 2.2k is not too much for digital.


so i still need to put a pull down resistor to the digital pin?
Title: Re: what input pin is it using?
Post by: Grumpy_Mike on Jan 21, 2013, 09:04 pm
Yes still have a resistor pulling in the opposite direction to the sensor.

There are in fact two types of digital hall sensor, one which switches when it sees any magnetic field and the other that outputs one state when it sees a south pole and changes state not when the magnet is removed but when it sees a north pole.
Title: Re: what input pin is it using?
Post by: PeterH on Jan 21, 2013, 10:27 pm

i disagree the car is normally a front wheel drive car, when slip is detected it will lock up the rear diff (as it doesnt have a centre diff) to transfer the power to the back wheels. in its original state the car will decide how much lock to put on by looking at the outside temperature, steering angles, throttle position, G force meter and overall speed. so this will be a simple system compared to the original


For that to make sense, the drive to the rear wheels must be very different to a conventional prop shaft and diff. Do you have a clutch in the prop shaft? (I remember there was a very nice hydraulically controlled one from Land Rover a few years ago.)
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 21, 2013, 11:02 pm
Maybe it's a posi?
Title: Re: what input pin is it using?
Post by: Joes on Jan 22, 2013, 09:29 pm
Quote

For that to make sense, the drive to the rear wheels must be very different to a conventional prop shaft and diff. Do you have a clutch in the prop shaft? (I remember there was a very nice hydraulically controlled one from Land Rover a few years ago.)


yes it is a  hydraulically controlled


i tride that sensor out to day and could not get it to work the way we discussed so i tock the 10K pull down resister out and put a pot in then tork the pot down to 1.3k and it did work but very tempermental
the sensor seems to work between 1.0-1.3k
what do you think?
Title: Re: what input pin is it using?
Post by: PeterH on Jan 23, 2013, 12:57 am

i tride that sensor out to day and could not get it to work the way we discussed so i tock the 10K pull down resister out and put a pot in then tork the pot down to 1.3k and it did work but very tempermental
the sensor seems to work between 1.0-1.3k
what do you think?


I think you need to find out for certain what sort of sensor you have and what sort of signal it outputs. Is it definitely a Hall effect sensor? I would have thought that an MVR sensor was more likely.
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 23, 2013, 03:35 am
If it's a Hall switch then you use it like a manual switch/button.
Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 06:33 pm
Quote

I think you need to find out for certain what sort of sensor you have and what sort of signal it outputs. Is it definitely a Hall effect sensor? I would have thought that an MVR sensor was more likely.


how can i test to see if it is a mvr sensor?
mite be easier to just get a now one so we no what we have then somthing like this?
http://www.amazon.com/Inductive-Approach-Proximity-Sensor-Detection/dp/B004U4GCCW/ref=pd_sxp_grid_pt_1_0

but would be better in 5v
Title: Re: what input pin is it using?
Post by: PeterH on Jan 23, 2013, 07:21 pm

how can i test to see if it is a mvr sensor?


If it's an MVR sensor then the sensor will be slightly magnetic and it will produce a weak alternating electrical signal when ferrous material is moved towards and away from it. The magnitude of the signal is determined by the speed of the movement. This type of sensor is commonly used to detect the position of an iron/steel toothed wheel.

Hall effect sensors are not magnetic but require a magnet in the part being sensed.
Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 07:33 pm
this sensor is very magnetic on the end so might be, is that easy to be used with the arduino or am i better off getting a hall sensor ?

i thought it must be a hall sensor as a lot of the cars had a hall sensor looking at a steel trigger wheel for the engine rpm, so i thought these might be the same but obviously not
Title: Re: what input pin is it using?
Post by: PeterH on Jan 23, 2013, 08:29 pm

a lot of the cars had a hall sensor looking at a steel trigger wheel for the engine rpm, so i thought these might be the same


They probably are the same, but those other cars you're thinking of aren't using Hall effect sensors either.

You need to measure the voltage level over the range of speeds you need to support when the sensor is installed. You will almost certainly need to do some signal conditioning to take your variable voltage incoming signal and clean it up to a square wave.
Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 08:43 pm
so i will be easier to put some hall sensor on it like in link then?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 23, 2013, 09:00 pm
It could be as simple as a magnet in a coil. When a gear tooth passes close across the axis of the coil it will induce current in the gear tooth (eddy current) and the coil, the latter which can be picked up as a pulse with strength in proportion to the speed of the gear tooth. Such a sensor would not be affected by dirt or wet the way an light and sensor would. Unlike a Hall sensor, it would not require any magnets placed on the turning wheel.

If it is, don't try feeding it directly to Arduino until you know what directions make +V and -V.

Why buy when you already have something that must work or the car won't?
Can you get a part # on the sensor? Maybe it would be in a shop manual for the vehicle.


Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 09:08 pm
ahh yes there is a pos and neg symbol just above the pins on the sensor that would explain why they are there so how do i intergrate that with the arduino?

trying to find out information about it is near enough impossible ans manufacturers keep that information to themselves 
Title: Re: what input pin is it using?
Post by: PeterH on Jan 23, 2013, 09:55 pm

so i will be easier to put some hall sensor on it like in link then?


I would have said that an MVR sensor is the best one for the job - that's why they are so commonly used for this. But you need to cope with the fact that the amplitude of the output signal varies with speed, so you need to apply some conditioning before you can pass it to your input pin.
Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 10:17 pm
i just looked on my altodata and that says 60rpm 65 mV ac min
does that mean much to you or any help?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 23, 2013, 10:21 pm
We can Google a part number.
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 23, 2013, 10:26 pm

ahh yes there is a pos and neg symbol just above the pins on the sensor that would explain why they are there so how do i intergrate that with the arduino?

trying to find out information about it is near enough impossible ans manufacturers keep that information to themselves 


That would be in a repair manual even if it's just a company number.

There's a + and a -. Any other pins? The thing could be a package with built-in amplifier for all I know. But 60 rpm 65 mV AC... they wouldn't feed it AC yet + and - pins don't sound AC to me.

How about the make, model and year of the vehicle? There are automotive forums where the answer may be found as well.
Title: Re: what input pin is it using?
Post by: Joes on Jan 23, 2013, 10:44 pm
no part numbers on it just have 2 pin's on it. it is only a very little thing so i dont imagine there is much in it. i am extremely tempted to say sod it and just purchase some after market hall sensors as the car is an early 1980's car and everything mechanical in the car is from an 08 plate vehicle so me fitting those sensors is broad as it is long to fit either or, probably easier to fit the after market ones as i havent got to try and find trigger wheels to fit the cv joints and drill out hub carriers to fit them. at least with the hall sensor i can just get it to look at the bolk heads on the inner cv joint.
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 24, 2013, 12:02 am
You could try a Hall *switch* (security type, very cheap, very sensitive and reads digital) and a magnet with a toothed or holed steel/iron wheel between the two. Iron between switch and magnet should suck the field in. I'm just not sure how big a hole you'd need for enough field to get through, depending on the thickness of the wheel and how close the sensor and magnet are.

If you put 1 magnet on a shaft then you will get 1 pulse per turn and the rest of the time nothing. With a fast turning shaft it's probably all you need but otherwise maybe not.

Title: Re: what input pin is it using?
Post by: Joes on Jan 25, 2013, 09:18 pm
ok thanks i'll have to have a play but now we are back to the original question how can i run 3 hall inputs as i can only have to at mo?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 25, 2013, 10:13 pm
If you -have- to use interrupts then 2 of them can be level change interrupts.

I keep trying to get you to get sensors working so you can tell if you -need- to use interrupts at all.
Chances are that you don't. Chances are that you could catch the HIGHs a few times in a row as each magnet/gear tooth passes each sensor. But you won't know until you get sensors working and until you know it's probably not a great idea to design the sketch.


Title: Re: what input pin is it using?
Post by: Joes on Jan 25, 2013, 10:58 pm
ok
if im using a hall sensor it is high or low
i no there will be 6 triggers a revolution
we no what short of speeds we are looking at
what else we looking at apart from the mechanical side?
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 25, 2013, 11:27 pm
Hall switch operates ON/OFF.

Hall sensor linear type is analog -but- digital read pin triggers ON/OFF when voltage passes the switch points so you can use the linear type either way.

6 triggers per revolution... not 60?
With 60 the triggers per second is same as rpm, with 6 it is rpm/10.

I think that you could get by polling all 3 sensors at once by Port read and process the 3 bits at 10,000, maybe more triggers per second continuous if you don't do heavy processing.

If you don't do continuous reads, say capture and store 100 to 500 reads in an array and then process those while not reading then you could capture higher rates, possibly over 50,000 triggers per second and still sample and control more than 10x a second.

My ultrasonic sensor code has a while loop that does a digital read, unsigned long increment and unsigned long compare that runs just about 1 million times a second. I am being conservative in my estimates above because I can't be sure what your processing entails.
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 25, 2013, 11:41 pm
It does occur to me that you could write test programs reading the pins in a loop just to see how fast you can do it --- as long as the data doesn't matter. You can set them INPUT HIGH or pull them down through a 10k or higher (better) resistor or just let them float. Do all the things you would do with real data except run the car, you can get a good idea of what's possible.

Read all the pins at once for best results. Well, using AVR code in the sketch may save more cycles but I'm not the person to say those steps -- I do what I need without.

Title: Re: what input pin is it using?
Post by: Joes on Jan 25, 2013, 11:49 pm
yes the 60 trigger was with the old sensor i was thinkthing of putting the new sensor somewhere else hence now 6 trigger
here is the code i have at mo:
i no there is delays in it but when they are active the hall will not be being used
i would like to put all what we have been talking about in where it says (auto mod)

Code: [Select]



#include <AH_EasyDriver.h>

//AH_EasyDriver(int RES, int DIR, int STEP, int MS1, int MS2, int SLP);
AH_EasyDriver stepper(200,2,3,4,5,6);    // init w/o "enable" and "reset" functions


int tempsensor     = A1;
int brack          = 12;
int pump           = 13;
int automanual     = 11;
int overtempled    = 10;

int previous = 0;                       // the previous reading from the analog input
bool DoneInitialization = false;

void setup() {
  stepper.resetDriver();                  // reset driver
  stepper.enableDriver();                 // enable driver
  stepper.setMicrostepping(3);            // 0 -> Full Step                               
                                          // 1 -> 1/2 microstepping
                                          // 2 -> 1/4 microstepping
                                          // 3 -> 1/8 microstepping
  stepper.setSpeedRPM(50);                // set speed in RPM, rotations per minute
  pinMode(brack      , INPUT) ;           // brack
  pinMode(pump       , OUTPUT);           // hydraulis pump
  pinMode(automanual , INPUT) ;           // auto / manual swicth
  pinMode(overtempled, OUTPUT);           // over temp LED
  delay(4000);
}

void loop() {
                                            // get the sensor value
  int potVal = analogRead(0);
  int stpPos = map(potVal, 0, 1023, 0, 152);
  //                                         ----------------------
  int val = analogRead(tempsensor);          // temp sensor high
  if (val <970) {
    digitalWrite(pump,        HIGH);         // hydraulis pump high
    digitalWrite(overtempled,    LOW);          // over temp LED
    //                                      ----------------------- 
    if (digitalRead(brack) == LOW) {        // brack swicth
    if (digitalRead(automanual) == HIGH) {  // auto / manual swicth
    //                                    -------------------------------------------
        if (!DoneInitialization) {
    stepper.sleepON();                     // set Sleep mode ON
    delay(10000);
        DoneInitialization=true;           // Initialization is done, don't run it again until it has been reset
    } //                                ---------------------------------------------
      stepper.sleepOFF();                  // set Sleep mode OFF
      stepper.rotate(stpPos - previous);

      previous = stpPos;                   // remember the previous value of the sensor
    }
//                                      ---------------------------------------------
  else {                                              // -- AUTO mod -- //
                                                      //----------------//
  }
}
  //                                      ---------------------------------------------------------
  else {                                   // brack swicth when HIGH
      stepper.rotate(-previous);
                                           // reset the previous value to zero
      previous = 0;
  }
}
  //                                      ---------------------------------------------------------
  else {                                   // temp sensor HIGH
    stepper.rotate(-previous);
    previous = 0;                          // reset the previous value to zero
    DoneInitialization=false;              // resetting the count
    digitalWrite(overtempled,    HIGH);    // over temp LED
    delay(1000);
    stepper.sleepON();                     // set Sleep mode ON
    delay(10000);
    digitalWrite(pump,          LOW);      // hydraulis pump high
    delay(30000);
  }
  //                                     --------------------------------------------     
}
Title: Re: what input pin is it using?
Post by: GoForSmoke on Jan 26, 2013, 12:12 am
Oh no. You have to use timing based (Real Time) code to get this to work, even using interrupts.
The stepper moves like a glacier compared to Arduino. Loop has to finish very fast to get enough reads per second for... I forget how many rpm but it's for a car wheel.

If you read 10x as often as triggers then you will be sure to catch every one a few times in a row. That lets you be sure you don't get false positives, a good thing.

Also be real careful to debug and test this insanely much before going out on any road. If someone gets hurt there will be lawyers who will do anything to make it your fault. Facts won't matter, they are trained to steer around such trivialities as facts.