Here is Arduino Motor PWM code
//By Roee Bloch
//Arduino Motor PWM, in this example I am changing motor speed and directions
//All right Reserved
// Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com
//
// This source is subject to the Roee Bloch License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Roee Bloch</author>
// <email>roeebloch@walla.co.il</email>
// <date>June 2015</date>
int M1 = 3; // Motor 1 this is connected to PWMR
int M2 = 5; // Motor 1this is connected to PWML
// Also connect 2 enables pins to 5V (enable)
int val = 0; // variable to store the read value
void setup()
{
pinMode(M1, OUTPUT); // sets the pin as output
pinMode(M2, OUTPUT); // sets the pin as output
pinMode(8, OUTPUT); // sets the pin as output
pinMode(9, OUTPUT); // sets the pin as output
digitalWrite(8, HIGH); // enable Motor M1
digitalWrite(9, HIGH); // enable Motor M1
}
void loop()
{
for (int i = 1; i < 255; i++)
{
analogWrite(3, i);
analogWrite(5, 0);
delay(50);
}
delay(200);
for (int i = 1; i < 255; i++)
{
analogWrite(5, i);
analogWrite(3, 0);
delay(50);
}
}