//Sesuaikan dengan sistem anda
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(3, 2); // RX, TX untuk bluetooth
int SerialData;
int BluetoothData;
#include <Servo.h>
Servo myservo;
void setup()
{
Serial.begin(9600);
bluetooth.begin(38400);
//bluetooth.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(13,OUTPUT);
myservo.attach(5);
}
void loop()
{
if (Serial.available())
{
SerialData=Serial.read();
bluetooth.print("Diterima : ");
bluetooth.println(SerialData);
delay(100);
}
if (bluetooth.available())
{
BluetoothData=bluetooth.read();
Serial.print("Perintah Diterima : ");
Serial.println(BluetoothData);
delay(100);
if(BluetoothData=='1')
{
digitalWrite(13,HIGH);
delay(300);
bluetooth.println("Indikator ON");
//bluetooth.println("LED On D13 ON ! ");
//myservo.write(170);
}
if(BluetoothData=='0')
{
digitalWrite(13,LOW);
delay(300);
bluetooth.println("Indikator OFF");
//bluetooth.println("LED On D13 Off ! ");
//myservo.write(10);
}
if(BluetoothData=='2')
{
//digitalWrite(13,LOW);
//bluetooth.println("LED On D13 Off ! ");
myservo.write(10);
delay(300);
bluetooth.println("Servo di 10' ");
}
if(BluetoothData=='3')
{
//digitalWrite(13,LOW);
//bluetooth.println("LED On D13 Off ! ");
myservo.write(170);
delay(300);
bluetooth.println("Servo di 170' ");
/*
int i;
for(i=0;i<=10;i++)
{
int adc=analogRead(A0);
bluetooth.print("adc0= ");
bluetooth.println(adc);
delay(500);
}
*/
}
}
else
{
return;
}
delay(100);
}
Tidak ada komentar:
Posting Komentar