Programming: views : 1161

Arduino UNO tachometer coding with variable resistor and DC motor speed control

Here is a copy and paste code for arduino uno kit to make a speed regulated tachometer for DC motors. Algorithm of program is like this, we connect a variable resistor with a ADC pin of the arduino UNO and set it as input pin through coding. This is converted into digital value in the form of an integer. Using IR proximity sensor, we read the speed of DC motor. DC motor is again controlled by a power transistor (BD139 for 1 ampere current). Speed is controlled by PWM signal and PWM is generated by the help of the integer value that we get from variable resistor.


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

Happy Teacher’s Day of Dear Madam, Thank You For continually Inspiring me to do my best..
Dear Madam, Thank You For continually Inspiring me to do my best..
Happy teachers day of Thank you for teaching me how to read and write, for guiding me to distinguish between what is wrong and what is right. For allowing me to dream and soar as a kite, thank you for being my...
Thank you for teaching me how to read and write, for guiding me to distinguish between what is wrong and what is right. For allowing me to dream and soar as a kite, thank you for being my...
A good teacher is like a candle of A good teacher is like a candle – it consumes itself to light the way for others..
A good teacher is like a candle – it consumes itself to light the way for others..
The teacher who is indeed wise of The teacher who is indeed wise does not bid you to enter the house of his wisdom but rather leads you..
The teacher who is indeed wise does not bid you to enter the house of his wisdom but rather leads you..
Happy World Teachers' Day! of I am proud to let you know that you have been the great teacher in my life! Happy World Teachers' Day!...
I am proud to let you know that you have been the great teacher in my life! Happy World Teachers' Day!...
Happy teachers day of Without you, we would have been lost. Thank you teacher for guiding us, inspiring us And making us..
Without you, we would have been lost. Thank you teacher for guiding us, inspiring us And making us..
Wishing you a Teacher's Day of I was lucky to have a teacher as wonderful as you are. Wishing you a Teacher's Day that’s full of joyous...
I was lucky to have a teacher as wonderful as you are. Wishing you a Teacher's Day that’s full of joyous...
 Happy Teacher's Day! of Teacher, you have always challenged me to work hard and get good grades. I will always remember you. Happy Teacher's Day!...
Teacher, you have always challenged me to work hard and get good grades. I will always remember you. Happy Teacher's Day!...
Happy Teacher's Day! of The best teachers teach from the heart, not from the book. Thank you for being a wonderful teacher. Happy Teacher's Day!..
The best teachers teach from the heart, not from the book. Thank you for being a wonderful teacher. Happy Teacher's Day!..
Happy Teacher’s Day of Happy Teacher’s Day! It has been an honor to get to learn so many...
Happy Teacher’s Day! It has been an honor to get to learn so many...
Wishing you joy and happiness of Wishing you joy and happiness, you are an amazing teacher, and you only..
Wishing you joy and happiness, you are an amazing teacher, and you only..

Peoples

Comments...

Write Your Comment

Related to Programming

Latest topics




More Categories
latest mobile phones ireps.gov.in irctc.co.in Working Principle Viral Discussion True Love quotes True Love Today is Celebrated For Tips for better life Tips and Hacks Technology News Teachers Day Quotes Study Materials Self Motivating Quotes Science Sad Lines (Sayeri) Romantic shayari quotes Robotics Reviews Results Questions_and_Answers Programming Problem Resolved PHP Codes PCB Design Online Works New Year Quotes Shayari Status My World My Responsibilities Motivational lines Mobile Issues Microcontrollers Lucknow Local News Latest Technology Iphone Homeopathy Historical place in India Heart Touching Love Quotes Health Good Night Quotes Good Morning Quotes GeM.gov.in GST portal Funny Lines (Sayeri) Friendship Quotes Food Recipes Exam Time Table Engineering Project Ideas Electronics Electronic and electrical project making ideas Electricals Educations Desh Bhakti Shayeri Criminal Love Cricket News Corona Updates Christmas Quotes Shayari Status CBSE Updates/Circulars Breaking News Breaking Heart Shayeri Break Up Lines (Sayeri) BirthDay Wishes Best kitchen Tips Best Valentine quotes Shayeri Beauty Hacks Basic Knowledges Attitude quotes shayari Attitude quotes Attitude quotes Assembly Election 2022
Go to top

Important Links

  • Contact Us
  • About Us
  • All copyright © 2020 are reserved by Groomix - designed by Groomix

    MORE

    Programming >
    latest mobile phones >
    ireps.gov.in >
    irctc.co.in >
    Working Principle >
    Viral Discussion >
    True Love quotes >
    True Love >
    Today is Celebrated For >
    Tips for better life >
    Tips and Hacks >
    Technology News >
    Teachers Day Quotes >
    Study Materials >
    Self Motivating Quotes >
    Science >
    Sad Lines (Sayeri) >
    Romantic shayari quotes >
    Robotics >
    Reviews >
    Results >
    Questions_and_Answers >
    Problem Resolved >
    PHP Codes >
    PCB Design >
    Online Works >
    New Year Quotes Shayari Status >
    My World My Responsibilities >
    Motivational lines >
    Mobile Issues >
    Microcontrollers >
    Lucknow Local News >
    Latest Technology >
    Iphone >
    Homeopathy >
    Historical place in India >
    Heart Touching Love Quotes >
    Health >
    Good Night Quotes >
    Good Morning Quotes >
    GeM.gov.in >
    GST portal >
    Funny Lines (Sayeri) >
    Friendship Quotes >
    Food Recipes >
    Exam Time Table >
    Engineering Project Ideas >
    Electronics >
    Electronic and electrical project making ideas >
    Electricals >
    Educations >
    Desh Bhakti Shayeri >
    Criminal Love >
    Cricket News >
    Corona Updates >
    Christmas Quotes Shayari Status >
    CBSE Updates/Circulars >
    Breaking News >
    Breaking Heart Shayeri >
    Break Up Lines (Sayeri) >
    BirthDay Wishes >
    Best kitchen Tips >
    Best Valentine quotes Shayeri >
    Beauty Hacks >
    Basic Knowledges >
    Attitude quotes shayari >
    Attitude quotes >
    Attitude quotes >
    Assembly Election 2022 >

    Peoples

    Latest Comments