#include #include Servo myservo; // create servo object to control a servo. int angle = 0; int pos = 0; // variable to store the servo position. int sensorPinA0 = A0; // select the input pin A0 for the potentiometer. int sensorPinA1 = A1; // select the input pin A1 for the potentiometer. int sensorValueA0 = 0; // variable to store the value coming from the sensor, Pin A0. int sensorValueA1 = 0; // variable to store the value coming from the sensor, Pin A1. LiquidCrystal lcd(2, 3, 10, 11, 12, 13);// Pinout, RS=2, E=3, DB4=10, DB5=11, DB6=12, DB7=13. int numRows = 2; // Number of rows of the LCD. int numCols = 16; // Number of Columns of the LCD. unsigned long echo = 0; int ultraSoundPin = 5; // Ultrasound signal pin. unsigned long ultrasoundValue = 0; void setup() // We write the initial configuration of our program. { myservo.attach(4); // attaches the servo on pin 9 to the servo object. myservo.write(angle); // set the motor shaft on 0 degrees. lcd.begin(numRows, numCols); // Allocates or initializes the number of rows and columns of the LCD. lcd.clear(); // Clean the LCD screen. lcd.setCursor(0,0); // Place the cursor at column 0, row 0. lcd.print(" ((( Moving ))) "); // Write on the screen that is indicated between quotes. lcd.setCursor(0,1); // Place the cursor at column 0, row 1. lcd.print(" ((( Radar ))) "); // Write on the screen that is indicated between quotes. delay(2000); // Wait 2 seconds. lcd.clear(); // Clean the LCD screen. pinMode(ultraSoundPin,OUTPUT); } void loop() { for (pos = 0; pos <= 180; pos += 10) { // goes from 0 degrees to 180 degrees. // in steps of 1 degree. myservo.write(pos); // tell servo to go to position in variable 'pos'. delay(10); // waits 15ms for the servo to reach the position. pinMode(ultraSoundPin, OUTPUT); // Switch signalpin to output. digitalWrite(ultraSoundPin, HIGH); // High pulse on Signal pin. delayMicroseconds(5); // Wait for 5 microseconds. digitalWrite(ultraSoundPin, LOW); // Wait for. pinMode(ultraSoundPin, INPUT); // Switch signalpin to input. echo = pulseIn(ultraSoundPin, HIGH); // Listen for echo, read high pulse. ultrasoundValue = (echo / 58); //convert to CM then to inches. lcd.setCursor(0,0); // Place the cursor at column 0, row 0. lcd.print(" Object Dist: "); // Write on the screen that is indicated between quotes. lcd.setCursor(9,1); // Place the cursor at column 9, row 1. lcd.print("cms"); // Write on the screen that is indicated between quotes. lcd.setCursor(5,1); // Place the cursor at column 5, row 0. lcd.print(ultrasoundValue); // It is written on the screen indicated between quotes. if (ultrasoundValue < 100) { lcd.setCursor(7,1); // Place the cursor at column 7, row 1. lcd.print(" "); // Clear the column 7. } } for (pos = 180; pos >= 0; pos -= 10) // goes from 180 degrees to 0 degrees. { myservo.write(pos); // tell servo to go to position in variable 'pos'. delay(10); // waits 15ms for the servo to reach the position. pinMode(ultraSoundPin, OUTPUT); // Switch signalpin to output. digitalWrite(ultraSoundPin, HIGH); // High pulse on Signal pin. delayMicroseconds(5); // Wait for 5 microseconds. digitalWrite(ultraSoundPin, LOW); // Wait for. pinMode(ultraSoundPin, INPUT); // Switch signalpin to input. echo = pulseIn(ultraSoundPin, HIGH);// Listen for echo, read high pulse. ultrasoundValue = (echo / 58); //convert to CM then to inches. lcd.setCursor(0,0); // Place the cursor at column 0, row 0. lcd.print(" Object Dist: "); // Write on the screen that is indicated between quotes. lcd.setCursor(9,1); // Place the cursor at column 9, row 1. lcd.print("cms"); // Write on the screen that is indicated between quotes. lcd.setCursor(5,1); // Place the cursor at column 5, row 0. lcd.print(ultrasoundValue); // It is written on the screen indicated between quotes. if (ultrasoundValue < 100) // if variable value is < 100, then clear the 7 column on LCD. { lcd.setCursor(7,1); // Place the cursor at column 7, row 1. lcd.print(" "); // Clear the column 7 } } }