Arduino Motor Software

Making your program work.
Posts: 1
Joined: Tue Jun 15, 2010 12:45 am

Arduino Motor Software

Post by geekboy »

Anyone know what I have to change in this code to increase the frequency of PWM?

Code: Select all

 int potPin = 2;    // select the input pin for the potentiometer
    int ledPin = 11;   // note onlly 5,6, 9,10,11 are PWM
    int wait = 0;     // variable to store the value coming from the sensor

    void setup() {
   //   Serial.begin(9600);
    pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT

    void loop() {
    wait = analogRead(potPin) - 28; // read the value from the sensor
    if(wait > 950){
      digitalWrite(ledPin, LOW);
       digitalWrite(ledPin, HIGH); // turn the ledPin on
       delayMicroseconds(1023 - wait); // stop the program for some time
       digitalWrite(ledPin, LOW); // turn the ledPin off
       delayMicroseconds( wait); // stop the program for some time
   //   Serial.println( wait );
Right now I am in the default setting of 500 Hertz and its annoying Rolling Eyes

Posts: 4
Joined: Tue Jun 15, 2010 8:08 pm

Re: Arduino Motor Software

Post by fhayashi »

As far as I understand it, PWM is how the Arduino 'fakes' analog output. Instead of HIGH and LOW, you can kind of fake zero volts to 5 volts on pins 3, 5, 6, 9, 10, and 11 by using:

Code: Select all

analogWrite(pin, ###)
where ### is a value from 0 (off) to 255 (fully on).

Your code snippet doesn't seem to have anything to do with motors. If you want help coding so you can set the speed on a motor, try

You'll probably need a transistor to actually drive the motor. I don't think you can provide adequate amperage through the Arduino (or clone).

Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: Arduino Motor Software

Post by oz »

HI geekboy,

Here's your answer: ... Cheatsheet

I had this up on the Arduino PWM (analogWrite (sic)) reference page, but David Mellis deleted it. He's very big on eliminating useful information, that he doesn't believe in making available to users, for whatever reason. I've pretty much stopped working on the Arduino site since he has deleted so many of my reference pages.


Posts: 1
Joined: Tue Nov 09, 2010 8:26 pm

Re: Arduino Motor Software

Post by DeathlyHallow »

hi paul

that was a very helpful tool.

it seems that their problem will be solved with the information you have provided for them.

Post Reply