Mengendalikan 8 buah Relay dengan Bluetooth dan menyimpan status relay pada memory EEPROM
Pada Tutorial kali ini kita akan membuat sebuah project pengendalian beban/relay secara wireless menggunakan Bluetooth dengan control Hp Android.
Disini kita menggunakan memory EEPROM internal atmega328 (Arduino Uno) untuk menyimpan posisi terakhir dari relay.Jadi apabila controller mati yang diakibatkan dari Power OFF (misal listrik mati/pemadaman PLN) atau sistem mengalami Restart maka SEMUA posisi Relay akan dikembalikan seperti posisi terakhir sebelum sistem mati.
A.Bahan dan Module yang dibutuhkan
-1Unit Relay Module 5V 8 Channel-1Unit Bluetooth Module (HC-05 atau HC-06)
-1Unit Arduino Uno/Nano/Pro mini/Mega
-Hp Android dengan Aplikasi Arduino Bluetooth Kontrol
Silahkan download aplikasinya pada link berikut :
https://play.google.com/store/apps/details?id=com.app.control
Berikut screen shoot aplikasinya :
B.Wiring
Perhatikan Gambar pada header artikel ini.Jika kita tidak menggunakan Software Serial Berarti kita menghubungkan module bluetooth
ke pin TX RX (D0 D1),artinya saat melakukan Upload program dari Arduino IDE kita harus melepas sambungan Module Blutooth k Arduino sementara,setelah proses upload selesai kita dapat menghubungkanya kembali.
C.Library
Untuk Tutorial kali ini kita tidak membutuhkan library Eksternal untuk ditambahkan ke sistem arduino IDE.Kita hanya menggunakan library EEPROM yang sudah include pada installer software Arduino.D.Sourch Code
Berikut Sourch Code Untuk Tutorial kali ini.Silahkan copy paste code berikut ke dalam Arduino IDE anda kemudian Upload ke Arduino Board (jangan lupa lepas module bluetothnya terlebih dulu jika menggunakan pin TX RX)#include <EEPROM.h>
#define ON 0
#define OFF 1
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
const int relay4 = 5;
const int relay5 = 6;
const int relay6 = 7;
const int relay7 = 8;
const int relay8 = 9;
byte State1 = 1;
byte State2 = 1;
byte State3 = 1;
byte State4 = 1;
byte State5 = 1;
byte State6 = 1;
byte State7 = 1;
byte State8 = 1;
char input;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(F("Control 8 Channel relay via Bluetooth"));
pinMode(relay1,OUTPUT);digitalWrite (relay1,OFF);
pinMode(relay2,OUTPUT);digitalWrite (relay2,OFF);
pinMode(relay3,OUTPUT);digitalWrite (relay3,OFF);
pinMode(relay4,OUTPUT);digitalWrite (relay4,OFF);
pinMode(relay5,OUTPUT);digitalWrite (relay5,OFF);
pinMode(relay6,OUTPUT);digitalWrite (relay6,OFF);
pinMode(relay7,OUTPUT);digitalWrite (relay7,OFF);
pinMode(relay8,OUTPUT);digitalWrite (relay8,OFF);
ReadEEPROM ();
}
void loop() {
// put your main code here, to run repeatedly:
bluetooth();
}
void bluetooth() {
if (Serial.available()>0)
{
input= Serial.read();
if (input == 'A') {
digitalWrite (relay1,ON);
EEPROM.write(1, 0);
Serial.println("relay 1 ON by Bluetooth");}
if (input == 'a') {
digitalWrite (relay1,OFF);
EEPROM.write(1, 1);
Serial.println("relay 1 OFF by Bluetooth");}
if (input == 'B') {
digitalWrite (relay2,ON);
EEPROM.write(2, 0);
Serial.println("relay 2 ON by Bluetooth");}
if (input == 'b') {
digitalWrite (relay2,OFF);
EEPROM.write(2, 1);
Serial.println("relay 2 OFF by Bluetooth");}
if (input == 'C') {
digitalWrite (relay3,ON);
EEPROM.write(3, 0);
Serial.println("relay 3 ON by Bluetooth");}
if (input == 'c') {
digitalWrite (relay3,OFF);
EEPROM.write(3, 1);
Serial.println("relay 3 OFF by Bluetooth");}
if (input == 'D') {
digitalWrite (relay4,ON);
EEPROM.write(4, 0);
Serial.println("relay 4 ON by Bluetooth");}
if (input == 'd') {
digitalWrite (relay4,OFF);
EEPROM.write(4, 1);
Serial.println("relay 4 OFF by Bluetooth");}
if (input == 'E') {
digitalWrite (relay5,ON);
EEPROM.write(5, 0);
Serial.println("relay 5 ON by Bluetooth");}
if (input == 'e') {
digitalWrite (relay5,OFF);
EEPROM.write(5, 1);
Serial.println("relay 5 OFF by Bluetooth");}
if (input == 'F') {
digitalWrite (relay6,ON);
EEPROM.write(6, 0);
Serial.println("relay 6 ON by Bluetooth");}
if (input == 'f') {
digitalWrite (relay6,OFF);
EEPROM.write(6, 1);
Serial.println("relay 6 OFF by Bluetooth");}
if (input == 'G') {
digitalWrite (relay7,ON);
EEPROM.write(7, 0);
Serial.println("relay 7 ON by Bluetooth");}
if (input == 'g') {
digitalWrite (relay7,OFF);
EEPROM.write(7, 1);
Serial.println("relay 7 OFF by Bluetooth");}
if (input == 'H') {
digitalWrite (relay8,ON);
EEPROM.write(8, 0);
Serial.println("relay 8 ON by Bluetooth");}
if (input == 'h') {
digitalWrite (relay8,OFF);
EEPROM.write(8, 1);
Serial.println("relay 8 OFF by Bluetooth");}
}
}
void ReadEEPROM (){
State1 = EEPROM.read(1);
State2 = EEPROM.read(2);
State3 = EEPROM.read(3);
State4 = EEPROM.read(4);
State5 = EEPROM.read(5);
State6 = EEPROM.read(6);
State7 = EEPROM.read(7);
State8 = EEPROM.read(8);
digitalWrite(relay1,State1);
Serial.print(F("Posisi Terakhir relay1 = "));
if(State1==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay2,State2);
Serial.print(F("Posisi Terakhir relay2 = "));
if(State2==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay3,State3);
Serial.print(F("Posisi Terakhir relay3 = "));
if(State3==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay4,State4);
Serial.print(F("Posisi Terakhir relay4 = "));
if(State4==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay5,State5);
Serial.print(F("Posisi Terakhir relay5 = "));
if(State5==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay6,State6);
Serial.print(F("Posisi Terakhir relay6 = "));
if(State6==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay7,State7);
Serial.print(F("Posisi Terakhir relay7 = "));
if(State7==0){Serial.println("ON");} else {Serial.println("OFF");}
digitalWrite(relay8,State8);
Serial.print(F("Posisi Terakhir relay8 = "));
if(State8==0){Serial.println("ON");} else {Serial.println("OFF");}
}
void relayON (uint8_t r) {
digitalWrite (r+1,ON);
EEPROM.write(r, 1);
Serial.print("Relay ");
Serial.print(r);
Serial.println(" ON by Bluetooth");
}
void relayOFF (uint8_t r) {
digitalWrite (r+1,OFF);
EEPROM.write(r, 0);
Serial.print("Relay ");
Serial.print(r);
Serial.println(" OFF by Bluetooth");
}
E.Test & Trial
-Rangkai Module dan Arduino sesuai wiring-Upload sketch program diatas
-Install aplikasi "Arduino Device Control" di Hp Android anda
-Buka aplikasi "Arduino Device Conrol"
-Connect to / hubungkan aplikasi dengan module bluetooth yang terpasang di Arduino
apabila module bluetooth anda belum terlihat pada daftar perangkat yang tampil pada aplikasi ini
silahkan test pairing terlebih dahulu melalui menu Pengaturan/Setting->Bluetooth->Cari perangkat
kemudian hubungkan atau pasangkan dan buka kembali aplikasi Arduino Bluetooth Controllernya.
Control 8 Channel Relay with Bluetooth & EEPROM
Reviewed by MCH
on
October 02, 2016
Rating:
No comments: