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.
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
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 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");
}
}
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.
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.
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.
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.
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.