Optical infrared water liquid level sensor

Hi. I am new to the Arduino. Getting used to it slowly. I have picked up a couple of these optical water level sensors and would like to know if anyone could help with how I go about wiring this to the Arduino uno. An what code i would use to run them like traditional duckbill floats.

Here is a link to the product. Check out the images for the schematics.

You help would be greatly valued. Thanks Forum.

--20150609143622.jpg

--20150609143636.jpg

--20150609143716.jpg

An additional attached image of how these work. An led and sensor

ElectoopticOP740440db89d641fc9b844bbc5344274c.png

I am guessing here. Am i correct in thinking that the light sensor side would function something like this Using a Photocell | Photocells | Adafruit Learning System

I have copied the code from the above website below.

I guess i would need a 390R on the LED side, and a 4.7K on the light sensor. The light sensor yellow wire to the A0 analog pin on Arduino uno. i guess i would then fill the tank with water and set the LED and sensor to HIGH and see what numbers we are getting from A0. note down the number with the water, then again without the water and then use these numbers like in the code below to do with as i please. eg run a function or change a variable. Let me know if i am looking in the right direction. If so i will have a go at wiring this up. i just want to make sure i dont blow my Arduino or anything.

/* Photocell simple testing sketch.

Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground

For more information see http://learn.adafruit.com/photocells */

int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider

void setup(void) {
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
}

void loop(void) {
photocellReading = analogRead(photocellPin);

Serial.print("Analog reading = ");
Serial.print(photocellReading); // the raw analog reading

// We’ll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
delay(1000);
}

One last question would be. In both the attached schematics of the wiring diagrams i posted. On one diagram it shows the R1 390R between 5+ and LED (blue wire), and on the other diagram it shows it between LED and ground (red). what is the difference here?

Ok I have basically answered my own question :slight_smile: i have this working now. East to set up. Here is the code for anyone who wants to use it. Nothing out there on the Internet at all about setting these up with Arduino so I hope this helps someone.

/* OPTICAL WATER LEVEL SENSOR - The optical sensor is great as there are no moving parts like all other water floats. Very accurate and nice little sensors. I could not find any information how to get these to work, after some research i found these have an LED and a LDR light sensor, NICE! the LED is on the blue and red wires blue to +5 VCC then to a 390R resistor, red to GND. The white and yellow are the LDR. White is +5 VCC, yellow to A0 pin on UNO and also yellow to 4.7K resistor then to GND. There is no need for any settings in the code for the LED as its taking direct power from +5 VCC. You could use a digital pin i guess and set it high for +5 to LED and LDR.

Code by Scott Bailey www.activstudios.com */


int topOpticalSensorPin = 0;                                 // the cell and 4.7K pulldown are connected to analog pin A0
int topOpticalSensorReading;                                // variable to hold the optical float sensor


// MAIN PROGRAM SETUP

 
void setup(void) {
  Serial.begin(9600);                                                                 // Initialise serial communications
}



// MAIN PROGRAM LOOP



void loop(void) {

  topOpticalSensorReading = analogRead(topOpticalSensorPin);     // take a reading from the optical sensor pin
 
  Serial.print("TOP OPTICAL SENSOR READING = ");                     // Print string to console
  Serial.print(topOpticalSensorReading);                                      // the analog reading of the optical sensor
 
  if (topOpticalSensorReading < 100) {
    Serial.println(" - TOUCHING WATER - YES");
  } else if (topOpticalSensorReading < 400) {
    Serial.println(" - TOUCHING WATER - NO");
  } else {
    Serial.println(" - TOUCHING WATER - NO");
  }
  
}

Hi,
Welcome to the Forum

Well that's good you talked your way through your problem, thanks for leaving your code as this is one of the reasons for the forum.

Can you edit the subject of this thread and put [SOLVED} at the end of it, so that members know there is a solution to the request.

That device looks very interesting, I can't see, just quickly looking, what the range is.
What have you found?

Thanks. Tom... :slight_smile:

I am hooking up the same sensor (or I think they are the same) but it's not working. I have blue wire to 390r to 5v. White wire to 5v. Red to ground. Yellow to the arduino with a pull donw resistor of 4.7k ohms. I tested it on two optical level sensor and it's not working. I wonder if both sensors are bad. I want to say my infrared light is working but the photo sensor is not. I'm not getting any feedback from when when measuring it. The infrared led acts like a diode so I'm getting some type of feedback when trying to measure it with my multimeter. Any idea guys?

Hi,
Have you got a DMM to measure voltages around the circuit to check if it is working.

How are you testing if it is working?

If you are using your code to check its operation, can you post the code please.

If you have a digital camera, you may be able to see some IR light leakage from the sensor, just watch your camera, as you apply and remove power to see if you can see any change in the image.

Tom.. :slight_smile:

I hooked it up according to the datasheet. Then hooked it up to the arduino. Wrote a simple code to read from it. From my understanding, the output should be either a HIGH or a LOW. It's always LOW regardless if it's in the water or not. I tried it both of the units that I received. It does not work for both of them. I measured the LED diode with an ohm meter which gave me a reading. I measured the light sensor which gave me no feedback (greater than a few million ohms). I'm stumped now.

paulsvang:
I hooked it up according to the datasheet. Then hooked it up to the arduino. Wrote a simple code to read from it. From my understanding, the output should be either a HIGH or a LOW. It's always LOW regardless if it's in the water or not. I tried it both of the units that I received. It does not work for both of them. I measured the LED diode with an ohm meter which gave me a reading. I measured the light sensor which gave me no feedback (greater than a few million ohms). I'm stumped now.

The latest code you posted prints the value of the measured analog input, A0. What does that show?

Also please post a clear image of your actual hardware.

Hi,
Can you measure the DC voltages at points A and B with respect to GND please.
One set OUT of the water and another set IN the water.
IR_WaterLevelSensor.jpg

Thanks… Tom… :slight_smile:

Out of the water
B = 5v
A = 0v

In water
B = 5v
A = 0v

R1 is 320 ohms and R2 is 5k ohms for my setup. What throws me off is that I have two units and it's the same thing. I hooked it up to the datasheet that I received and it does not work. I'm definitely think it might be the sensors or the color color of the wirings are wrong.

Hi,
What is the voltage at PIN 1/white of the sensor?
What is the voltage at PIN 4/red of the sensor?

The voltage at B is showing you have no current flowing through the LED.

Can you post a picture of your project please, so we can see your layout?

Tom.. :slight_smile:

Hi,
Does you DMM have a DIODE Test position?
If it does put it in DIODE mode and check the response between BLUE and RED wires.

First; Pos probe on BLUE
Neg probe on RED

Second; Pos probe on RED
Neg probe on BLUE

Thanks.. Tom.. :slight_smile:

I thought my diode test was working but then it’s not giving me a reading on either position. I then tested it on an LED and I get no reading on the DMM as well however the LED lights up when I put positive to anode and negative to cathode. Anyhow I will see if I can add in a pictures. I only see an option to link a picture. I’ll figure it out and post a pic of it.


Here it is.

Both sensors are bad. Thats why it didnt work. I just received the new ones and they are working.

Hi,
Excellent, pity you got two faulty, but a good outcome.

Tom.. :slight_smile:

TomGeorge:
Hi,
Excellent, pity you got two faulty, but a good outcome.

Tom.. :slight_smile:

Thanks for your help.

Sorry guys . I have had no notifications on this post. Glad you sorted it. For reference it's the A0 pin that is supplying a reading from the photocell. I was getting reading of 900 for out of the water and readings of 80-200 in water.