Go Down

Topic: hall effect sensor as a rpm mesauerment device (Read 10 times) previous topic - next topic

red65536

just to see if i have the concept down correctly.  what i want to do i measuer the acceleration of a wheel.  it will be spinning at 100 hrz at the top speed.  i tihnk the best way to do this is to have the hall effect sensor singal the interpt on the aurdino every time it goes high.  each time it is trigered i want to export a time stamp to the pc and log it, and then graph the trend of the acceleration based on the diference between a time stamp and its previous time stamp.

does hat make sense, or is there a better way to do data logging with the arduino.

thanks

Cheater

Thats one way.

Another way which is better if your doing other things on the chip at the same time:
1) When a interrupt fires, revolutions++;
2) Every X ms (however fine you want it) get the number of revolutions and reset the variable to 0
3) Compare the previous number to the current number. The change is acceleration while the number is absolute speed.

red65536

on a side note, i wrote some code to count how many times a button is pressed, and to only measuer the state changes.

here is that.

int ledPin = 12;                // LED connected to digital pin 13
int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status
int cnt =0;      // var for counting the presses
int tog =0;       //bit used to toggle and keep track of when the button is pressd or not

void setup()                    // run once, when the sketch starts
{
 pinMode(ledPin, OUTPUT);      // sets the digital pin as output
 pinMode(inPin, INPUT);    // declare pushbutton as input
 Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps

}

void loop()                     // run over and over again
{
 val = digitalRead(inPin);  // read input value
 if (val == HIGH) {         // check if the input is HIGH (button released)
   digitalWrite(ledPin, LOW);  // turn LED OFF
   if (tog ==0){
     tog++;}
     else{
   while ( tog == 1) {
     cnt++;
     Serial.print(cnt, DEC);
     Serial.print("\t");
     Serial.print(tog, DEC);
     Serial.print("\t");
     tog = 2;
   }  
 }
 }
 else
 {
   digitalWrite(ledPin, HIGH);  // turn LED ON
   tog =0;
 }
}



can i just replace the push button with the hall effect sensor?

red65536

also, is that a good way to do this function.  i dot really know much about code format.

mrmeval

The code should work. If you learn how to do that with an interrupt the chip could be doing other things until the interrupt is triggered.  That would be important only if you were running something time sensitive like a scanned LED matrix or had to monitor some other sensors.
If it was designed by man it can be repaired by man.

Go Up