Very Basic Project, Need Guidance

Hello, this is my first post in the Arduino forums and I would love some help on a project that I am working on.

For the project, I would like to use an Infrared LED to measure the density of a liquid by coupling it with an Infrared Receiver which will measure the amount of light that actually gets through the liquid. Right now I have the infrared led up and running no problem, as its a very simple circuit. I also believe that I have the receiver wired correctly. Here is the circuit digram i followed for the receiver:

http://geekspiel.blogspot.com/2009/02/ir-receiver-circuit.html

and here is the receiver I am using:

http://www.radioshack.com/product/index.jsp?productId=2049727&prodFindSrc=cart

At first I thought that the signal the receiver it would output would be an analog signal ranging from like 0 to 5ish volts. But i have since found that it outputs in PWM (at least I think so). Here is the test program I have written to test the receiver:

int pin = 6; unsigned long duration;

void setup() { Serial.begin(9600); pinMode(pin, INPUT); }

void loop() { duration = pulseIn(pin, HIGH); Serial.print(duration); Serial.print(" microseconds "); Serial.print("\n"); delay(1000);

}

What I am getting is mainly 0's for the value in microseconds of the duration of the pulse that it is counting. If i move my finer directly next to the receiver it will jump to some really random values which are completely uncorrelated to the amount of infrared light hitting the receiver.

Can anyone give me some insight as to where I am screwing up? I would appreciate any and all feedback. I am new to all of this and I am eager to learn!

Thanks

Not sure I’m understanding everything, but I have several concerns here.

Let’s start with the aim of the project. Is it really intended to measure density, as in g/cm3 or some such? Or is it instead supposed to measure opacity/clarity of the liquid?

That IR receiver is for remote controls. Its output is on/off, 0/5V, if it's in the presence of a 38kHz IR signal. It's not suited to your application.

You're looking for an IR photodiode, minimally, for a variable (analog) result.

Ah! Thats exactly what i needed to hear Pancake! I thought I had purchased the wrong type of IR receiver. And I should have elaborated a little bit more Jack. I am planning to use the amount of light that gets through the water to measure the density of the water arbitrarily in terms of how much light gets through. I don't need an exact measurement in terms of g/cm^3 or anything.

But thank you for your help Pancake!

Agree on the receiver, I thought the same. It still sounds like the aim might be to measure opacity. Is the intent to measure how clear the water is, or how heavy (dense) it is? What's the measurement theory, i.e. how does using pulseIn() and counting microseconds come into it? If the intent is to measure clarity, then we should measure intensity of the light transmitted through the water. If the intent really is to measure density, perhaps indirectly as a change in the water's index of refraction, then microseconds may not be fine enough unless there is quite a bit of water involved.

The problem statement still is not clear to me.

@Mohrad

I am planning to use the amount of light that gets through the water to measure the density of the water arbitrarily in terms of how much light gets through. I don't need an exact measurement in terms of g/cm^3 or anything.

Let me get this ... according of what I read , the density of water is = 1 That is the water is H2O. So put salt into it, or mud... I don't thing the density will be more than 2, mostly a bit above 1 ( my guess ) like 1.025 , something like that.

To measure how clear, Jack is talking about a LDR - Light Dependent Resitor or a Photo Transistor. Therefore you measure ( get a reading ) when the water is clear ( the drinking water from the tap ) to a muddy water ( from the bottom of a lake ) or beer or tomato juice. If that you want in your project Mohrad.

The code is simply : value = analogRead(any_analog_pin); value @ clear and value @ muddy depending of the configuration of the light sensor. I mean : full light on the sensor = clear water or no light on the sensor = clear water. The config is up to you.

I thought I had purchased the wrong type of IR receiver.

The IR receiver is a sensitive device, with it you can only tell if there is a 38kHz IR signal present, whether that's weak or strong - or somewhere in between, it's all the same to it. If you need to quantify the amount of IR passing through your substance, for an analogRead application, then you need a photodiode (and, in all likelihood, an op-amp.)

My tap water might at times be cloudy and less dense or more by what's gotten into it. Air, for example.

Not density but --

Make a device that identifies dangerous liquids by analyzing light – By Eric Rosenthal…

After air travel security banned bottled water and baby formula, I began wondering why they didn’t use a device to determine the contents of liquids. If a liquid was detected to be safe, security could allow it on the plane. Spectrometers can identify the chemical makeup of a material by shining light on it and analyzing the precise mix of colors that bounce back.

http://blog.makezine.com/archive/2008/11/safety-spectrometer.html

Yes, in reality I am trying to measure the amount of light that get's through a water-algae mixture. As time goes on and the algae continues to grow, the density of the mixture is going to change because the ratio of algae-water is going to increase. As the density of the algae mixture increases, the amount of light that gets through the mixture should hypothetically decrease. I am going to use this assumption to attempt to measure the density of the mixture as a function of how much light is getting through the mixture over time. The end result is the program telling me when an experimental value of the "ideal light permittivity" is reached based off of the ideal density of the algae-light mixture (also an experimental value).

