int DCPin = 9; // Control pin for dc motor int DCPin2 = 10; // Control pin for dc motor2 int servoPin = 6; // Control pin for Servomotor int pulse = 0; // Amount to pulse the servo int minPulse = 500; // Minimum servo position int maxPulse = 2500; // Maximum servo position long lastPulse = 0; // the time in milliseconds of the last pulse int refreshTime = 20; // the time needed in between pulses int analogValue = 0; // the value returned from the analog sensor int analogPin = 0; // the analog pin that the sensor's on void setup() { pinMode(servoPin, OUTPUT); // Set servo pin as an output pin pinMode(DCPin, OUTPUT); pinMode(DCPin2, OUTPUT); Serial.begin(9600); } void loop() { analogValue = analogRead(analogPin); // read the analog input pulse = (analogValue * 19) / 10 + minPulse; // convert the analog value analogWrite(DCPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 analogWrite(DCPin2, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 if (millis() - lastPulse >= refreshTime) { digitalWrite(servoPin, HIGH); // Turn the motor on delayMicroseconds(pulse); // Length of the pulse sets the motor position digitalWrite(servoPin, LOW); // Turn the motor off lastPulse = millis(); // save the time of the last pulse } // to a range between minPulse // and maxPulse. Serial.println("======================================="); Serial.println(analogValue); if (analogValue>500) { digitalWrite(DCPin, HIGH); // Turn the motor on digitalWrite(DCPin2, HIGH); // Turn the motor on } else { digitalWrite(DCPin, LOW); // Turn the motor off digitalWrite(DCPin2, LOW); // Turn the motor off } delay(1000); }