Arduino czujnik wody - Arduino water sensor

witam mam problem z kodem arduino ponieważ jestem nowicjuszem to poprostu niewiem
mam swój nowy projekt który działa na zasadzie 2 diod i water sensora i działa to tak ze jesli water sensor nie wykryje diody to swieci czerwona dioda a jeśli wykryje wode to gaśnie czerwona i zapala sie zielona i to działa lecz chciałbym dodać jeszcze wyśwwietlacz z magistralą i2c i w kodzie mam teks ,,brak wody'' i ,jest woda'' ale niewiem jak zrobić tak aby kiedy wykryje wode pokazywała sie zielona dioda i tekst ,jest wioda '' i kiedy niebędzie wody sie zapalała czerwona dioda i napis ,,brak wody'' oto mój kod

#define Grove_Water_Sensor 8 // Attach Water sensor to Arduino Digital Pin 8
#define LED 9 // Attach an LED to Digital Pin 9 (or use onboard LED)
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
void setup() {
   pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
   pinMode(LED, OUTPUT); // The LED is an Output

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("B");
  lcd.print("R");
  lcd.print("A");
  lcd.print("K");
  lcd.setCursor(2,1);
  lcd.print("W");
  lcd.print("O");
  lcd.print("D");  
  lcd.print("Y");

  
  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("J");
  lcd.print("E");
  lcd.print("S");
  lcd.print("T");
  lcd.setCursor(2,1);
  lcd.print("W");
  lcd.print("O");
  lcd.print("D");  
  lcd.print("A");
}
void loop()
{

   /* The water sensor will switch LOW when water is detected.
   Get the Arduino to illuminate the LED and activate the buzzer
   when water is detected, and switch both off when no water is present */
   if( digitalRead(Grove_Water_Sensor) == HIGH) {
      digitalWrite(LED,HIGH);
   }else {
      digitalWrite(LED,LOW);
   }

   #define LED 13 // Attach an LED to Digital Pin 13 (or use onboard LED)

/* The water sensor will switch LOW when water is detected.
   Get the Arduino to illuminate the LED and activate the buzzer
   when water is detected, and switch both off when no water is present */
   if( digitalRead(Grove_Water_Sensor) == LOW) {
      digitalWrite(LED,HIGH);
   }else {
      digitalWrite(LED,LOW); 
      
      //pin 13 ma pracowac jako wyjscie
  pinMode(13, OUTPUT);  
   }
   {
  //pin 9 ma pracowac jako wyjscie
  pinMode(9, OUTPUT);
   }
}

pozdrawiam

In English courtesy of Google Translate

hello I have a problem with the arduino code because I am a novice, I just don't know my new project which works on the principle of 2 diodes and a water sensor and it works so that if the water sensor does not detect the diode, the red diode lights up and if it detects water, the red diode goes out and lights up green and it works but I would like to add a display with the i2c bus and in the code I have the text "no water" and, there is water "" but I don't know how to do so that when it detects water, a green LED and text are shown, there is light "and when in the absence of water, the red diode will be on and the inscription "no water" is my code

@wisnia

Nie ma niestety polskiego forum. Czy umiesz czytać/pisać po angielsku?
(Google Translate)


There is unfortunately no Polish forum. Can you read/write in English?

hello I have a problem with the code arduino because I'm a novice it's just invisible I have my new project that works on the principle of 2 diodes and water sensor and it works so that if the water sensor does not detect the diode is lit red diode and if it detects water it goes out red and lights up green and it works butI would like to add a display with the i2c bus and in the code I have a text "no water" and "there is water" but I do not know how to do so that when it detects water shows a green diode and the text , it is known " and when there will be no water lit a red diode and the inscription "no water" is my code

#define Grove_Water_Sensor 8 // Attach Water sensor to Arduino Digital Pin 8
#define LED 9 // Attach an LED to Digital Pin 9 (or use onboard LED)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
void setup() {
pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
pinMode(LED, OUTPUT); // The LED is an Output

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("B");
lcd.print("R");
lcd.print("A");
lcd.print("K");
lcd.setCursor(2,1);
lcd.print("W");
lcd.print("O");
lcd.print("D");
lcd.print("Y");

lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("J");
lcd.print("E");
lcd.print("S");
lcd.print("T");
lcd.setCursor(2,1);
lcd.print("W");
lcd.print("O");
lcd.print("D");
lcd.print("A");
}
void loop()
{

/* The water sensor will switch LOW when water is detected.
Get the Arduino to illuminate the LED and activate the buzzer
when water is detected, and switch both off when no water is present */
if( digitalRead(Grove_Water_Sensor) == HIGH) {
digitalWrite(LED,HIGH);
}else {
digitalWrite(LED,LOW);
}

#define LED 13 // Attach an LED to Digital Pin 13 (or use onboard LED)

/* The water sensor will switch LOW when water is detected.
Get the Arduino to illuminate the LED and activate the buzzer
when water is detected, and switch both off when no water is present */
if( digitalRead(Grove_Water_Sensor) == LOW) {
digitalWrite(LED,HIGH);
}else {
digitalWrite(LED,LOW);

  //pin 13 ma pracowac jako wyjscie

pinMode(13, OUTPUT);
}
{
//pin 9 ma pracowac jako wyjscie
pinMode(9, OUTPUT);
}
}

Hello,
I added code tags once, I won't do it twice...

do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Hello
Try this untested sketch:

#define Grove_Water_Sensor 8 // Attach Water sensor to Arduino Digital Pin 8
#define LED 9 // Attach an LED to Digital Pin 9 (or use onboard LED)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
  pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
  pinMode(LED, OUTPUT); // The LED is an Output
  lcd.init();                      // initialize the lcd
  lcd.backlight();
}
void loop() {
  /* The water sensor will switch LOW when water is detected.
    Get the Arduino to illuminate the LED and activate the buzzer
    when water is detected, and switch both off when no water is present */
  if ( digitalRead(Grove_Water_Sensor) == HIGH) {
    digitalWrite(LED, HIGH);
    lcd.setCursor(3, 0);
    lcd.print("B");
    lcd.print("R");
    lcd.print("A");
    lcd.print("K");
    lcd.setCursor(2, 1);
    lcd.print("W");
    lcd.print("O");
    lcd.print("D");
    lcd.print("Y");

  } else {
    digitalWrite(LED, LOW);
    lcd.setCursor(3, 0);
    lcd.print("J");
    lcd.print("E");
    lcd.print("S");
    lcd.print("T");
    lcd.setCursor(2, 1);
    lcd.print("W");
    lcd.print("O");
    lcd.print("D");
    lcd.print("A");
  }
}

Have a nice day and enjoy coding in C++.

thanks your post but there is still no switching of the green diode to "there is water"

Hello
As mentioned the sketch was not tested. The sketch has to be seen as framework to provide support.
Well, either you you have to check the hardware or the logic of sketch to get ready.
Have a nice day and enjoy coding in C++.

ok thank yough

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.