Hi all. Another beginner question here.
Before I lay out my question in detail, I wanted to point out that I attached a high-resolution image collage of the work I've done so far. You can download it below and zoom around to see detailed photos. It shows that I have wired the sensor correctly according to the datasheet schematic, and that I'm getting the results I expected on the oscilloscope (without LED vs. with LED).
Anyways, here goes my question
I am attempting to read the frequency data from an IR light sensor with my Arduino and print it to the serial monitor. The sensor in question is the TSL245 from Taos. It has a peak sensitivity of about 940 nm. It outputs a square wave with a frequency that is proportionate to the amount of light it receives.
For convenience, HERE IS THE DIGIKEY PAGE, and HERE IS THE DATASHEET.
THIS ARTICLE says that there are two ways to read frequency data from a sensor with the Arduino. I have pasted text from that article below:
Method 1 - Using FreqCounter library. It can measure frequencies up to several MHz, and is very precise. However, measurement pin is fixed to digital pin 5. Also it may affect Arduino PWM outputs, increasing their duty cycles. In case you don't use PWM and you need to measure frequency of just one signal, FreqCounter is an excellent choice
Method 2 - Using pulseIn() function from standard Arduino libraries. The technique I'm suggesting below is free from FreqCounter limitations, so you can use it on any pin. However, it's minimal wave period is 10 uS, with corresponding maximum measurable frequency of 50 kHz
In the image collage below, you'll see that when the sensor is fully saturated with the IR LED's light, the scope displays a frequency of 10 kHz. For this reason, I believe Method 2 would be fine. (Where 50 kHz is the upper limit) This would free me from the need to use pin 5 like in Method 1. Also, I don't believe I'd have to build a preamp like in Method 1.So Method 2 (pulseIn function) it is.
Below, I modified the code for the simple PulseIn function to include pin 9, which you'll see in the image below is the input pin I've wired to my Arduino.
https://www.arduino.cc/en/Reference/PulseIn
int pin = 9;
unsigned long duration;
void setup()
{
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH);
}
Now I'm wondering where I go next? I have used the serial print function for AnalogRead values. This thread had a similar subject but never resolved the issue.
I am thinking this is what I should add next but I know it's incorrect. It doesn't compile and I'm not sure I even have the right idea
Can anyone lend a hand? Much appreciated
int pin = 9;
unsigned long duration;
void setup()
{
Serial.begin (9600);
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(9, HIGH);
value = pulseIn(pin 9, HIGH);
Serial.print(value);
Serial.println(": value.");
}