DC motor phototransistor control
analogRead() returns an integer between 0 and 1023. Using 30 and 400 in the map() function, then passing in a value outside of that range will cause strange results. Here is a sketch to illustrate my point.

void setup(){

  Serial.begin(9600);

  // Prints -20 to 684
  for(int i = 0; i &lt; 1024; i++){
    Serial.println(map(i, 30, 400, 0, 255));
  }
  Serial.println();

  // Prints -7 to 255
  for(int i = 0; i &lt; 1024; i++){
    Serial.println(map(i, 30, 1023, 0, 255));
  }
  Serial.println();

  // Prints 0 to 255
  for(int i = 0; i &lt; 1024; i++){
    Serial.println(map(i, 0, 1023, 0, 255));
  }
}

void loop(){}