i am trying to turn on a light when my output detects water but i am not sure what the sensor actually outputs and anything i have tested fails to turn the light on this is the product wiki Non-contact Capacitive Liquid Level Sensor Arduino Wiki - DFRobot any insight would be very appreciated
these are the code i have already tried
digitalWrite(lightPin, digitalRead(inPin));
the idea was the light would turn on when the sensor what high and off when sesnor was low
int inPin = 8;
boolean running = 0;//when running=1, the liquid is detected, print out 1, otherwise, print out 0; running=0, the liquid is detected, print out 0, otherwise, print out 1.
int modePin = 9;
int lightPin = 5;
void setup()
{
Serial.begin(9600);
pinMode(inPin, INPUT);
pinMode(modePin, OUTPUT);
digitalWrite(modePin, running);
}
void loop()
{
Serial.println(digitalRead(inPin));
if (inPin == 1) {
digitalWrite(5, HIGH);
}
else {
digitalWrite(5, LOW);
}
}
and this idea was when the boolean running was 1 light turn on as that was what the product wiki said its function was but it didn't work
Did you try that sample code in your link?
thats who i got the idea for the second code but it didn't work i could have been me could you try writing some code for it
If this is the device you are using then when mode=0 the signal will be low when water is detected. Mode=1 will reverse this and then the signal will be high when water is detected.
i am 95% sure i tried both modes
inPin is 8, it will never be 1.
so how would you code it
does this input need to be configured with the internal pull-up resistor enabled --- INPUT_PULLUP?
Try:
void loop()
{
digitalWrite(5, digitalRead(inPin));
Serial.println(digitalRead(inPin));
delay(2000);
}
- OP, (as mentioned) do you understand why this is wrong ?
if (inPin == 1) {
digitalWrite(5, HIGH);
}
Correctly
yep because the pin will always = 8 so it can never =1
i will test all these out when i get home thanks for the help
Update: it turns out that the code was fine and one of the jumpers wasn't plugged in properly i feel like an idiot
Don't. We've all been there. I was there twice today.
If you're not making mistakes, you're not learning anything. By the way, if that's your cat : what a sweet little face
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.