Mini motors experience

Experience done to the Project in Automation and Industrial Robotics, class from the Integrated Master in Mechanical Engineering of the University of Aveiro.

A program was created to control and to monitor 5 vibrator motors (cellphone ones) choosing its frequency, dutty cycle (power) and offset between all the motors.
Using RS232 protocol communication it’s possible to send the data that the user inserts in the gtk interface to the arduino, that is going to control the motors.

The main goal of this project is to observe how the motors react to different frequencies.

The pins in the Arduino Mega have a constant frequency of 490Hz.

The PWM behavior is determined by timers. Changing one pin’s frequency requires changes to the timer it connects to. However, creating custom frequencies messes up with the prescaler and requires the sacrifice of one channel. Initially, a library called PWM.h was used. However, since the Arduino Mega doesn’t have the same timers attributed to the same pins as the others, the change of prescaler had to be done by hand. For Arduino Mega, the timer 0 controls the pin 13 and 4, timer 1 controls pin 12 and 11, timer 2 controls pin 10 and 9, timer 3 controls pin 5, 3 and 2, and timer 4 controls pin 8, 7 and 6. \n
In this project the pins 3, 5, 6, 7 and 8 were used, so TIMER 3 and TIMER 4 were changed.

The frequency values, and also the offset and the dutycycle are sent by serial port using the Serial.readStringUntil() function.
The motors are controlled using the analogWrite() function from the Arduino library.

To send data from the Arduino the command sprintf and Serialprintln() was used.
Since the code has a default frequency, dutycycle and offset when no data is received, everytime new data is sent from the gtk interface, it takes some time for those values (frequency, dutycycle, etc) to be changed in the arduino, since the code starts running with the default.