Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

How to build a bidirectional PWM motor controller using an Arduino

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,398
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Feb 14, 2011

How to build a two-direction motor controller. For faster motors, use N-channel MOSFETS. Otherwise NPN transistors are fine. Here is the code:

int mSpeed = 0;
int stage;

void setup() { pinMode(9, OUTPUT);
pinMode(8, OUTPUT); mSpeed = 0;
stage = 1;
}

void loop() { switch (stage){
case 2: mSpeed--; analogWrite(9, mSpeed); if(mSpeed == 0){ stage = 3; } break;




case 3: mSpeed++; analogWrite(8, mSpeed); if(mSpeed == 255){ stage = 4; } break;




case 4: mSpeed--; analogWrite(8, mSpeed); if(mSpeed == 0){ stage = 1; } break;




case 1: mSpeed ++ ; analogWrite(9, mSpeed); if(mSpeed == 255){ stage = 2; } break; }
delay(mSpeed / 10);




}

Link to this comment:

Share to:

Uploader Comments (Bizorke)

  • i been trying to understand transistor i have bought a book and online search but i just dont get it gow they work and what they do, can you please help me

  • @supersanchez1991 thanks for the comment. I was actually planning on doing a video tutorial on how to interface transistors with microcontrollers. Since you asked, I will place additional emphasis on the transistor circuitry. I should have time to do it this week. Please subscribe for updates.

see all

All Comments (4)

Sign In or Sign Up now to post a comment!
  • could you up a schematic of what you did? the video is difficult to make out.

  • than you

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more