#include //liquid crystal libary #define trigger 7 // trigger on the ping sensors #define echopin 6 //echopin on the ping sensor #define trigger2 9 //second trigger on ping sensor #define echopinn 10 //second echopin on the ping sensors #define button 8 //buton pin #define off LOW // I'm using the interal resistor on the arduino for the button and the button will awalys be on high so we //need to define it or int to t ``he button so when we push it it sets on low instead of high. int answer = 0;// this is the total to the two ping sensors when they both add up it is set to zero because we need a no value until we click the button for the added up value. int buttonstate = 0;// the thing i said the button awalys being high we need to set the button push to count it by 1 which tells the arduino // and the code the button has been pushed as low. int tube = 19.5;// this is the height of the tube im using so it awalys adds 19.5 cm + the just measured cm. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//this is the pins we are useing for the 16x2 lcd screen we are using. void setup () { lcd.begin(16, 2);// this sets the area of the screen. lcd.print("Please click [o] ");//the screen will show this . //Serial.begin(9600); pinMode(trigger, OUTPUT); pinMode(echopin, INPUT); //this reads the sensor data when it turns on. pinMode(button,INPUT);// this reads the button when its is pushed, digitalWrite(button,HIGH);//this sets the internal resistor for the arduino on high i belive im still learning but it works. pinMode(trigger2, OUTPUT); pinMode(echopinn, INPUT); } void loop(){ buttonstate = digitalRead(button); //the digitalRead function tells the code the button has been pushed. if (buttonstate == off){ // the if statemennt tells the arduino if condition has been met do something lcd.clear();// this clears the letters on the screen long duration, distance,distance2; // the long varabile keeps numbers for the values we give it like duration and distance digitalWrite(trigger, LOW); delayMicroseconds(2); digitalWrite(trigger, HIGH); delayMicroseconds(10); digitalWrite(trigger, LOW); duration = pulseIn( echopin, HIGH); distance = (duration/2) / 29.1; delay(80); digitalWrite(trigger2, LOW); delayMicroseconds(2); digitalWrite(trigger2, HIGH); delayMicroseconds(10); digitalWrite(trigger2, LOW); duration = pulseIn( echopinn, HIGH); distance2 = (duration/2) / 82.1; delay(80); answer=distance+distance2+tube;// this is adding the tube +the distance of one sensor +the second sensor. //Serial.print(distance); //Serial.print(" cm"); //Serial.print(" +"); //Serial.print(" cm"); //Serial.println(distance2); //Serial.print(" ="); lcd.print("room is ="); lcd.setCursor(1,11 ); // this sets the the printed words to the second column lcd.print( answer);//this prints the total of everything lcd.print(" cm");// this prints cm at the end of evey total } else { // the else statemenat awalys goes after the if statement so if the condition is not meant it will do something else instead, digitalWrite(trigger, LOW);// this turns off the sensor from pinging. digitalWrite(trigger2,LOW); } }