Rabu, 31 Maret 2021

Cara menghiting RPM dengan satu interupt revolusi

Coding untuk hitung RPM  dengan satu interupt satu revolusi






CATATAN:
  1. Hubungkan pin VCC pada LCD i2C ke pin 5V Arduino
  2. Hubungkan pin GND pada LCD i2C ke pin GND Arduino
  3. Hubungkan pin SCL pada LCD i2C ke pin SCL (atau bisa pake pin A5) Arduino
  4. Hubungkan pin SDA pada LCD i2C ke pin SDA (atau bisa pake pin A4) Arduino

/*
* http://elimelecsarduinoprojects.blogspot.co.id/2013/06/measure-rpms-arduino.html
*/
#include<LiquidCrystal.h>
//LiquidCrystal lcd(12,11,6,5,4,3);
LiquidCrystal lcd(12, 11, 5, 4, 3, 10);

volatile int rpmcount = 0;  //see http://arduino.cc/en/Reference/Volatile
int rpm = 0;
unsigned long lastmillis = 0;

void setup(){
 Serial.begin(9600); 
 lcd.begin(16,2); 
 attachInterrupt(0, rpm_fan, FALLING);//interrupt cero (0) is on pin two(2).
}

void loop(){

 if (millis() - lastmillis == 1000){  /*Uptade every one second, this will be equal to reading frecuency (Hz).*/

 detachInterrupt(0);    //Disable interrupt when calculating


 rpm = rpmcount * 60;  /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/

 Serial.print("RPM=\t"); //print the word "RPM" and tab.
 Serial.print(rpm); // print the rpm value.
 Serial.print("\t Hz=\t"); //print the word "Hz".
 Serial.println(rpmcount); /*print revolutions per second or Hz. And print new line or enter.*/

lcd.clear();
lcd.setCursor(1,0);
lcd.print("__TACHOMETER_V1");
lcd.setCursor(1,1);
lcd.print(rpm);
lcd.setCursor(6,1);
lcd.print(" RPM");
lcd.print("   ");

 rpmcount = 0; // Restart the RPM counter
 lastmillis = millis(); // Uptade lasmillis
 attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
  }
}


void rpm_fan(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
  rpmcount++;
}

Sabtu, 01 Februari 2020

PEMROGRAMAN ARDUINO - for loop dan while loop

/*
PEMROGRAMAN ARDUINO - for loop dan while loop


M-->lambat-->cepat(2secon-->10%)
H-->cepat-->lambat(2secon-->10%)
B-->lambat-->cepat(10 secon +10%)
*/
const int ledM=10;
const int ledH=11;
const int ledB=12;


void setup() {
pinMode(ledM,OUTPUT);
pinMode(ledH,OUTPUT);
pinMode(ledB,OUTPUT);

}

void loop() {

int i=1000;
while(i>=10){
  digitalWrite(ledM,1);
  delay(i);
  digitalWrite(ledM,0);
  delay(i);
  i = i-(i * 0.1);
   
}
int j=10;
while(j<=1000){
  digitalWrite(ledH,1);
  delay(j);
  digitalWrite(ledH,0);
  delay(j);
  j = j + (j * 0.1);
   
}
int x=1000;
while(x>=10){
  digitalWrite(ledB,1);
  delay(x);
  digitalWrite(ledB,0);
  delay(x);
  x = x - (x * 0.1);
   
}
}

Minggu, 01 April 2018

berikut RPM base sensor IR detection,
active low,
tempel pake isolasi double tape buat actifin buat ukur speed fan

#include<LiquidCrystal.h>
//LiquidCrystal lcd(12,11,6,5,4,3);
LiquidCrystal lcd(12, 11, 5, 4, 3, 10);
const byte blade = 1;
float value=0;
float rev=0;
int rpm;
int oldtime=0;
int time;

void isr() //interrupt service routine
{
rev++;
}

void setup()
{
lcd.begin(16,2);                //initialize LCD
attachInterrupt(0,isr,FALLING);  //attaching the interrupt
}

void loop()
{
delay(1000);
detachInterrupt(0);           //detaches the interrupt
time=millis()-oldtime;        //finds the time
rpm=(rev/time)*60000/blade;         //calculates rpm
oldtime=millis();             //saves the current time
rev=0;
lcd.clear();
lcd.setCursor(1,0);
lcd.print("___TACHOMETER___");
lcd.setCursor(1,1);
lcd.print(     rpm);
lcd.print(" RPM");
lcd.print("   ");
attachInterrupt(0,isr,FALLING);

}

Cara menghiting RPM dengan satu interupt revolusi

Coding untuk hitung RPM  dengan satu interupt satu revolusi CATATAN: Hubungkan pin VCC pada LCD i2C ke pin 5V Arduino Hubungkan pin GND pada...