I came here again as I am always getting help from you guys
I want to make a speedometer using an IR sensor.
Do you have any ideas how how this code could work? I thought about store the millis() of the IR signal when it sees the object and one more millis() when it sees the next and measure it with their difference but it doesnt seems to be working as I am getting strange results...
I have no code yet (or at least a working one)...I am just thinking the way I can make it...
I though something like this which didnt worked:
if ("sensorvalue">0){
time1=millis();
state=1; //use state for being sure it wont enter the second "if" is the wheel didnt move
}
if ("sensorvallue"=0 && state=1){
time2=millis()
state=2;
}
time=time2-time1; // from this I maybe use maths to calculate the speed.
Thats my idea....Even though it didnt worked...Also I am not sure if this can practically work...this is a project that the wheel is going to run at 1-5 cycles per second I assume....Also I think the spoke of the wheel is not going to stay more than a couple of milliseconds..
I ve tested that with a PC Fan. The result of this values from (-)14XXX - (+)30XXX
I think (but not sure) that the last 3 digits (XXX) were almost the same. Is it possible to work with the last 3 digits?
AWOL:
C forbids comparison between a pointer and an integer.
In a millisecond, an Arduino could execute up to 16000 instructions.
I know..thats why I think it may not work...Even though I dont think that the sensor tht I got from Ebay is cappable of getting so many instructions xD
const int pingPin = 7;
void setup() {
 Serial.begin(9600);
}
void loop()
{
 long duration;
 int rpm;
 int count=0;
 long time;
 long time1;
 long time2;
 pinMode(pingPin, INPUT);
 duration = pulseIn(pingPin, HIGH);
 millis();
 if(duration > 0){
 time1=millis();
 state=1;
 }
 if(duration=0 && state=1){
 time2=millis();
 state=2;
 }
 time=time2-time1
  Serial.print("count=");
  Serial.print(time);
  Serial.print("\n");
  Serial.print("duration=");
  Serial.print(duration);
  Serial.print("\n");
}
Note that I got the code form a website. It was intended to test the sensor. I dont know what "duration" gives exactly but it works fine when an object pass away.
Post a link to the sensor.
Wheel? Spokes? So you use a photo interruptor. Is is continuous (affected by daylight) or modulated.
Did you calculate the minimum time the beam is interrupted by the spoke. How wide is the spoke.
Isn't wheel RPM usually done by a hall sensor and a small magnet clipped onto a spoke?
Leo..
How many of the examples provided with the IDE have you worked through?
How many of them (that didn't involve an ultrasonic sensor) put "pinMode" in "loop()"?
Wawa:
Post a link to the sensor.
Wheel? Spokes? So you use a photo interruptor. Is is continious (affected by daylight) or modulated.
Did you calculate the minimum time the beam is interrupted by the spoke. How wide is the spoke.
Isn't wheel RPM usually done by a hall sensor and a small magnet clipped onto a spoke?
Leo..
EAch spoke is just 3-5mm....The sensor wont be exposed to lighting....Its for a personal project which will be used indoors.
AWOL:
How many of the examples provided with the IDE have you worked through?
How many of them (that didn't involve an ultrasonic sensor) put "pinMode" in "loop()"?
I made a speedometer for a model railroad. Code is here.
Mayby it gives you an idea how to adapt it? This code can display it on (at the moment) two times of displays (SSD1306 I2C OLED or HT16K33 I2C 7-segment).
But make sure the sensor works correct. Does it indeed detect the spokes?
I think that the path you are currently headed down using the pulseIn() function is the wrong way to go. It is a "blocking" function and can cause problems as your code grows larger and more complex. It is designed to measure pulse length (duration) and there are better ways to determine the passing of an object in front of your sensor. I would advise that you take a step backwards, learn how to detect HIGH and LOW states from your sensor, and learn how to count the number of spoke passings using either digitalRead() or interrupt methods.
The code as I am trying to do it wont be similar to hall sensor with the magnets? I assume that because it will be done like switching took.
I don't know what you are trying to say, but your code WILL be similar to all the hall sensor or optical interrupter tachometer code(some good, some bad) floating around in cyberspace.
There are several ways to go with these speedometer applications. You can determine speed from the time interval between the passage of two spokes, like you are doing, or you can count the total number of spoke passings in a given time period, or you can find the time for a fixed number of spoke passings. Which way is better will depend on your sensor, the number and spacing of the spokes, and the speed of the wheel.
The first thing to do is to learn how to work with the sensor, so some simple counting and interval measurments, and prove that it is adequate for the task. Does it see every spoke? How fast can they be going? You may be able to improve the reflectivity of the spokes as well. Get the hardware working reliably and the speedometer code will follow.
The sensor used is a 3-30cm reflection sensor, most likely continuous mode.
I think it will be very unreliable detecting 3-5mm (round?) spokes.
I would first write a small program where the sensor just flashes a LED on the Arduino (onboard LED).
Then you can see what the sensor does if you turn the wheel. Adjust distance and sensitivity for reliability.
Maybe you can put large white areas on the wheel itself with e.g. twink or white nail polish.
A think a photo interrupter (gate) would have been better here.
Leo..