HI,
im trying to use a IR Led and receiver to count the rpms of a fan, i have it all wired up but im getting no information through to the infrared photo transistor, im using an elegoo uno R3
ill put my code below
[code]
int photo_i_p = 2;
int loop_no = 0;
int time_sec = 0;
int input_value = 0; // digital input signal either on / off 0 or 1
int currentState = 0;
int previousState = 0; // set up input and count variables, -32768 to 32767
float pot_i_p ;
float voltScaled ;
float period = 2000; // using millis() is mS
float physCount = 0;
float blades_sec ;
float set_rev_sec ;
float fb_rev_sec ; // feed back photo_i_p optic sense
float elapse ;
float start ;
void setup()
{
pinMode(photo_i_p, INPUT) ; // declare i/p could avoid this set as default
pinMode(10, OUTPUT);
Serial.begin(9600) ;
delay(1000) ; // delay to start
Serial.println("");
Serial.println(" Oct 2019 ");
Serial.println(" ");
Serial.println(" ");
Serial.println(" set feed back");
Serial.println(" sec rev/s rev/s ");
start = millis(); // mS since program started
} // setup
void loop()
{
// section 1/ potentiometer input leading to PWM output
pot_i_p = analogRead(A1); // read volts pin A1 = physical pin #15 (0-5.0 volts)
voltScaled = (pot_i_p / 665) * 250; // scaled for 0-1023 from 0-5.0 volt
set_rev_sec = voltScaled / 3.5 + 16.07;
analogWrite(10, voltScaled);
// section 2/ measure rotational speed
// a/ single pulse debounce & count, increments as a result of single cycle input
input_value = digitalRead(photo_i_p);
if (input_value == HIGH)
{
currentState = 1;
}
else
{
currentState = 0;
}
if (currentState != previousState)
{
if (currentState == 1)
{
physCount ++;
}
}
previousState = currentState;
// b/ n-second sampling period, rpm calculation
elapse = millis() - start ; // elapse = millis(current) – millis(start of programme) mS
if (elapse > period) // period set in declarations above
{
blades_sec = physCount * 1000 / period ; // use thousands as no decimal
fb_rev_sec = blades_sec / 7.0 ; // true feedback speed from 7 fan
// blades
loop_no ++ ; time_sec = loop_no * period / 1000;
// start = millis(); // reset timer
physCount = 0; //physical counter reset for new sample period
displayResult(); // call output routine
}
} // loop return
// section 3/ display on monitor
void displayResult()
{
Serial.print(" ");
Serial.print(time_sec);
Serial.print(" ");
Serial.print(set_rev_sec); // from potentiometer scaled
Serial.print(" ");
Serial.print(fb_rev_sec);// from photo-diode
Serial.println(" ");
} // display
thanking you
Also putting a schematic or at least a labeled block diagram would be of great help.
Have you verified the IR LED is working?
1 Like
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please go back and fix your original post.
Photos that clearly show your wiring can also be very helpful.
1 Like
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.