Can someone show me what's wrong

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresse I2C de l'écran LCD

const int moistureSensorPin = A0; // Broche analogique pour le capteur d'humidité
const int pumpPin = 3; // Broche de contrôle de la pompe à eau
const int moistureThreshold = 500; // Seuil d'humidité pour l'arrosage (ajustez selon vos besoins)

void setup() {l
lcd.init(); // Initialisation de l'écran LCD
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Auto-Irrigation");

pinMode(moistureSensorPin, INPUT);
pinMode(Assurez-vous de connecter correctement tous les composants et d'ajuster les broches selon votre configuration matérielle. Ce code suppose que vous utilisez un écran LCD I2C, sinon, vous devrez ajuster la
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(moistureValue);

if (moistureValue < moistureThreshold) {
startPump();
} else {
stopPump();
}

delay(1000); // Attendre 1 seconde avant la prochaine lecture
}

void startPump() {
analogWrite(pumpPin, 128); // Contrôle de la vitesse moyenne de la pompe
}

void stopPump() {
digitalWrite(pumpPin, LOW); // Arrêter la pompe
}

Do you have a problem with the code ?

See here for some tips on using the forum;

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966

what's wrong is the missing code tags :slight_smile:

Once you'll have edited your first post (the little pencil below the post) and added the code tags and relevant information for your project, circuit and issue - then we can tell you more like looking more deeply at


PS there is a French speaking forum if that's easier for you, you have similar rules though ➜ "Les bonnes pratiques du Forum Francophone”

1 Like
  • why is there a character after the brace?
  • looks like the pinMode() argument is a comment
  • where is moistureValue defined
  • where is loop() defined

all of these errors are identified by the compiler.

It appears I am not the only one that cannot follow the gibberish you posted. Follow @J-M-L and @srnet recommendations you will get a much better answer without a lot of questions.

Assurez - vous de connecter correctement tous les composants et d'ajuster les broches selon votre configuration matérielle. Ce code suppose que vous utilisez un écran LCD I2C, sinon, vous devrez ajuster la

So that comment is in a pinMode(); but the questions remains, is your LCD an I2C type (four wires, SDA, SCL, VCC and GND)?

Is that line supposed to be this?

 pinMode(pumpPin, OUTPUT);

Also, delay(1000); // Attendre 1 seconde avant la prochaine lecture
There's really no desire to put this in since your sketch has a very simple task: if it's too dry, start the pump, otherwise leave it off.

Nevertheless, I left it in in your code that was missing void loop() and was otherwise a mess. Anyway, please post neat code next time that you can format using CTRL+T in the IDE (it's beaucoup helpful) and post using code tags as others have mentioned.

Here's what your code might look like following the instructions just ^

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresse I2C de l'écran LCD

const int moistureSensorPin = A0; // Broche analogique pour le capteur d'humidité
const int pumpPin = 3; // Broche de contrôle de la pompe à eau
const int moistureThreshold = 500; // Seuil d'humidité pour l'arrosage (ajustez selon vos besoins)

void setup() {
  lcd.init(); // Initialisation de l'écran LCD
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Auto-Irrigation");
  pinMode(moistureSensorPin, INPUT);
  pinMode(pumpPin, OUTPUT);
}

void loop() {
  int moistureValue = analogRead(moistureSensorPin);
  if (moistureValue < moistureThreshold) {
    startPump();
  } else {
    stopPump();
  }
  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(moistureValue);
  delay(1000); // Attendre 1 seconde avant la prochaine lecture
}

void startPump() {
  analogWrite(pumpPin, 128); // Contrôle de la vitesse moyenne de la pompe
}

void stopPump() {
  digitalWrite(pumpPin, LOW); // Arrêter la pompe
}

I'm not saying it will work, I just cleaned it up a bit for you so you'd have somewhere to begin.

Now working through this, there are lots of problems. One is this

moistureValue

"moistureValue was not declared in this scope", in other words, where are you getting moistureValue? What pin are you reading and how to get this? You need a line like:

int moistureValue = analogRead(moistureSensorPin);

EDIT: added that line in so it will at least compile for you.

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