Bonjour à tous,
Nouveau membre de ce forum et débutant dans l'utilisation de l'Arduino, je viens vous demander conseil.
je veux réaliser un contrôleur de niveau d’eau de mon récupérateur d'eau de pluie.
voici le schema:
et le code:
// C++ code
//
#include <Adafruit_LiquidCrystal.h>
int ultrasonic = 0;
long duree;
int distanceCm;
byte hniveaumaxi=21; //niveau haut (distance entre le haut de la cuve et l'eau) en cm
byte hniveaumini=141; //niveau bas (distance entre le haut de la cuve et l'eau)
float pourcent;
long Litres;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}
Adafruit_LiquidCrystal lcd_1_1(0);
void setup()
{
Serial.begin(9600);
lcd_1_1.begin(16, 2);
}
void loop()
{
ultrasonic = 0.01723 * readUltrasonicDistance(10, 11);
pourcent= (ultrasonic*100-hniveaumaxi)/hniveaumini;
lcd_1_1.setCursor(0,0);
lcd_1_1.print("Niveau ");
lcd_1_1.print(pourcent);
lcd_1_1.print("%");
Litres= 3*pourcent; // la cuve fait 300l
lcd_1_1.setCursor(0,1);
lcd_1_1.print("environ ");
lcd_1_1.print(Litres);
lcd_1_1.print(" L");
delay(10);
}
ca fonctionne pas !! pas d'affichage
je pense que le code n'est pas adapté au capteur.
Pouvez vous m'aider
Merci
Phil
hello
1er point, un exemple de la librairie fonctionne t'il?
teste ce code:
saisissez ou The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
*/
// include the library code:
#include "Adafruit_LiquidCrystal.h"
// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);
void setup() {
Serial.begin(115200);
// while(!Serial);
Serial.println("LCD Character Backpack I2C Test.");
// set up the LCD's number of rows and columns:
if (!lcd.begin(16, 2)) {
Serial.println("Could not init backpack. Check wiring.");
while(1);
}
Serial.println("Backpack init'd.");
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
lcd.setBacklight(HIGH);
delay(500);
lcd.setBacklight(LOW);
delay(500);
} collez du code ici
en ajoutant le Serial.print j'ai une erreur.
le moniteur n'affiche rien du debut à la fin.
Quant à l'imprimante 3D je doit dire qu'elle affectivement beaucoup de travail !!
si je traduis il faut brancher la platine sur le pc ... mais apres je fais quoi?? n’oublie pas je suis un pur débutant et que par moment c’est compliqué !!
Oui, c'est la ligne Serial.println(pourcent);
que l'on a ajouté. Cette LED clignote au rythme des caractères envoyés à la console.
Télécharges ce scanner i2C dans ton UNO et dis nous ce qu'il y a dans la console à 9600.
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}