Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses modul wireless yang sangat umum dijumpai di masyarakat atau di toko elektronik, yaitu RF LINK 433MHZ. modul ini sangat terjangkau sekali harganya dan juga jarak tempuh sensor ini mencapai 500 meter open area.sensor ini ada dua tipe yaitu transmitter dan receiver. untuk mengetahui lebih lanjut berikut adalah program dan skemanya.
download library: LINK DOWNLOAD
a. Arduino Mega
b. Modul Wireless RF-Link 433MHZ
c. Skema Receiver
d. skema transmitter
e. Program Arduino Terima Data
// RF 433MHz Modules (Receiver Circuit) #include <RH_ASK.h> // Serial Peripheral Interface (SPI) #include <SPI.h> // Needed to compile RH_ASK driver; void setup () { Serial.begin (9600); // Debugging ONLY if (!driver.init ()) Serial.println ("init failed"); } void loop () { uint8_t buf [12]; uint8_t buflen = sizeof (buf); if (driver.recv (buf, &buflen)) { // Non-blocking int i; // Message with a good cheksum received, dump it Serial.print ("Message: "); Serial.println ((char*) buf); } }
f. Program Arduino Kirim Data
// RF 433MHz Modules (Transmitter Circuit) #include <RH_ASK.h> // Serial Peripheral Interface (SPI) #include <SPI.h> // Needed to compile RH_ASK driver; void setup () { Serial.begin (9600); // Debugging ONLY if (!driver.init ()) Serial.println ("init failed"); } void loop () { const char *msg = "Hello World!"; driver.send ((uint8_t *) msg, strlen (msg)); driver.waitPacketSent (); delay (1000); }
g. Program Arduino Transmitter Untuk ON/OFF
#include "Wire.h"
#include <LiquidCrystal.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
RH_ASK driver;
int relay = 8;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
if (!driver.init())
Serial.println("init failed");
}
void loop() {
int sensorpir = analogRead(A0);
int sensorValue = analogRead(A7);
float voltage = sensorValue * (5.0 / 1023.0);
float suhu = voltage * 100 ;
if (sensorpir > 100) {
digitalWrite(relay, HIGH);
lcd.setCursor(0, 0);
lcd.print("Terdeteksi");
lcd.setCursor(0, 1);
lcd.print("HIDUPKAN AC");
delay(500);
lcd.clear();
} else {
if (suhu >= 20){
//on AC 2
const char *msg = "255";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
if (suhu <= 18){
//OFF AC 2
const char *msg = "999";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
lcd.setCursor(0, 0);
lcd.print("suhu = ");
lcd.print(suhu);
lcd.setCursor(0, 1);
lcd.print("PIR = ");
lcd.print(sensorpir);
delay(500);
lcd.clear();
}
}
h. Program Arduino Terima data ON/OFF
#include <LiquidCrystal.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
RH_ASK driver;
int relay = 8;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
if (!driver.init())
Serial.println("init failed");
}
void loop() {
int sensorpir = analogRead(A0);
int sensorValue = analogRead(A7);
float voltage = sensorValue * (5.0 / 1023.0);
float suhu = voltage * 100 ;
if (sensorpir > 100) {
digitalWrite(relay, HIGH);
lcd.setCursor(0, 0);
lcd.print("Terdeteksi");
lcd.setCursor(0, 1);
lcd.print("HIDUPKAN AC");
delay(500);
lcd.clear();
} else {
if (suhu >= 20){
//on AC 2
const char *msg = "255";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
if (suhu <= 18){
//OFF AC 2
const char *msg = "999";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
}
lcd.setCursor(0, 0);
lcd.print("suhu = ");
lcd.print(suhu);
lcd.setCursor(0, 1);
lcd.print("PIR = ");
lcd.print(sensorpir);
delay(500);
lcd.clear();
}
}
h. Program Arduino Terima data ON/OFF
#include "Wire.h"
#include <LiquidCrystal.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int relay = 8;
String a;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
if (!driver.init())
Serial.println("init failed");
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
float suhu = voltage * 100 ;
lcd.setCursor(0, 0);
lcd.print("suhu = ");
lcd.print(suhu);
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Suhu: ");
Serial.println(suhu);
Serial.print("Message: ");
Serial.println((char*)buf);
lcd.setCursor(0, 1);
lcd.print((char*)buf);
int nilai = atoi((char*)buf);
// if (nilai < 500 ){
// digitalWrite(relay, HIGH);
// }
// if (nilai > 500 ){
// digitalWrite(relay, LOW);
// }
}
delay(500);
lcd.clear();
}
#include <LiquidCrystal.h>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int relay = 8;
String a;
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
if (!driver.init())
Serial.println("init failed");
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
float suhu = voltage * 100 ;
lcd.setCursor(0, 0);
lcd.print("suhu = ");
lcd.print(suhu);
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Suhu: ");
Serial.println(suhu);
Serial.print("Message: ");
Serial.println((char*)buf);
lcd.setCursor(0, 1);
lcd.print((char*)buf);
int nilai = atoi((char*)buf);
// if (nilai < 500 ){
// digitalWrite(relay, HIGH);
// }
// if (nilai > 500 ){
// digitalWrite(relay, LOW);
// }
}
delay(500);
lcd.clear();
}
i. VIDEO HASILNYA
No comments:
Post a Comment