Simulasi Sensor parkir mobil dengan rem otomatis berbasis arduino
|Simulasi Sensor parkir mobil dengan rem otomatis berbasis arduino
alat ini menggunakan mikrokontroler arduino, yang berfungsi untuk memarkirkan mobil pada saat parkir mundur dan di bantu rem otomatis, alarm, dan layar lcd jarak,
Description program : u can in the Comment
Simulasi Sensor parkir mobil dengan rem otomatis berbasis arduino
Simulasi Sensor parkir mobil dengan rem otomatis berbasis arduino
3 Comments
Program :
#########Breadboard circuit mounting:########
* LCD VSS pin to ground
* LCD VDD pin to +5V
* 2K2Ohm resistor: ends to LCD VO pin and ground
* LCD RS pin to digital pin 9
* LCD R/W pin to ground
* LCD Enable pin to digital pin 8
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD A pin to +5V
* LCD K pin to ground
* Buzzer + to 220Ohm Resistor leg and – to ground. The other resistor leg goes to pin 12.
* HC-SCR GND to ground
* HC-SCR Echo to pin 11
* HC-SCR Trig to pin 10
* HC-SCR Vcc to +5V
##############################################
*/
//Defining pins
#define trigPin 6
#define echoPin 7
#define buzPin 12
#define RS 9
#define Enable 8
#define D4 5
#define D5 4
#define D6 3
#define D7 2
//Including the LCD and sound library:
#include <LiquidCrystal.h>
#include "pitches.h"
#include <Servo.h>
// Initialize the LCD library
LiquidCrystallcd(RS, Enable, D4, D5, D6, D7);
/////DefinisiLCDkarakter khusus///
uint8_t cc0[8] = {0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07};
uint8_t cc1[8] = {0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x1C};
uint8_t cc2[8] = {0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00};
uint8_t cc3[8] = {0x1C,0x18,0x10,0x00,0x00,0x00,0x00,0x00};
uint8_t cc4[8] = {0x00,0x00,0x00,0x10,0x18,0x0C,0x04,0x06};
uint8_t cc5[8] = {0x06,0x04,0x0C,0x18,0x10,0x00,0x00,0x00};
uint8_t cc6[8] = {0x10,0x08,0x0C,0x06,0x02,0x03,0x03,0x03};
uint8_t cc7[8] = {0x03,0x03,0x03,0x02,0x06,0x0C,0x08,0x10};
////Sound notes setup
int melody0[] = {NOTE_B3, NOTE_B3,NOTE_B3, NOTE_G3, NOTE_B3,0, NOTE_D4, NOTE_D3};
int melody1[] = {NOTE_C6,NOTE_C6,NOTE_C6,NOTE_C6};
int melody2[] = {NOTE_C6,NOTE_C6,NOTE_C6};
int melody3[] = {NOTE_C6,NOTE_C6};
int melody4[] = {NOTE_C6};
// Tambahkanukurandi sini, dan pada akhirdari "music" array.
int* music[6/number of melodies + 1/] = {melody0, melody1, melody2, melody3, melody4 /,add here/};
////Sound notes durations
int notesMelody0[] = {8,4,4,8,8,8,2,4};
int notesMelody1[] = {8,8,8,8};
int notesMelody2[] = {8,8,8};
int notesMelody3[] = {8,8};
int notesMelody4[] = {4};
//Tambahkandurasimelodysini, dan pada akhirdari "noteDurations" array.
int* noteDurations[6/number of melodies + 1/] = {notesMelody0, notesMelody1, notesMelody2 , notesMelody3 , notesMelody4 /,add here/};
Servo myservo;
Servo myservo2;
intpos = 0;
////Sound sizes
int sizeMelody0 = sizeof(melody0)/sizeof(int);
int sizeMelody1 = sizeof(melody1)/sizeof(int);
int sizeMelody2 = sizeof(melody2)/sizeof(int);
int sizeMelody3 = sizeof(melody3)/sizeof(int);
int sizeMelody4 = sizeof(melody4)/sizeof(int);
//Tambahkanukurandi sini, dan pada akhirdari "ukuran" array.
int sizes[] = {sizeMelody0,sizeMelody1,sizeMelody2,sizeMelody3,sizeMelody4 /,add here/};
////ToneFungsi- Memutarnada
intplaySong(int track, float durConst){
for (intthisNote = 0; thisNote< sizes[track]; thisNote++) {
intnoteDuration = 1000/noteDurations[track][thisNote];
tone(buzPin, music[track][thisNote],noteDuration);
intpauseBetweenNotes = noteDuration * durConst;
delay(pauseBetweenNotes);
noTone(buzPin);
}
}
//Mendeklarasikanvariabelyang akanmenghitungMillissehinggaberkedip
independent of "delays"
unsigned long millisCounter = 0;
int displaying = 0;
////////////////////////////////////
//////////////SETUP/////////////////
////////////////////////////////////
void setup(){
// MengaturnomorLCDkolom dan baris:
lcd.begin(16, 2);
// Mengaturkarakterlcd (8 maximum)
lcd.createChar(0, cc0);
lcd.createChar(1, cc1);
lcd.createChar(2, cc2);
lcd.createChar(3, cc3);
lcd.createChar(4, cc4);
lcd.createChar(5, cc5);
lcd.createChar(6, cc6);
lcd.createChar(7, cc7);
//menginisialisasi pin HC-SCR04
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(10);
myservo2.attach(11);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" SENSOR PARKIR ");
lcd.setCursor(0, 1);
lcd.print(" MOBIL ");
myservo.write(0);
myservo2.write(90);
//Plays intro song
playSong(0,1.30);
}
////////////////////////////////////
//////////////LOOP//////////////////
////////////////////////////////////
void loop()
{
unsigned long millisNow = millis();
long duration;
int distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//Mengukurjarak
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 0){//Evaluate the distance value.
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" YAUDAH RUSAK ");
lcd.setCursor(0, 1);
lcd.print("MOBIL SAYA.. T_T");
}
else {
lcd.clear();
Serial.print(distance);
Serial.println(" cm");
lcd.setCursor(0, 0);
lcd.print("JRK PARKIR");
lcd.setCursor(2, 1);
lcd.print(distance);
lcd.print(" cm. ");
//jarakperkiraan
if(distance <= 10)
{
if(millisNow-millisCounter>50 && displaying == 0){//This part is used for the blinking while at 10 cm less.
//Each of these "lcd.setCursor" and "lcd.write" are responsible for the drawings.
lcd.setCursor(10, 0);//This positionates the cursor on the desired slot
lcd.write(byte(0));//This writes the prefab symbols
lcd.write(byte(1));
lcd.write(byte(4));
lcd.write(" ");
lcd.write(" ");
lcd.write(" ");
lcd.setCursor(10, 1);
lcd.write(byte(2));
lcd.write(byte(3));
lcd.write(byte(5));
lcd.write(" ");
lcd.write(" ");
lcd.write(" ");
playSong(1,1.30);//This plays the "beep"
myservo.write(90);
myservo2.write(0);
millisCounter = millisNow;
displaying = 1;
} else {lcd.setCursor(10, 0);lcd.write(" ");lcd.setCursor(10, 1);lcd.write(" ");playSong(1,1.30);displaying=0;millisCounter = millisNow;}
}
else if(distance <= 30)
{
lcd.setCursor(10, 0);
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(4));
lcd.write(byte(6));
lcd.write(" ");
lcd.write(" ");
lcd.setCursor(10, 1);
lcd.write(byte(2));
lcd.write(byte(3));
lcd.write(byte(5));
lcd.write(byte(7));
lcd.write(" ");
lcd.write(" ");
playSong(2,2.07);
myservo.write(0);
myservo2.write(90);
}
else if(distance <= 70){
lcd.setCursor(10, 0);
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(4));
lcd.write(byte(6));
lcd.write(byte(6));
lcd.write(" ");
lcd.setCursor(10, 1);
lcd.write(byte(2));
lcd.write(byte(3));
lcd.write(byte(5));
lcd.write(byte(7));
lcd.write(byte(7));
lcd.write(" ");
playSong(3,3.60);
myservo.write(0);
myservo2.write(90);
}
else if(distance <= 400){
lcd.setCursor(10, 0);
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(4));
lcd.write(byte(6));
lcd.write(byte(6));
lcd.write(byte(6));
lcd.setCursor(10, 1);
lcd.write(byte(2));
lcd.write(byte(3));
lcd.write(byte(5));
lcd.write(byte(7));
lcd.write(byte(7));
lcd.write(byte(7));
playSong(4,3.60);
myservo.write(0);
myservo2.write(90);
}
}
}
share tutorial dong gan
Cara buat nya gimana gan?share dong