Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat kendali ON/OFF Relay yang dapat dikendalikan menggunakan HP Android, alat ini dilengkapi dengan wireless bluetooth untuk komunikasi dari alat ke HP Android, modul bluetooth yang digunakan adalah HC-05. untuk lebih jelasnya berikut adalah skema dan programnya.
a. Minimum System Arduino + Relay
b. Bluetooth HC-05
c. Program Arduino IDE
int datain;
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int a5 = 0;
int a6 = 0;
int a7 = 0;
int a8 = 0;
int a9 = 0;
int a10 = 0;
int a11 = 0;
int a12 = 0;
int a13 = 0;
int a14 = 0;
int a15 = 0;
void setup(){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0)
{
datain = Serial.parseInt();
Serial.print(datain);
//==========================================
if ((datain == 100)&&(a1 == 0))
{
digitalWrite(2,HIGH);
a1 = 1;
datain = 0;
}
if ((datain == 100)&&(a1 == 1))
{
digitalWrite(2,LOW);
a1 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 200)&&(a2 == 0))
{
digitalWrite(3,HIGH);
a2 = 1;
datain = 0;
}
if ((datain == 200)&&(a2 == 1))
{
digitalWrite(3,LOW);
a2 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 300)&&(a3 == 0))
{
digitalWrite(4,HIGH);
a3 = 1;
datain = 0;
}
if ((datain == 300)&&(a3 == 1))
{
digitalWrite(4,LOW);
a3 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 400)&&(a4 == 0))
{
digitalWrite(5,HIGH);
a4 = 1;
datain = 0;
}
if ((datain == 400)&&(a4 == 1))
{
digitalWrite(5,LOW);
a4 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 500)&&(a5 == 0))
{
digitalWrite(6,HIGH);
a5 = 1;
datain = 0;
}
if ((datain == 500)&&(a5 == 1))
{
digitalWrite(6,LOW);
a5 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 600)&&(a6 == 0))
{
digitalWrite(7,HIGH);
a6 = 1;
datain = 0;
}
if ((datain == 600)&&(a6 == 1))
{
digitalWrite(7,LOW);
a6 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 700)&&(a7 == 0))
{
digitalWrite(8,HIGH);
a7 = 1;
datain = 0;
}
if ((datain == 700)&&(a7 == 1))
{
digitalWrite(8,LOW);
a7 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 800)&&(a8 == 0))
{
digitalWrite(9,HIGH);
a8 = 1;
datain = 0;
}
if ((datain == 800)&&(a8 == 1))
{
digitalWrite(9,LOW);
a8 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 900)&&(a9 == 0))
{
digitalWrite(10,HIGH);
a9 = 1;
datain = 0;
}
if ((datain == 900)&&(a9 == 1))
{
digitalWrite(10,LOW);
a9 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 110)&&(a10 == 0))
{
digitalWrite(A0,HIGH);
a10 = 1;
datain = 0;
}
if ((datain == 110)&&(a10 == 1))
{
digitalWrite(A0,LOW);
a10 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 120)&&(a11 == 0))
{
digitalWrite(A1,HIGH);
a11 = 1;
datain = 0;
}
if ((datain == 120)&&(a11 == 1))
{
digitalWrite(A1,LOW);
a11 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 130)&&(a12 == 0))
{
digitalWrite(A2,HIGH);
a12 = 1;
datain = 0;
}
if ((datain == 130)&&(a12 == 1))
{
digitalWrite(A2,LOW);
a12 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 140)&&(a13 == 0))
{
digitalWrite(A3,HIGH);
a13 = 1;
datain = 0;
}
if ((datain == 140)&&(a13 == 1))
{
digitalWrite(A3,LOW);
a13 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 150)&&(a14 == 0))
{
digitalWrite(A4,HIGH);
a14 = 1;
datain = 0;
}
if ((datain == 150)&&(a14 == 1))
{
digitalWrite(A4,LOW);
a14 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 160)&&(a15 == 0))
{
digitalWrite(A5,HIGH);
a15 = 1;
datain = 0;
}
if ((datain == 160)&&(a15 == 1))
{
digitalWrite(A5,LOW);
a15 = 0;
datain = 0;
}
//==========================================
}
}
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int a5 = 0;
int a6 = 0;
int a7 = 0;
int a8 = 0;
int a9 = 0;
int a10 = 0;
int a11 = 0;
int a12 = 0;
int a13 = 0;
int a14 = 0;
int a15 = 0;
void setup(){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0)
{
datain = Serial.parseInt();
Serial.print(datain);
//==========================================
if ((datain == 100)&&(a1 == 0))
{
digitalWrite(2,HIGH);
a1 = 1;
datain = 0;
}
if ((datain == 100)&&(a1 == 1))
{
digitalWrite(2,LOW);
a1 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 200)&&(a2 == 0))
{
digitalWrite(3,HIGH);
a2 = 1;
datain = 0;
}
if ((datain == 200)&&(a2 == 1))
{
digitalWrite(3,LOW);
a2 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 300)&&(a3 == 0))
{
digitalWrite(4,HIGH);
a3 = 1;
datain = 0;
}
if ((datain == 300)&&(a3 == 1))
{
digitalWrite(4,LOW);
a3 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 400)&&(a4 == 0))
{
digitalWrite(5,HIGH);
a4 = 1;
datain = 0;
}
if ((datain == 400)&&(a4 == 1))
{
digitalWrite(5,LOW);
a4 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 500)&&(a5 == 0))
{
digitalWrite(6,HIGH);
a5 = 1;
datain = 0;
}
if ((datain == 500)&&(a5 == 1))
{
digitalWrite(6,LOW);
a5 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 600)&&(a6 == 0))
{
digitalWrite(7,HIGH);
a6 = 1;
datain = 0;
}
if ((datain == 600)&&(a6 == 1))
{
digitalWrite(7,LOW);
a6 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 700)&&(a7 == 0))
{
digitalWrite(8,HIGH);
a7 = 1;
datain = 0;
}
if ((datain == 700)&&(a7 == 1))
{
digitalWrite(8,LOW);
a7 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 800)&&(a8 == 0))
{
digitalWrite(9,HIGH);
a8 = 1;
datain = 0;
}
if ((datain == 800)&&(a8 == 1))
{
digitalWrite(9,LOW);
a8 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 900)&&(a9 == 0))
{
digitalWrite(10,HIGH);
a9 = 1;
datain = 0;
}
if ((datain == 900)&&(a9 == 1))
{
digitalWrite(10,LOW);
a9 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 110)&&(a10 == 0))
{
digitalWrite(A0,HIGH);
a10 = 1;
datain = 0;
}
if ((datain == 110)&&(a10 == 1))
{
digitalWrite(A0,LOW);
a10 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 120)&&(a11 == 0))
{
digitalWrite(A1,HIGH);
a11 = 1;
datain = 0;
}
if ((datain == 120)&&(a11 == 1))
{
digitalWrite(A1,LOW);
a11 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 130)&&(a12 == 0))
{
digitalWrite(A2,HIGH);
a12 = 1;
datain = 0;
}
if ((datain == 130)&&(a12 == 1))
{
digitalWrite(A2,LOW);
a12 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 140)&&(a13 == 0))
{
digitalWrite(A3,HIGH);
a13 = 1;
datain = 0;
}
if ((datain == 140)&&(a13 == 1))
{
digitalWrite(A3,LOW);
a13 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 150)&&(a14 == 0))
{
digitalWrite(A4,HIGH);
a14 = 1;
datain = 0;
}
if ((datain == 150)&&(a14 == 1))
{
digitalWrite(A4,LOW);
a14 = 0;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 160)&&(a15 == 0))
{
digitalWrite(A5,HIGH);
a15 = 1;
datain = 0;
}
if ((datain == 160)&&(a15 == 1))
{
digitalWrite(A5,LOW);
a15 = 0;
datain = 0;
}
//==========================================
}
}
d. Program Android
e. VIDEO HASILNYA
No comments:
Post a Comment