// Motor_1 // Control the speed of a motor using H-bridge // This uses L293D or equivalent const int Enable1 = 6; // this just gives a name to pin6 goes to Enable pin on L293D // When it says Enable1 in the program it means pin 6. const int direct1 = 5; // this pin goes to input1 on L293D const int direct2 = 4; // this pin goes to input2 on L293D // the actual program starts here void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(Enable1, OUTPUT); // digital pins need to be defined as input or output pinMode(direct1, OUTPUT); pinMode(direct2, OUTPUT); } void loop() { int PotValue = 0; // a variable to store the Potentiometer reading int speedValue = 0; // a variable to store the motor speed // read the input on analog pin 0: PotValue = analogRead(A0); // the value will be 0 to 1023 // print out the value read: Serial.println(PotValue); speedValue = PotValue/4; // the motor speed needs to be 0 to 254 for pwm analogWrite(Enable1, speedValue); // this creates a pwm output digitalWrite(direct1, HIGH); // one direction digitalWrite(direct2, LOW); // swap I1 and I2 values to reverse delay(500); // delay in between reads for stability }