You are on page 1of 3

#include <LiquidCrystal.

h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int in1=8; int in2=9; int int int int mo1=6; mo2=7; mo3=10; mo4=13;

int p,q,r,s= 0; // t for serial data xbee input variable, s for serial data g ps input variable, r for ir sensor variable int inputPin=0; // connect digital I/O d4 to the ECHO/Rx Pin int outputPin=1; // connect digital I/O d5 to the TRIG/TX Pin void setup() { pinMode(in1,OUTPUT); pinMode(in2,OUTPUT); pinMode(mo1,INPUT); pinMode(mo2,INPUT); pinMode(mo3,INPUT); pinMode(mo4,INPUT); pinMode(inputPin, INPUT); pinMode(outputPin, OUTPUT); digitalWrite(in1,LOW); digitalWrite(in2,LOW); digitalWrite(mo1,LOW); digitalWrite(mo2,LOW); digitalWrite(mo3,LOW); digitalWrite(mo4,LOW); lcd.begin(16, 2); lcd.print("under water"); lcd.setCursor(0, 1); lcd.print("object detection"); delay(7000); lcd.clear(); } void loop() { = digitalRead(mo1); = digitalRead(mo2); = digitalRead(mo3); = digitalRead(mo4); // initialize the digital pin as an output. // for ultra sonic comm........ p q r s

digitalWrite(outputPin, LOW); // send low pulse for 2s delayMicroseconds(2); digitalWrite(outputPin, HIGH); // send high pulse for 10s delayMicroseconds(10); digitalWrite(outputPin, LOW); // back to low pulse int distance = pulseIn(inputPin, HIGH); // read echo value int distance1= distance/29/2; // in cm lcd.print(distance1); delay(500); lcd.clear(); lcd.setCursor(0, 0); while(distance1 < 100) { digitalWrite(in1,LOW); digitalWrite(in2,LOW); lcd.setCursor(0, 1); lcd.print("stp"); delay(2000); digitalWrite(outputPin, LOW); // send low pulse for 2s delayMicroseconds(2); digitalWrite(outputPin, HIGH); // send high pulse for 10s delayMicroseconds(10); digitalWrite(outputPin, LOW); // back to low pulse int distance = pulseIn(inputPin, HIGH); // read echo value int distance1= distance/29/2; // in cm lcd.print(distance1); delay(500); lcd.clear(); lcd.setCursor(0, 0); if(distance1 > 100) { break; } }

if (p == HIGH && q == LOW && r == LOW && s == LOW) { digitalWrite(in1,HIGH); digitalWrite(in2,HIGH); lcd.setCursor(0, 1); lcd.print("frd"); } if (p == LOW && q == HIGH&& r == LOW && s == LOW) { digitalWrite(in1,LOW); digitalWrite(in2,LOW); lcd.setCursor(0, 1); lcd.print("stp"); }

if (p == HIGH && q == HIGH&& r == LOW && s == LOW) { digitalWrite(in1,LOW); digitalWrite(in2,HIGH); lcd.setCursor(0, 1); lcd.print("rgt"); } if (p == LOW && q == LOW&& r == HIGH && s == LOW) { digitalWrite(in1,HIGH); digitalWrite(in2,LOW); lcd.setCursor(0, 1); lcd.print("LFT"); } }