DC Motor Control – Arduino for Beginners

After seeing the below link… i have an doubt… How do I switch ON & OFF a DC fan from an Arduino ???

ingenstech.com/19-dc-motor-c … beginners/

If you want to use that circuit to control a DC motor, but instead control whether the motor is on/off instead of controlling forward/reverse, we would recommend trying something like this:

int analogInPin = A0;
int sensorValue1 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void loop() {
  sensorValue1 = analogRead(analogInPin);
  Serial.println(sensorValue1);
  if (sensorValue1 >= 300) { // On
    digitalWrite(9, HIGH);
    digitalWrite(10, LOW);
  } else { // Off
    digitalWrite(10, LOW); // Code changed here from high to low
    digitalWrite(9, LOW);
  }
  delay(10);
}

Notice that one of the digitalWrite calls in the else condition was changed from the example.