Monday, October 24, 2016

Use a Speed Sensor to know the speed of your motors

                                         
                                                    SCHEMATIC DESIGN
PARTS USED
1.
                                                                 65 mm WHEEL
2.

                                       DC Motor with double shaft Gearbox 1:120

3.

                                        DC Motor with double shaft Gearbox 1:48

4.

                                   Infrared Speed sensor module with encoder Disc

5.

                                           Jumper Wires male to female 20pcs

6.

                                              Jumper Wires male to male – 65pcs

7.

                                  L9110 Motor Driver H-Bridge board Dual Channel

8.
                                                                             UNO R3
CODE
#include <TimerOne.h>
unsigned int counter=0;
int b1a = 6;  // L9110 B-1A
int b1b = 9;  // L9110 B-1B
void docount()  // counts from the speed sensor
{
  counter++;  // increase +1 the counter value
}
void timerIsr()
{
  Timer1.detachInterrupt();  //stop the timer
  Serial.print("Motor Speed: ");
  int rotation = (counter / 20);  // divide by number of holes in Disc
  Serial.print(rotation,DEC);  
  Serial.println(" Rotation per seconds");
  counter=0;  //  reset counter to zero
  Timer1.attachInterrupt( timerIsr );  //enable the timer
}
void setup()
{
  Serial.begin(9600);
  
pinMode(b1a, OUTPUT);
pinMode(b1b, OUTPUT);
  
  Timer1.initialize(1000000); // set timer for 1sec
  attachInterrupt(0, docount, RISING);  // increase counter when speed sensor pin goes High
  Timer1.attachInterrupt( timerIsr ); // enable the timer
}
void loop()
{
  int potvalue = analogRead(1);  // Potentiometer connected to Pin A1
  int motorspeed = map(potvalue, 0, 680, 255, 0);
  analogWrite(b1a, motorspeed);  // set speed of motor (0-255)
  digitalWrite(b1b, 1);  // set rotation of motor to Clockwise
}
IMPORTANT FILES TO DOWNLOAD

No comments:

Post a Comment