Kendali Servo dan Led via Bluetooth Handphone / Smartphone
Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah alat yang dapat mengendalikan 6 buah servo dan dua buah led dengan menggunakan bluetooth dan device handphone / smartphone. jadi alat ini menggunakan arduino nano sebagai kendalinya dan modul HC-05 untuk koneksi bluetooth. untuk lebih jelasnya berikut adalah koding dan komponennya.
a. Komponen Penyusun
#include<Wire.h>
#include <Servo.h>
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;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;
void setup(){
Serial.begin(9600);
myservo1.attach(3);
myservo1.write(100);
myservo2.attach(5);
myservo2.write(100);
myservo3.attach(6);
myservo3.write(100);
myservo4.attach(9);
myservo4.write(100);
myservo5.attach(10);
myservo5.write(100);
myservo6.attach(11);
myservo6.write(100);
pinMode(8,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(8,HIGH);
digitalWrite(12,HIGH);
}
void loop(){
if (Serial.available() > 0)
{
datain = Serial.parseInt();
Serial.println(datain);
//==========================================
if ((datain == 100)&&(a1 == 1))
{
a1 = 0;
datain = 0;
}
if ((datain == 100)&&(a1 == 0))
{
a1 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 200)&&(a2 == 1))
{
a2 = 0;
datain = 0;
}
if ((datain == 200)&&(a2 == 0))
{
a2 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 300)&&(a3 == 1))
{
a3 = 0;
datain = 0;
}
if ((datain == 300)&&(a3 == 0))
{
a3 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 400)&&(a4 == 1))
{
a4 = 0;
datain = 0;
}
if ((datain == 400)&&(a4 == 0))
{
a4 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 500)&&(a5 == 1))
{
a5 = 0;
datain = 0;
}
if ((datain == 500)&&(a5 == 0))
{
a5 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 600)&&(a6 == 1))
{
a6 = 0;
datain = 0;
}
if ((datain == 600)&&(a6 == 0))
{
a6 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 700)&&(a7 == 1))
{
digitalWrite(8,LOW);
a7 = 0;
datain = 0;
}
if ((datain == 700)&&(a7 == 0))
{
digitalWrite(8,HIGH);
a7 = 1;
datain = 0;
}
//==========================================
//==========================================
if ((datain == 800)&&(a8 == 1))
{
digitalWrite(12,LOW);
a8 = 0;
datain = 0;
}
if ((datain == 800)&&(a8 == 0))
{
digitalWrite(12,HIGH);
a8 = 1;
datain = 0;
}
//==========================================
}
if(a1 == 1){
myservo1.write(100);
delay(1000);
myservo1.write(150);
delay(1000);
}
if(a2 == 1){
myservo2.write(100);
delay(1000);
myservo2.write(150);
delay(1000);
}
if(a3 == 1){
myservo3.write(100);
delay(1000);
myservo3.write(150);
delay(1000);
}
if(a4 == 1){
myservo4.write(100);
delay(1000);
myservo4.write(150);
delay(1000);
}
if(a5 == 1){
myservo5.write(100);
delay(1000);
myservo5.write(150);
delay(1000);
}
if(a6 == 1){
myservo6.write(100);
delay(1000);
myservo6.write(150);
delay(1000);
}
}
d. VIDEO HASILNYA
No comments:
Post a Comment