Buonasera a tutti.
Come già ho scritto nella presentazione mi sono da poco avvicinato ad Arduino e quindi inizio a trovare i primi nodi :).
Il mio progetto è piazzare arduino con due sensori ad ultrasuoni che mi rilevano l'altezza di liquido in due vasche e me lo riportano su un lcd 16x2.
Sembra funzionare tutto bene ma sul lcd nonmi arrivano i due risultati.
Sono partito con questo schema:
void setup (per lcd e 2 sensori)
void loop (vasca 1 risultato su lcd quindi vasca 2 risultato su lcd)
Ottengo: H Vasca 1 misura corretta cm
H Vasca 2 nessun risultato senza neanche cm
A questo punto ho copiato il loop vasca 1 dopo il loop della vaasca 2
con questo schema:
void setup (per lcd e 2 sensori)
void loop (vasca 2 risultato su lcd quindi vasca 1 risultato su lcd)
Ottengo: H Vasca 1 nessun risultato senza neanche cm
H Vasca 2 misura corretta cm.
Quindi mi viene il dubbio che il mio errore sia nella gestione del lcd.
Naturalmente nel modificare lo sketch non ho toccato alcun filo.
Ringrazio anticipatamente per la mano che potrete darmi e vi posto il mio sketch:
#include <NewPing.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pingPin = 9;
int inPin = 8;
int pingPin1 =10;
int inPin1 = 7;
void setup(){
//imposto il numero di colonne ed il numero di righe di lcd
//usando il metodo lcd
lcd.begin(16, 2);
// Scrive il messaggio sul display.
lcd.setCursor(0, 0);
lcd.print("H Vasca 1");
lcd.setCursor(0, 1);
lcd.print("H Vasca 2");
}
void loop()
{
//parte il 2
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration1, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin1, OUTPUT);
digitalWrite(pingPin1, LOW);
delayMicroseconds(2);
digitalWrite(pingPin1, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin1, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(inPin1, INPUT);
duration1 = pulseIn(inPin1, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters1(duration1);
lcd.setCursor(10, 1);
lcd.print(cm);
lcd.print(" cm");
delay(100);
}
long microsecondsToCentimeters1(long microseconds1)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return (500 -(microseconds1 / 29 / 2));
}
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(inPin, INPUT);
duration = pulseIn(inPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
lcd.setCursor(10, 0);
lcd.print(cm);
lcd.print(" cm");
delay(0);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return (500 -(microseconds / 29 / 2));
}