Project: Dyno. Check it out, for criticism and advice

That's the code:

float time;
const int redLed = 10;
const int yellowLed = 9;
const int sparkPin = 2;
int sensorValue = 0;         
int lastSensorValue = 0;     

void setup() {
  Serial.begin(9600);
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(sparkPin, INPUT);
}

void loop() {
  int sensorValue = digitalRead(2);
  float rpm = 0;
  time = millis();
  if (sensorValue == HIGH) {
    if (sensorValue != lastSensorValue) {
      rpm = (1/time)*60000;
      Serial.println(rpm);
      digitalWrite(redLed, HIGH);
      if (rpm > 4000) {
        digitalWrite(yellowLed, HIGH);
      }
    delay(1000);
    time = 0;
    }
  }
  digitalWrite(redLed, LOW);
  digitalWrite(yellowLed, LOW);
  lastSensorValue = sensorValue;
}

the circuit is attached (thanks to mister_rf to that)

The LEDs works all th time, but when the engine is running, the connection on serial port (with USB) is lost.

What's the problem??