b. Program Arduino IDE
#include <Wire.h> // i2C Conection Library
#include <LiquidCrystal_I2C.h> //i2C LCD Library
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;
int buzm = 11; //pin buzzer
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
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
}
lcd.setCursor(0, 0);
lcd.print("Kec=");
lcd.print(velocity_ms);
lcd.print(" m/s ");
if(velocity_ms > 5){
lcd.setCursor(0, 1);
lcd.print("Tinggi ");
digitalWrite(buzm,HIGH);
}
if((velocity_ms >= 3)&&(velocity_ms <= 5)){
lcd.setCursor(0, 1);
lcd.print("Sedang ");
digitalWrite(buzm,LOW);
}
if(velocity_ms < 3){
lcd.setCursor(0, 1);
lcd.print("Rendah ");
digitalWrite(buzm,LOW);
}
}
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