Any suggestions as to which IR phototransistor or IR photodiode I should take a look at?

Something as controlled as algae growth in water, yeah it should work! You might also measure how thick the algae layer on top forms as it needs light. Perhaps keep track of oxygen levels in the water as part of that optimum, are you working to use algae to produce sugars or oil?

You might try different colors while you're at it. And note that an led can be used to detect light that is the frequency (band?) of the led or higher. You don't need to spend money on receivers if you have leds. Also note that many IR receivers filter out higher frequencies... mine do.

Okay so I got an IR phototransistor and I have it all hooked up with a resistor. But now my serial monitor only prints the highest values. So then i went to check it with a multimeter and the second i hooked up the multimeter it began to act normally and actually record the changing values.

Any idea why this is happening?

Any idea why this is happening?

Sounds like some type of wiring issue.

It doesn't make sense that it only records the correct values when I have a multi-meter there measuring the voltage on the emitter end of the transistor with reference to ground.

It doesn't make sense that it only records the correct values when I have a multi-meter there measuring the voltage on the emitter end of the transistor with reference to ground.

Generally speaking, electronics usually work the way they are wired. I would suspect a grounding issue. Your arduino input may "float" if you don't have a high resistance path to ground when the meter is not connected. Try a high value resistor on the arduino input to keep it pulled low when there is little or no input.

Don't just run power to an analog pin and expect good input. Run your voltage to be measured through a resistor, perhaps 2.2K, to ground and then tap from before the resistor into your analog pin. Electrically the same, you could attach a resistor between the analog pin and ground to the circuit you already have.

The analog pins have high impedance "equivalent to 100 megohms". They measure current flow into the pin through that. For it to work you can't have the analog pin as your sink. You need to have current flow other than to the pin to get a good measure.

On the analog input example page there is a circuit diagram showing how to measure resistance on a turn pot. http://arduino.cc/en/Tutorial/AnalogInput

With a meter you can check that you don't have to hook all 3 legs of a pot to use it as a resistor. Go from either outer leg to center and turn the dial, the resistance changes. But try not hooking the pot to ground as in the diagram and you should get the same results as with your sensor.

I suspect that the impedance before the pin and the resistor to ground a voltage divider is formed though how the numbers apply I can't say offhand. The impedance to the pin is very very high so it seems that the value of the resistor to ground doesn't matter unless it is enormous too. But you need that flow past the pin for your circuit to behave normally or you won't get a good reading.

BTW, it took me hours to figure that one out and like you I was using a photo sensor. I still don't know the whys of everything I see done and that does bother me but I pick up clues now and then on the forum and docs.

Now all I am reading is 0’s. I ran a pull down resistor to ground form the emitter of the phototransistor and tapped in with the analog pin in between the resistor and the transistor. My circuit looks like this:

Try this:

Connect the long leg of the phototransistor (the collector) to +5V. Connect the short leg (emitter) to a 1k resistor. Connect the other end of the resistor to ground. Connect the emitter to the analog pin.

It can be done with a phototransistor, a 1k resistor, 3 jumper wires and a breadboard.

Don't worry about 5V going directly to analog in as analog in is high impedance. You want 5V able to go to the pin.

Now what do you read?

I'm still reading all zeros unless i literally attach 5v to the analog pin.

Here is my code:

const int analogInPin = A1;

int sensorValue = 0;

void setup() { Serial.begin(9600); }

void loop() { sensorValue = analogRead(analogInPin); Serial.print("Sensor Value = "); Serial.println(sensorValue, DEC); Serial.print("\n"); delay(1000); }

I could be wrong but setting a const int to A1..... See what happens if you do this.

const int analogInPin = A1;

int sensorValue = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("pin ");
  Serial.print(analogInPin);
  sensorValue = analogRead(A1);
  Serial.print("Sensor Value = ");
  Serial.println(sensorValue, DEC);
  Serial.print("\n");
  delay(1000);
}
[/quote]

Other than that you have conductive the long leg of the phototransistor to +5V, the short leg to pin A1 and a 1k resistor between A1 and ground, if the transistor and A1 haven't been fried should be good.

You can test the parts. Put the phototransistor long leg to 5V, the short leg to a 220 ohm resistor, the other end of the resistor to the long leg of a led and the short leg of the led to ground. Then change light and dark on the phototransistor, the led should go on and off.

Wow....It all comes down to simply looking at the back of the radio shack package that the IR Phototransistor came in which labels the collector as the short leg and the emitter as the long leg. After flipping it around, everything works perfectly. Thank you for your guidance in this project so far, it is much appreciated!