XKC-Y25-V Digital Non-Contact Water Level Sensor

I have been asked to get this sensor working with ardupilot. it’s ideal for low level alerts on water tanks, so would be ideal for crop sprayers

first you need to add a servo connections to the wires coming from the sensor, you can either crimp these on to the existing wires or just splice some servo wires on as i have done.
20220721_104919

Its pinout is:

Yellow is signal,

Brown is VCC, the sensor supports from 5-24v

black is ground

Blue is output select, leave it disconnected if you want the output to go high or connect it to the black wire for it to go low.

to get it working with ardupilot we want to:

Connect blue and black together and connect to the ground wire of the servo connector.
Connect the brown wire to the red servo wire.
Connect the yellow wire to the white signal wire.

once its wired connect it to AUX1 assuming your using a pixhawk and connect a 5v supply to the servo pins, if you dont have an auxiliary 5v for testing you can bridge the 5v pin from the rc out to the 5v pin of any of the aux or rc out pins to temporally patch power over while on USB for testing.

now startup your flight controller, connect with mission planner and go to the parameters page

SET:

BTN_ENABLE = 1
refresh the parameters to get the new options to show.

BTN_FUNC1 = 0 if your using lua to detect changes. im just setting it to 28 for relay so it shows on messages.
BTN_FUNC1 = 30 to make the pixhawk beep when its triggered.

BTN_OPTIONS1 = 0 if you want it to trigger when no water is detected.
BTN_OPTIONS1 = 2 if you want it to trigger when water is detected.

BTN_PIN1 = 50 , if using AUX1 on a pixhawk
SERVO09_FUNCTION = -1 to set it to gpio.

save parameters and reboot and it should work, you should see the button triggering on mission planner messages.

if you want to send alerts to the ground station when the sensor is triggered then use this lua example script.

3 Likes

how can i put to pixhawk2 to that script can you teach me like step by step

You just need to copy the lua script to the scripts folder and set SCR_ENABLE to 1 then reboot.

man thanks soo soo much

did you get the sensor and lua working ?

man im soo soryy i didnt i cant do that i did same all of param and not getting message idk what i making wrong

i tried to 3 px4 but same to situation i cant see btn_options and BTN_FONCTIONS . btw i can see thats params only pixhawk orange but other px4 i cant see

which one should i try

send a log file or parameters so i can see how you have it set up.

ok i will send to you

pıxhawk.param (14.0 KB)
px4BlackCube.param (18.3 KB)
px4OrangeCube.param (18.2 KB)
this my 3 dif pixhawk params

your missing parameters from the pixhawk and black cube, but the orange cube looks correct.

yas yas when i connect pixhawk and black cube i cant see btn_option and btn_function but when i connect orange cube i can see i can doo i did but orenge cube sensor working but i didnt take message

if i get some message i gonna put your lua script

idk why that doing like that