Translate

Monitor Arus AC Sensor SCT-013 Komunikasi Wireless LoRa Module ARDUINO

 Monitor Arus AC Sensor SCT-013 Komunikasi Wireless LoRa Module ARDUINO 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sepasang modul LoRa transmitter dan receiver untuk komunikasi datanya. sensor yang dipakai yaitu SCT-013 untuk mengukur arus AC atau IAC. untuk lebih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Uno




b. Modul Wireless LoRa




c. Sensor SCT-013




d. LCD + I2C






e. Program Arduino Transmitter

#include <SPI.h>
#include <LoRa.h>

int vin = 0;
int iin = 0;
int vout;
float kal;

unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

int a = 0;
int zero = 1;


void setup() {
  Serial.begin(9600);
   
  // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library

  // you can choose a prescaler from above.
  // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_128;    // set our own prescaler to 64

  while (!Serial);

  Serial.println("LoRa Sender");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {

unsigned int i1;
  unsigned int z1;
  z1 = 0;
 
  unsigned int i2;
  unsigned int z2;
  z2 = 0;
 
  unsigned int i3;
  unsigned int z3;
  z3 = 0;
 
  unsigned int i4;
  unsigned int z4;
  z4 = 0;
  
  for(i1=0;i1<100;i1++) {
    start_times[i1] = micros();
    values[i1] = analogRead(A0);            

  if (values[i1] >= z1) {
  z1 = values[i1];
  }
 
    stop_times[i1] = micros();
  }
 
    for(i2=0;i2<100;i2++) {
    start_times[i2] = micros();
    values[i2] = analogRead(A0);            

  if (values[i2] >= z2) {
  z2 = values[i2];
  }
 
    stop_times[i2] = micros();
  }
 
 
    for(i3=0;i3<100;i3++) {
    start_times[i3] = micros();
    values[i3] = analogRead(A0);            

  if (values[i3] >= z3) {
  z3 = values[i3];
  }
 
    stop_times[i3] = micros();
  }
 
 
    for(i4=0;i4<100;i4++) {
    start_times[i4] = micros();
    values[i4] = analogRead(A0);            

  if (values[i4] >= z4) {
  z4 = values[i4];
  }
 
    stop_times[i4] = micros();
  }
 

   int vin1 = z1 ;
   int vin2 = z2 ;
   int vin3 = z3 ;
   int vin4 = z4 ;

  z1 = 0;
  z2 = 0;
  z3 = 0;
  z4 = 0;

if((vin1 > vin2)&&(vin1 > vin3)&&(vin1 > vin4)){
  vout = vin1;
  kal = (vout - 512.0) / 7.0;
}
else if((vin2 > vin1)&&(vin2 > vin3)&&(vin2 > vin4)){
  vout = vin2;
  kal = (vout - 512.0) / 7.0;
}
else if((vin3 > vin1)&&(vin3 > vin2)&&(vin3 > vin4)){
  vout = vin3;
 kal = (vout - 512.0) / 7.0;
}
else if((vin4 > vin1)&&(vin4 > vin2)&&(vin4 > vin3)){
  vout = vin4;
 kal = (vout - 512.0) / 7.0;
}

if(kal < 0){
kal = 0;
}

int arusku = kal * 100; 

  Serial.print("I= ");
  Serial.println(arusku);

  // send packet
  LoRa.beginPacket();
  LoRa.print(arusku);
  LoRa.endPacket();
 
  delay(200);
}




f. Program Arduino Receiver

#include <SPI.h>
#include <LoRa.h>
#include "Wire.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

String inString = "";    // string to hold input
int val = 0;

void setup() {

  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Receiver");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {

  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) { 
    // read packet    
    while (LoRa.available())
    {
      int inChar = LoRa.read();
      inString += (char)inChar;
      val = inString.toInt();       
    }
    inString = "";     
    LoRa.packetRssi();    
  }
  
Serial.println(val); 

float ix = val/100.0;

lcd.setCursor(0,0);
lcd.print("I = ");
lcd.print(ix);
lcd.print("   ");

delay(200);
}



g. Cara kalibrasi

1. Siapkan Ampermeter dan Ms. Excel lalu catat  nilai yang dihasilkan 
2. Klik Add trendline lalu pilih linier
3. Lalu masukkan rumus yg dihasilkan





h. VIDEO HASILNYA








No comments:

Post a Comment