Ditched the last project and after some guidance from some other users I opted to go with a single board for simplicity.Running an arduino nano and two HC-sr04 sensors.
Both serial and LCD are only printing 25905 or 25906, doesn't change if I move anything in front of the sensor or move the sensors away. Code below:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
//
void setup() {
const int trigPin1 = A1;
const int echoPin1 = A2;
const int trigPin2 = A3;
const int echoPin2 = A6;
const int alarmPin = 2;
// defines variables
long duration1;
int distance1;
long duration2;
int distance2;
distance1 = duration1 * 0.034 / 2;
distance2 = duration2 * 0.034 / 4;
pinMode(trigPin1, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin1, INPUT); // Sets the echoPin as an Input
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin2, INPUT); // Sets the echoPin as an Input
pinMode(4, OUTPUT);
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(500);
lcd.init();
lcd.backlight();
Serial.print("Initializing Startup");
lcd.setCursor(2, 0);
lcd.print("Initializing");
lcd.setCursor(2, 1);
lcd.print("Start Up...");
delay(3000);
Serial.print("Testing Connections");
lcd.setCursor(2, 0);
lcd.print("Testing Sensor");
lcd.setCursor(2, 1);
lcd.print("connections...");
delay(3000);
if (digitalRead(2) == HIGH) {
lcd.setCursor(2, 0);
lcd.print("Sensor 1 ");
lcd.setCursor(2, 1);
lcd.print("connected ");
}
delay(3000);
if (digitalRead(6) == HIGH) {
lcd.setCursor(2, 0);
lcd.print("Sensor 2 ");
lcd.setCursor(2, 1);
lcd.print("connected ");
if (digitalRead(3) == LOW)
lcd.setCursor(2, 0);
lcd.print("Sensor 2 ");
lcd.setCursor(2, 1);
lcd.print("not connected ");
}
delay(3000);
lcd.setCursor(2, 0);
lcd.print("Test finished ");
lcd.setCursor(2, 1);
lcd.print(" ");
delay(3000);
lcd.setCursor(2, 0);
lcd.print("Starting ");
lcd.setCursor(2, 1);
lcd.print("monitors ");
delay(2000);
lcd.noDisplay();
// Turn on the display:
lcd.display();
delay(500);
//
}
void loop()
{
digitalWrite('trigPin1', LOW);;
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite('trigPin1', HIGH);
delayMicroseconds(10);
digitalWrite('trigPin1', LOW);
lcd.setCursor(2, 0);
lcd.print('distance1');
Serial.println('distance1');
delay(2500);
lcd.clear();
digitalWrite('trigPin2', LOW);;
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite('trigPin2', HIGH);
delayMicroseconds(10);
digitalWrite('trigPin2', LOW);
lcd.setCursor(2, 0);
lcd.print('distance2');
Serial.println('distance2');
delay(2500);
lcd.clear();
}