How to code Liquid Sensor for Electric Imp?

Hello, I’m trying to find out how to code the liquid sensor with electric imp and upload it to ubidots. any idea how to get to get it to work because i can’t find anything to start this at all. thanks = /

Give us a link to the liquid sensor you are discussing.

Helloo, I have this one is it possible for Ubidots to turn led on/off when liquid level reaches certain level?

I don’t understand the LED thing. Where are the LED’s?

The liquid sensor is simply a dry contact relay. That is just like a pushbutton switch.

If your LED’s are mounted on the imp, you don’t need much code at all … in fact, you can use the contacts on the relay without the imp to control the LED’s.

This is what your level sensor relay will look like … just like a pushbutton.

Explain the LED part.

my Leds are mounted on the imp …so I want something like when the liquid level goes to certain level…the Red led turns on and goes back off when water level is down. is it possible to do with Ubidots or do i need the code for the Agent and device?

You don’t even need to use the imp for the red led. The level relay contact switches when it touches water. Electronically, that switch lights the led. That same signal goes to the imp … And then the imp can send data to ubidots letting it know water was sensed.

You will need some electronic skills to hookup, assemble, and solder the components.

Do you at least have the imp running and showing on the IDE panel?

Yeah, I read that somewhere about not needing the imp for the led but I want to use imp mounted led for the liquid sensor to use it for my future projects. Yeah I got my imp and liquid sensor assembled when i bought it.

Are there too many codes to add for it to work the way I want it to work? because I will have to do it the way I’m trying to do in future anyway.

My imp working fine… i got multiple Leds working
. thanks

Your liquid level sensor has a relay on it with 3 pins … NO, C, NC

Hook C (common) to GND on the April board.
Hook NO (normally open) to an input pin on the April board.

When the relay closes (water detected), the digital input will go from 1 (high) to 0 (low).
1 (high) means there is NO water touching it.
2 (low) means there is water touching it.

If you wish to reverse that logic, use NC (normally closed) instead of NO (normally opened).

Are there any site where i can look into codes for liquid sensor to do that?


You just showed us the one you want to use:

And I just showed you an example of using it. It’s the same as a digital input w/pushbutton:


oh okay so if i change some stuff the example from the link above then it should work?

Yes. The closing and/or opening of the relay contacts is the same as a pushbutton. Within the imp, you do the LED’s on the associated output pins, and the change on the input pin gets sent to the agent, who then writes the change to your ubidots website.

I’m sure there will be differences in the coding, and the coding to handle the agent stuff and ubidots stuff. It seems simple to just report a pushbutton to ubidots, but there is coding to be done.

The agent also has to be listening for things coming from ubidots … for example, you are doing things online that will switch something in the imp.

What you’re doing is a great project for learning the imp.

I got this code for device to show button press and release but i’m only getting release for some reason


// Alias the GPIO pin as 'button’
button <- hardware.pin8;

function buttonPress() {
local state =;
if (state == 1 || state == 0) {
// The button is released
} else {
// The button is pressed

// Configure the button to call buttonPress() when the pin’s state changes
button.configure(DIGITAL_IN_PULLDOWN, buttonPress);

Assuming the input is low when released, try:

if (state == 0) {
      // The button is released
} else {
      // The button is pressed

BTW, I suggest you make use of the Button library as this handles de-bouncing for you (misreads caused when the electric contacts come together) and allows you to, optionally, attach functions to be called whenever the button is pressed and/or released.

unrelated but can someone tell if my imp is dead or not? it’s flashing red only everytime i power it up = /

Doesn’t matter Imp is working again .

… answered about the mysql database on your other thread.