Translate

Monitor Kecepatan Angin (Wind Speed) Anemometer Interface P10 RGB HUB75 Wireless Hc-12 IOT BLYNK 2.0

Monitor Kecepatan Angin (Wind Speed) Anemometer Interface P10 RGB HUB75 Wireless Hc-12 IOT BLYNK 2.0


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor kecepatan angin dengan interface P10 RGB hub75. mikrokontroller yang dipakai yaitu Arduino Uno pada bagian transmitter dan receiver menggunakan Arduino Wifi. untuk bisa mmonitor jarak jauh maka dipakai server Blynk 2.0. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema Alat




b. Program Transmitter

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <SoftwareSerial.h>

SoftwareSerial HC12(10, 11);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// anemometer parameters
volatile byte rpmcount; // count signals
volatile unsigned long last_micros;
unsigned long timeold;
unsigned long timemeasure = 2.00; // seconds
int timetoSleep = 1;               // minutes
unsigned long sleepTime = 15;      // minutes
unsigned long timeNow;
int countThing = 0;
int GPIO_pulse = 2; // Arduino = D2
float rpm, rps;     // frequencies
float radius = 0.1; // meters - measure of the lenght of each the anemometer wing
float velocity_kmh; // km/h
float velocity_ms;  //m/s
float omega = 0;    // rad/s
float calibration_value = 2.0;

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  HC12.begin(9600);  
   
  pinMode(GPIO_pulse, INPUT_PULLUP);
  digitalWrite(GPIO_pulse, LOW);

  detachInterrupt(digitalPinToInterrupt(GPIO_pulse));                         // force to initiate Interrupt on zero
  attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); //Initialize the intterrupt pin
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  timeNow = 0;
 
}

void loop()
{
  //Measure RPM
  if ((millis() - timeold) >= timemeasure * 1000)
  {
    //countThing++;
    detachInterrupt(digitalPinToInterrupt(GPIO_pulse)); // Disable interrupt when calculating
    rps = float(rpmcount) / float(timemeasure);         // rotations per second
    rpm = 60 * rps;                                     // rotations per minute
    omega = 2 * PI * rps;                               // rad/s
    velocity_ms = omega * radius * calibration_value;   // m/s
    velocity_kmh = velocity_ms * 3.6;                   // km/h
        
    timeold = millis();
    rpmcount = 0;
    attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); // enable interrupt
  }

  lcd.setCursor(0, 0);
  lcd.print("Kec=");
  lcd.print(velocity_ms);
  lcd.print(" m/s ");

  HC12.write(velocity_ms * 100);  
 delay(1000); 
}

void rpm_anemometer()
{
  if (long(micros() - last_micros) >= 5000)
  { // time to debounce measures
    rpmcount++;
    last_micros = micros();
  }
}


c. Program Receiver Arduino Uno

#include <Wire.h>
#include <Adafruit_GFX.h>   
#include <RGBmatrixPanel.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

int val;
float nilaims;
float nilaikmh;
int nilaimsx;
int nilaikmhx;

int bta = 13;
int btb = 12;
int btax;
int btbx;
int nilaimaxkmh, nilaimaxms;
int mode;

SoftwareSerial HC12(10, 11);  

void setup()
{
  Serial.begin(9600);
  pinMode(bta,INPUT_PULLUP);
  pinMode(btb,INPUT_PULLUP);
  HC12.begin(9600); 
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  matrix.begin();
  matrix.setTextWrap(true); // Allow text to run off right edge
  matrix.setTextSize(1);
}

void loop()
{

btax = digitalRead(bta);
btbx = digitalRead(btb);

if((btax == 0)&&(btbx == 0)){
  lcd.clear();
  delay(1000);
  setting1();
  setting2();
}
    
  while (HC12.available()) {        // If HC-12 has data
    val = HC12.read();
    nilaims = val / 100.0;
    //Serial.println(HC12.read());      // Send the data to Serial monitor
  } 

  nilaikmh = nilaims * 3.6;
  nilaims = nilaikmh / 3.6;

if(btax == 0){
mode++;
}

if(mode > 1){
  mode = 0;
}

if(mode == 0){
  lcd.setCursor(0, 0);
  lcd.print("Kec= ");
  lcd.print(nilaims);
  lcd.print(" m/s   ");

if(nilaims < nilaimaxms){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(0, 1, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaims);
}


if(nilaims >= nilaimaxms){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(1, 0, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaims);
}

}

if(mode == 1){
  lcd.setCursor(0, 0);
  lcd.print("Kec= ");
  lcd.print(nilaikmh);
  lcd.print(" km/h  ");

if(nilaikmh >= nilaimaxkmh){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(1, 0, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaikmh);
}

if(nilaikmh < nilaimaxkmh){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(0, 1, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaikmh);
}
 
}

nilaikmhx = nilaikmh * 100;
nilaimsx = nilaims * 100;

  lcd.setCursor(0, 1);
  lcd.print(nilaimaxms);
  lcd.print(" / ");
  lcd.print(nilaimaxkmh);
  lcd.print(" / ");

  Serial.print("*");
  Serial.print(nilaimsx);
  Serial.print(",");
  Serial.print(nilaikmhx);
  Serial.println("#");  

delay(1000);
}


void setting1(){
  
btax = digitalRead(bta);
btbx = digitalRead(btb);  

if(btax == 0){
 delay(200); 
 nilaimaxms++; 
}

if(btbx == 0){
 delay(200); 
 nilaimaxms--; 
}

if((btax == 0)&&(btbx == 0)){
 delay(200); 
 lcd.clear();
 return;
}

  lcd.setCursor(0, 0);
  lcd.print("Kec1=");
  lcd.print(nilaimaxms);
  lcd.print(" m/s ");  
  
setting1();  
}


void setting2(){
  
btax = digitalRead(bta);
btbx = digitalRead(btb);  

if(btax == 0){
 delay(200); 
 nilaimaxkmh++; 
}

if(btbx == 0){
 delay(200); 
 nilaimaxkmh--; 
}

if((btax == 0)&&(btbx == 0)){
 delay(200); 
 lcd.clear();
 return;
}

  lcd.setCursor(0, 0);
  lcd.print("Kec2=");
  lcd.print(nilaimaxkmh);
  lcd.print(" km/h ");  
  
setting2();  
}


d. Program Receiver ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6Xd6mRxxx"
#define BLYNK_TEMPLATE_NAME "anemometer"
#define BLYNK_AUTH_TOKEN "tSFV2OuvES_o9gLE77FjEERbD3L0xxxx"

#define BLYNK_PRINT Serial    
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

float ms;
float kmh;

float datain1;
float datain2;

String dataIn;
String dt[10];
int i;
boolean parsing=false;
int pinValue;
int pinValue2;
int pinValue3;

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

void sendSensor()
{

 Blynk.virtualWrite(V0, ms);
 Blynk.virtualWrite(V1, kmh);
 delay(1000);
}

void setup()
{
  dataIn=""; 
  // Debug console
 Serial.begin(9600);
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, sendSensor);
}

void loop()
{

while(Serial.available()>0) {
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
  parsingData();
    
  Blynk.run();
  timer.run();
}

}

void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

datain1 = dt[0].toInt();
datain2 = dt[1].toInt();

 ms = datain1 / 100.0;
 kmh = datain2 / 100.0;

}


 
e. VIDEO HASILNYA





No comments:

Post a Comment