Home > Driving Motors > Arduino PWM and Mini Motor

Arduino PWM and Mini Motor

Driving a vibrating motor directly from an Arduino is possible without burning it.

Using a 75 Ohms series resistor the current can be maintained under 40 milliams (ATMEGA238 max. limit).

The motor speed can be controlled using a Potentiometer to adjust the PWM signal.

A Photoswitch detects the slot in the wheel  for revolutions counting.

Minimot_GIF

The yellow Led  toggles every 30 revolutions.

Removing the offset weight, a no easy task.

Minimot_mass

Some Laser Cutting was done before put together all parts.

Disc_1_slotSoportes

How was connected to the Arduino pins:

Minimot_sch_

The final Assembly:

Final_Ass

The sketch used in the YouTube demostration:

/*------------------------------------------------------------------------------
  MiniMot_10
  Arduining.com  05 APRIL 2013
  
      The excentric mass is replaced by a disk in a Mini Vibrating Motor.
      A Motor Revolutions Counter is implemented using a photoswitch.   
      The Motor speed is controlled with a potentiometer.
      A led is toggled every 30 revolutions to show the motor speed.
      The PWM value is transmited to the Serial monitor.
  
      Arduino (ATMEGA328)drives directly the Motor, a series resistor
      of 75 ohms limits the current to 40 milliamps.
     
 -----------------------------------------------------------------------------*/
#define  MOT1    9        //Pin directly connected to the Motor.
#define  MOT2    10       //Pin connected to the Motor trhought a 75 Ohms resistor.
#define  LED     7        //Pin connected to the LED.
#define  POT     0        //Analog input for the potentiometer.
#define  PhotoSwitch  8   //Pin connected to the photoswitch.

#define  TURNS   30       //Number of turns to toggle the LED.

int Counter;              //Revolutions counter.
int PWMval;               //PWM Value to control the motor speed.
boolean WaitSlot= true;   //Flag used for slot detection.
boolean LedState= 0;      //1= on , 0= off

void setup() {                 
  pinMode(LED, OUTPUT);
  pinMode (PhotoSwitch, INPUT);
  Serial.begin(9600);
  analogWrite(MOT2, 0);    //pin 2 of the motor grounded.
}

void loop()
{
  PWMval=analogRead(POT)/4;  //read potentiometer.
  analogWrite(MOT1,PWMval);  //set the motor speed.

  if (!digitalRead(PhotoSwitch) && WaitSlot){  //slot detection!
    Counter++;
    WaitSlot=false;
    if (Counter == TURNS){
      LedState = !LedState;        // toggle the Led state.
      digitalWrite(LED,LedState);
      Serial.println(PWMval);
      Counter=0;                  //Reset the revolutions counter.
      }
    }

  else if (digitalRead(PhotoSwitch)) WaitSlot= true;  //No slot.

 }
Advertisements
Categories: Driving Motors
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: