Changing the frequency of a motor using Arduino

I'm new to Arduino ... and hardly understand how its supposed to work... Though I would really like to know what its doing... I have a motor which works on 12.5 Hz ... and a laser that's supposed to work only on 10Hz. What I have not been able to understand is what formula should I be using ... F = 1 / time ? But what will time be ?

I would really appreciate some understanding on this topic .. I don't want the code or anything ... Just let me know how to start ....

Oh and I saw this motor.h library ... but it is still under construction from what I understood... Is there any other library ?

Hi mmewar,
I don't know about anyone else, but I don't quite understand what you mean? a motor DC? or AC? that runs at 12.5Hz and a Laser at 10Hz. Can we have more details, then perhaps someone can help you. Data sheets, details, pics anything..


Yes, its an AC motor ... I just returned home, so I don't have pics related to the same ... What I want to understand is how to set a frequency for the motor... Its basically like this:

There is a laser which runs only on 10Hz.
The motor which is an input to the laser runs on 12.5Hz ... Which is bad. I need to set the frequency of this AC motor to 10Hz (Tolerance of +- 0.1Hz is fine)

Is there any library that would help me do this ?

As motors don't have frequencies and the frequency of a laser is no where near 10Hz you need to do a lot of explaining.


Perhaps the laser pulses (emits bursts of light) at 10 Hz.
But how can a motor be an input to a laser?

@jremington - Yes... It pulses at 10Hz is what I meant.

The motor(AC @ 50Hz) generates a frequency of 12.5 Hz. The laser uses 2 inputs - 1) the motor and 2) the start button

What the program should do:
Check if there is a Motor-signal
Check if there is a Signal from the start input
If there are signals from both inputs:
Calculate motor frequency (you can do that earlier, so that no time is lost. The motor frequency should be calculated on a regular basis so that frequency changes are taken into account.)
Modulate laser pulse (max allowed frequency shift is +-0.1 Hz.
The laser should run with 10 Hz) to synchronize laser and motor pulse over the next 10-15 pulses.
Give signal to open shutter, to open the mechanical shutter unit.

I just want to know how to start calculating the frequency of the motor in question and keep it to 10Hz instead of 12.5Hz...

This gets more and more confusing..

The motor(AC @ 50Hz) generates a frequency of 12.5 Hz.

Is there some kind of sensor on the geared output shaft? You should really be a lot more specific in order to help people help you

And I was told this is going to be the easiest part :frowning: .... ! Its an Atmega. How would a geared sensored shaft do anything to reduce the frequency ?

const int laserPulse = 9; // output pulse for laser
const int motorInput = 8; // motor signal input
const int shutterOut = 0; // output signal for mechanical shutter
const int isMeasurement = 2; // input signal for measurement start

// Variables will change:
int pulseState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
unsigned long previusMotorMillis = 0;
long dMotor =80; // standard dt of motor pulse
int Motor = LOW;
int measurement = LOW;
boolean pulsing = false;
long interval = 100; // interval at which to pulse (milliseconds)
signed long shift=0;
unsigned long currentMillis = 0;
boolean messen = false;

void setup() {
// set the digital pin as output:
pinMode(isMeasurement, INPUT);
pinMode(motorInput, INPUT);
pinMode(shutterOut, OUTPUT);
pinMode(laserPulse, OUTPUT);

void calcMotorFrequence (unsigned long *previousMotorMillis, long *dMotor)
*dMotor = millis() - *previousMotorMillis; // in milliseconds
*previousMotorMillis = millis();

// calculates shift for superimposing laser pulse and motor signal
void calcShift(long *pointPrevTime, signed long *shift)
long timeStart=millis();
*shift = timeStart-*pointPrevTime;

// generates pulse with defined delay
void pulse(signed int shift, unsigned long *currentMillis)
*currentMillis = millis();
if(*currentMillis - previousMillis > interval + shift)
// save the last time the laser pulsed
previousMillis = *currentMillis;
// output pulse
digitalWrite(laserPulse, HIGH);
digitalWrite(laserPulse, LOW);
pulsing = false;

void loop()
// here is where you'd put code that needs to be running all the time.

// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
// unsigned long currentMillis = millis();
Motor = digitalRead(motorInput);
measurement = digitalRead(isMeasurement);

// check if there is a signal from the start-button
if(measurement == HIGH){
// if start button is pressed
// if start button is not pressed
if (messen==true){
calcShift(&previousMillis, &shift);

... This is what I joined somehow .... I can do the C++ part ... The pointers used by my group mate are not correct I know... But I don't understand how it is calculating frequency

Nobody here understands what you mean by a motor emitting a frequency. So please elaborate

HI mmewar,
It's all getting rather confusing!! Do you mean the motor rotates at 12.5 rpm? then what you might mean is controlling the speed? How does the motor trigger the Laser?

And I was told this is going to be the easiest part :frowning: .... ! Its an Atmega. How would a geared sensored shaft do anything to reduce the frequency ?

If you don't know the answer?? think about it, as nilton61 said where does the motor trigger come from? a switch or sensor??
Can we see a schematic or pictures, we need more info.