Programming: heading views : 0

Copy And Paste Code For Arduino Uno Tachometer

#include <LiquidCrystal.h>
//Assigning pins
int ledPin = 13;
int in_ir = 7; 
int motor = 6; 
int adc_input=A0;
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); /// REGISTER SELECT PIN,ENABLE PIN,D4 PIN,D5 PIN, D6 PIN, D7 PIN

//variables
int timer1_counter;
unsigned int s=0;

unsigned int pwm_timing=0;
unsigned int pwm_duty=0;
unsigned int rpm_set=0;
unsigned int rpm_read=0;
char rpm_read_status = 0;
//timer

void setup()
{
  pinMode(ledPin,OUTPUT);
  pinMode(motor,OUTPUT);
  pinMode(in_ir,INPUT);
  pinMode(adc_input,INPUT);
  

  lcd.begin(16, 2);         // initializes the 16x2 LCD
  lcd.setCursor(2,0);       // sets the cursor at column 2 row 0
  lcd.print("IR TACHOMERTER  "); // prints temperature
  

  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  // Set timer1_counter to the correct value for our interrupt interval
  //timer1_counter = 64911;   // preload timer 65536-16MHz/256/100Hz
  //timer1_counter = 64286;   // preload timer 65536-16MHz/256/50Hz
  timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz
  
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}

ISR(TIMER1_OVF_vect)        // interrupt service routine 
{
  TCNT1 = timer1_counter;   // preload timer
  s++;
  //digitalWrite(ledPin, digitalRead(ledPin) ^ 1);
}

void loop()
{
 
 if(digitalRead(in_ir) == LOW) {//read rpm senssor
   rpm_read++;
   while(digitalRead(in_ir) == LOW){;}
 }

  if((rpm_read * 12) > rpm_set){
       pwm_duty++;
       if(pwm_duty > 65000){pwm_duty=65000;}
  }
  else {
       pwm_duty--;
       if(pwm_duty < 1){pwm_duty=1;}
  }


 if(pwm_timing < 10){
      digitalWrite(ledPin, LOW);
      digitalWrite(motor, LOW);
 }
 if((pwm_timing > 10) && (pwm_timing > pwm_duty)){
      digitalWrite(ledPin, HIGH);
      digitalWrite(motor, HIGH);
      pwm_timing=0;
      delay(10);
 }
 pwm_timing++;
 
    if(s%5==0){
      if(rpm_read_status == 0){
        lcd.setCursor(8,1);
        lcd.print("                ");
        lcd.setCursor(8,1);
        lcd.print("R=");
        lcd.print((rpm_read * 12)); 
        delay(10);
        rpm_read=0;
      }
      rpm_read_status=1;
    }
    else {rpm_read_status=0;}
    
    if(s%2==1){
      lcd.setCursor(0,1);
        lcd.print("        ");
       lcd.setCursor(0,1);       // sets the cursor at column 2 row 0
        lcd.print("S=");
        rpm_set=analogRead(adc_input); // reads the sensor output
        lcd.print(rpm_set); 
        delay(10); 
    }
   
}
 



Share this page with your friends
share via Whatsapp

Posted By :
Mahesh Nigam
(Scientist)
2019-09-27 17:13
See Author's other Published Topics

Airtel cheating ther customers by incomplete description of recharge pack of Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
साहस और धैर्य का प्रतिक कारगिल विजय दिवस  of साहस और धैर्य का प्रतिक कारगिल विजय दिवस
साहस और धैर्य का प्रतिक कारगिल विजय दिवस
Vaisakhi  of Vaisakhi
Vaisakhi
3 मार्च - विश्व वन्यजीव दिवस of 3 मार्च - विश्व वन्यजीव दिवस
3 मार्च - विश्व वन्यजीव दिवस
1 मार्च- विश्व प्रशंसा दिवस of 1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस of 1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च - शून्य भेदभाव दिवस of 1 march शून्य भेदभाव दिवस
1 march शून्य भेदभाव दिवस
करती रही of पूरा नही बस थोड़ा सा ही समझा होता ....
पूरा नही बस थोड़ा सा ही समझा होता ....
वैलेंटाइन of वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
National Test Agency of UGC NET December 2023 results and download its subject wise cut-off
UGC NET December 2023 results and download its subject wise cut-off
परीक्षा पे चर्चा  of परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।
परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।

Peoples