buenas tardes necesito ayuda con un proyecto que estoy realizando
consiste en una cisterna y un tinaco en encender un motor con 2 sensores ultrasonicos, que a cierta distancia solo encienda el motor cuando el tinaco no tenga agua y la cisterna si
pero para visualizarlo en el lcd necesito mostrar cuando esta encendido y cuando estan apagados y la verdad no se
#include <NewPing.h>2
#include <LiquidCrystal.h>2 // Entre los símbolos <>
#define TRIGGER_PIN 4 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 3 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define TRIGGER_PIN2 6
#define ECHO_PIN2 5
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define Motor 7
LiquidCrystal lcd(12, 11, 10, 9, 8, 2);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
NewPing sonar1(TRIGGER_PIN2, ECHO_PIN2, MAX_DISTANCE);
#define COLS 16 // Columnas del LCD
#define ROWS 2 // Filas del LCD
void setup() {
pinMode(Motor, OUTPUT);
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
lcd.begin(16, 2);
lcd.print(" UNIVERSIDAD");
lcd.setCursor(0, 1);
lcd.print(" TECNOLOGICA");
delay(5000);
lcd.clear();
}
void loop() {
delay(1000);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm());
Serial.println("cm");
delay(1000);
Serial.print("Ping1: ");
Serial.print(sonar1.ping_cm());
Serial.println("cm");
lcd.begin(16, 2);
lcd.print(" Tinaco= ");
lcd.setCursor(1,1);
lcd.print(" Cisterna=");
delay(5000);
unsigned int uS1 = sonar.ping(); // activates the first sensor
delay(50); // wait 50ms
unsigned int uS2 = sonar1.ping(); // activate the second sensor
delay(50); // wait 50ms
if (uS1 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
//from the front sensor,
digitalWrite(Motor, 1);
//the motor will rotate forward.
}
if (uS2 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
//from the back sensor,
digitalWrite(Motor, 0);
//the motor will rotate backwards.
}
if (uS1 / US_ROUNDTRIP_CM < 20 && uS2 / US_ROUNDTRIP_CM < 20 ) {
//if an object is less than 20 cm away from the right and left sensors,
digitalWrite(Motor, 0);
//the motor will not rotate.
}
if (uS1 / US_ROUNDTRIP_CM > 20 && uS2 / US_ROUNDTRIP_CM > 20 ) {
//if an object is more than 20 cm away from the right and left sensors,
digitalWrite(Motor, 0);
//the motor will not rotate.
}
}