Alat Monitor Kecepatan Angin (Anemometer) dann Arus DC INA219 Arduino
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor kecepatan angin dan arus dc dengan menggunakan Arduino, sensor yang digunakan yaitu sensor kecepatan angin dan INA219 untuk arus DC.untuk lebih jelasnya berikut adalah program dan komponennya.
a. Komponen yang dipakai
b. Program arduino IDE
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <Adafruit_INA219.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int INA_addr = 0x40;
Adafruit_INA219 ina219(INA_addr);
// 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;
int buzm = 11; //pin buzzer
float arusdc;
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
ina219.begin();
pinMode(buzm,OUTPUT);
digitalWrite(buzm,LOW);
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
}
arusdc = ina219.getCurrent_mA();
arusdc = arusdc /1000.0;
lcd.setCursor(0, 0);
lcd.print("Kec=");
lcd.print(velocity_ms);
lcd.print(" m/s ");
lcd.setCursor(0, 1);
lcd.print("I=");
lcd.print(arusdc);
lcd.print(" mA ");
delay(200);
}
void rpm_anemometer()
{
if (long(micros() - last_micros) >= 5000)
{ // time to debounce measures
rpmcount++;
last_micros = micros();
}
}
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <Adafruit_INA219.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int INA_addr = 0x40;
Adafruit_INA219 ina219(INA_addr);
// 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;
int buzm = 11; //pin buzzer
float arusdc;
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
ina219.begin();
pinMode(buzm,OUTPUT);
digitalWrite(buzm,LOW);
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
}
arusdc = ina219.getCurrent_mA();
arusdc = arusdc /1000.0;
lcd.setCursor(0, 0);
lcd.print("Kec=");
lcd.print(velocity_ms);
lcd.print(" m/s ");
lcd.setCursor(0, 1);
lcd.print("I=");
lcd.print(arusdc);
lcd.print(" mA ");
delay(200);
}
void rpm_anemometer()
{
if (long(micros() - last_micros) >= 5000)
{ // time to debounce measures
rpmcount++;
last_micros = micros();
}
}
c. VIDEO HASILNYA
No comments:
Post a Comment