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.