Fans run at 3000rpms and this seems to work fine.
I'm not sure how the fans get the hall effect sensor to output +5v pulses so you may want to look at an hall effect sensor that has the circuitry to do that for you.
how would you poll the sensor so theres is a constant sample rate, would it be by using an interupt, i feel that the code delay times would fluctuate based on the data that is acquired and the different times it will take to pass it along the serial conenction.
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.
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?
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.
im not exactly sure how you would use the interupt for this situation. i have two ideas from what you have mentioned.
use the interupt as the data in from the hall effect sensor. when the interupt is triggered send the current time out via the serial link ot the comp to log and process this data and then graph it.
2)run code to count all of the positive state transistions the hall effect sensor has, when setting up a timer to trigger the interupt at a constant time, and do the math based on how many revs per interupt period.
When using a interrupt you have to make the interrupt function as small as possible.
You cannot use stuff like Serial in it. If its too big then strange things happen.
Its best to make the hall effect sensor fire the interrupt and just have a variable storing how many times it fires.
Thats only a single instruction and will work the best.
I'm just getting started with the arduino and figured i'd give the pushbutton example a try. When i connect up everything as shown on this page http://www.arduino.cc/en/Tutorial/Pushbutton the LED gives me a flashing light instead of an on/off behavior... i'm stuck? Is it supposed to give me a flashing LED? or a state-like behavior which would make sense.
The led should follow the state of the button. Perhaps the input is floating, check to make sure that the switch is connected to pin 7. If you have a voltmeter, check that the voltage is 5 volts on pin 7 when the switch is not pressed and 0 volts when pressed.
Also, are you sure your sketch has been sent to the board, as I recall on mine. the default sketch just flashes the led.
Thanks for the quick response. I'm pretty sure the sketch is being sent. I have the NG board so i've been pressing reset then sending the sketch to it. I added Serial.println("this is high"); to the statement to see if it was going through the loop properly and it does not print out....am i missing something?
Are you seeing any serial output? Have you tried the ASCIITable serial example to verify that download is working and you can see serial data from the arduino?
If that works then try adding code to the ASCIITable sketch to read your inPin and output something indicating the state. (Don't forget to set inPin to input).
If that doesn't work then recheck your switch, resistor and wiring. A voltmeter is a big help for projects that involve external components. It's worth getting if you don't have one.
So you're listening to the RPM from a hall effect sensor, but you also want to ouput info to a serial LCD or save info to a USB thumb drive (serial) or send information via wireless (probably serial) to some other device (another arduino?) and you want to listen, or at least post for button inputs because you have a few user inputs... yeah how? How many things can you have interrupts for?
Could you make a simple device to take in the hall effect reading and output an analog signal based on that reading? say at like 1hz reading every second (really slow RPM) vout = 0v and your limit of 100hz vout=5v. You're going to have your "speedometer"
Then Arduino wouldn't really have to listen,but rather post for it. Assuming you don't have any really long loops, you'd probably pick up the vout at least every 100hz... It'd be like a rolling average, but it couldn't ever be too far behind, at least as far as mechanical things go... The problem with hall effect sensors is that they can't really read 0rpm, it has to be assumed.
That's still something I'm having trouble getting my head around as a mechanical guy playing with electrical stuff... 16Mhz is extremely fast for me, 16million operations every second? wow... hard to believe you couldn't pick up something running at 100hz, the issue of course is not if you can pick it up or not, but if you miss the signal, like the hall effect sensor trips when you're not posting for it so you only pick up say 99hz when it's really 100... how much of a difference does it make in the end?
In reality, if you wanted Arduino to collect a lot of data, just how limited are you?
Yeah I'm just sort of thinking out loud, this is something I see myself running into within the next year...
can anybody tell me why the last line of the below function says "that each rotation, this interrupt function runs twice"
i am a noobe and it is not readily obvious
void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}