You are on page 1of 4

Arduino Project

:
Ultrasonic Sensor for Fish Detection on the deep sea

Ultrasonic Sensor adalah projek yang menggunakan sensor ultrasonic HC-SR04 bagi
mengesan objek atau halangan di hadapan. Objek yang dimaksudkan ialah ikan di
dsasar laut khususnya baagi menangkap ikan di kawasan laut dalam. Apabila sensor
mengesan objek atau halangan berdekatan, alat ini akan mengeluarkan bunyi buzzer
dan gerakan vibrator. Mini projek ini menggunakan asas seperti botol dan minuman
tin. Kedua-dua objek ini digabungkan untuk membentuk replika Bot menangkap ikan.

LAYOUT LITAR :

.Senarai komponen nya adalah seperti berikut.

begin(8. pinMode(echoPin2. HIGH). lcd. digitalWrite(trigPin1.duration2.count. LOW).distance1. OUTPUT). LOW). INPUT).print("Distance").11. pinMode(echoPin1. // digitalWrite(trigPin2. INPUT). OUTPUT).h> LiquidCrystal lcd(5. delayMicroseconds(10). .min. digitalWrite(trigPin1.10.2).6. #define buzzer 9 #define vibrator 12 #define trigPin1 A0 #define echoPin1 A1 #define trigPin2 A2 #define echoPin2 A3 int counter. LOW). OUTPUT). delayMicroseconds(2).7.begin(9600). HIGH). // delayMicroseconds(2).8). long duration1. } void loop() { digitalWrite(trigPin1. pinMode(buzzer. pinMode(trigPin2. OUTPUT). Arduino Source Code /* Project: Ultrasonic for Blind Programmer: Shahrulnizam Mat Rejab Board: Arduino UNO Last Modified: 20 May 2015 Website: http://shahrulnizam. pinMode(trigPin1. duration1 = pulseIn(echoPin1.distance2. Serial.com */ #include <LiquidCrystal. void setup() { pinMode(vibrator. lcd.

// delayMicroseconds(10). else if(distance2<100) lcd.70. else if(distance1==6) distance1=100.1.setCursor(0.10). distance2=200. else if(distance1<100) lcd. // duration2 = pulseIn(echoPin2.print(" "). so to find the distance of the // object we take half of the distance travelled. else min=distance2. digitalWrite(vibrator.print(distance1).HIGH). LOW). if(distance2<10) lcd. if((counter<=5)&&(count>0)) { digitalWrite(buzzer.0. HIGH). else counter=1. // The ping travels out and back.print(distance2). // digitalWrite(trigPin2. lcd.LOW). HIGH).print(" "). lcd.//microsecondsToCentimeters(duration2). digitalWrite(vibrator.print(" "). else count=map(min. if(min>=70) count=0.print(" "). } lcd. if(distance1>1000) distance1=distance1/1000+100. if(distance2>1000) distance2=distance2/1000+100.// digitalWrite(trigPin2. return microseconds / 29 / 2.1). if(distance1<10) lcd.HIGH). distance1=microsecondsToCentimeters(duration1). } else { digitalWrite(buzzer. if(distance1<distance2) min=distance1. if(counter<5*count) counter++.print(" "). lcd.LOW). } . } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter.