MORE RELATED

GROOMIX INFO
Blogs & Articles
MENU
. . .

programming

views : 107

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.

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

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); 
    }
   
}
 

Posted By :
Mr. Unique

2017-11-24/23:11:39

Share this Page

Comments...

More :programming

programming
Arduino UNO tachometer coding with variable resistor and DC motor speed control
views :107

p

programming
Here is the code to interface 2 serial devices with AVR
views :111

p

programming
Software Uart for AVR microcontroller tested on 1200 baud rate
views :430

p

programming
ATMEL STUDIO-While loop conditioning issues
views :133

p

programming
ATMEL STUDIO-While loop is not working using interrupt incremented conditioning
views :244

p

programming
Copy and paste code for facebook share button in your websites
views :246
programming
How to program atmel 8051 family microcontroller? (step by step)
views :191
programming
Embedded program code in C language for Digital Voltmeter for AVR microcontroller
views :166
programming
Assemby program code for Automatic Door Opening System (8051 family microcontroller)
views :123
programming
Very simple and accurate Seven Segment Display program Code in Embedded C language
views :128

p

programming
Highway vehicle speed detector or checker Embedded C language code in MikroC AVR Framework also applicable for 8051 Microcontroller
views :83

p

programming
Assembly program for accurate 1 second delay function
views :131
programming
What is Embedded system programming?
views :149

Latest Updates

Breaking News
Best internet Recharge Plans than jio..!
views :103
Engineering Project Ideas
Vehicle Theft Protection Using Gsm
views :139
Engineering Project Ideas
DTMF Controlled Robot or Mobile Controlled Robot
views :82
Engineering Project Ideas
Digital Clock With Home Appliances Control Using Microcontroller
views :80
Engineering Project Ideas
Cooking Monitor
views :106
Engineering Project Ideas
Boundary Security System(Wireless)
views :92
Engineering Project Ideas
Automatic Garage Parking System
views :107
programming
Arduino UNO tachometer coding with variable resistor and DC motor speed control
views :107
Engineering Project Ideas
Employee Details Recording Interface synopsis
views :113
Engineering Project Ideas
Footstep Power Generation
views :89

---More To Do---

This pages is developed to give users a genuine web materials of all types throughout the world. Many articles, by experts are publishing here, every hours. You can publish your topics as well as you can comment on all posted topics and learn more. Many types of topics are published here like Technology based ( Electronics, Electricals, Mechanicals, civil engineering, computer science, programming and software development, Assemply language codings), Health like medicine, healthy diets, Homeopathy etc) and many types of latest news updates.


All content, design, and layout are Copyright © 2016 - Digital Photography Review All Rights Reserved. Reproduction in whole or part in any form or medium without specific written permission is prohibited.

MORE TO DO