Desain Hardware
alat :
led 1 terhubung ke pin 2
led 2 terhubung ke pin 3
Relay 1 terhubung ke pin 4 ( untuk menggerakkan pintu buka)
Relay 2 terhubung ke pin 5 ( untuk menggerakkan pintu tutup)
Desain tampilan depan Mit App Inventor
Desain tampilan belakang Mit App Inventor (bagian program)
Program arduino
int nilai;
void setup() {
pinMode (2,OUTPUT);
pinMode (3,OUTPUT);
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
if( Serial.available() >0 ) {
nilai = Serial.read(); // Membaca nilai blutut
if ( nilai ==1 ) digitalWrite( 2, HIGH );
if ( nilai ==2 ) digitalWrite( 2, LOW );
if ( nilai ==5 ) digitalWrite( 3, HIGH );
if ( nilai ==6 ) digitalWrite( 3, LOW );
if ( nilai ==3 ) digitalWrite( 4, HIGH );
if ( nilai ==4 ) digitalWrite( 5, HIGH );
if ( nilai ==7 ) { digitalWrite( 4, LOW ); digitalWrite( 5, LOW ); }
delay (200);
} }
Kelemahan alat yaitu pintu pagar tidak dapat auto stop.
saran tambah sesor limit switch.
Program kedua
int ls1, ls2, nilai ;
void setup() {
pinMode (12,INPUT);
pinMode (13,INPUT);
pinMode (2,OUTPUT);
pinMode (3,OUTPUT);
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
if( Serial.available() >0 ) {
nilai = Serial.read(); // Membaca nilai blutut
// if (n!= nilai ) { n=nilai ;
if ( nilai ==1 ) digitalWrite( 2, HIGH );
if ( nilai ==2 ) digitalWrite( 2, LOW );
if ( nilai ==5 ) digitalWrite( 3, HIGH );
if ( nilai ==6 ) digitalWrite( 3, LOW );
if ( nilai ==3 ) digitalWrite( 4, HIGH ) ;
if ( nilai ==4 ) digitalWrite( 5, HIGH );
if ( nilai ==7 ) { digitalWrite( 4, LOW ); digitalWrite( 5, LOW ); }}
// }
ls1= digitalRead (12);
ls2= digitalRead (13);
if (ls1== HIGH ) {
digitalWrite( 4, LOW );
}
if (ls2== HIGH ) {
digitalWrite( 5, LOW );
}
delay (200);
nilai =0;
}
Sudah ada limit switch tapi masih bisa buka tutup nyala bersama