• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeArduinoAdvanced Learning Kit for ArduinoHow to use U-shape Speed measurement breakout with ...
Previous Next

How to use U-shape Speed measurement breakout with Arduino

Posted by: admin , January 4, 2015

We can use the speed encoder wheel and U-shape speed measurement breakout with Arduino to measure the motor speed. In this tutorial, we will detail the steps taken.

 

110046odqfqfxgqodfq5nd

 

We connect G of the breakout to GND of Arduino, V of the breakout to 5V of Arduino, and S of the breakout to digital 2 or 3 (this is very important as the interruption uses these two) of the Arduino.

If we insert an object in the U-shape, the LED on the breakout will turn on. If we remove it, the LED will turn off.

The sample code is as following:

/************************************************************************
 * Motor speed measurement 
 * use millis()function to measure time in unit of ms
 * Use interrupt function, when the signal level changes, it will count once
 * Use 1:48 reduced speed motor, 20 holes encoder wheel as example
 * Divide the val by 40, and we can get the number of turns
 * Divied by the current time, as the time is in unit of ms, divided again by 60000 to get minute
 * Now we will obtain the speed in unit of turns/minute
 * BY YFROBOT
 ************************************************************************/

//Connect the signal to digital pin 2
int U_Pin = 2;    
float Val = 0;      
float time;  /
float Speed;  

void setup(){

  Serial.begin(9600);
  attachInterrupt(0,count,CHANGE);    
}

void loop(){

  time = millis();
  Speed =  (Val/40)/(time/60000) ;
  Serial.println(Speed);
}

void count(){
  Val += 1;
}

 

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors