I have no electrical engineering skills so I put my hopes to this forum for some guidance. The problem that I have is that when I write anything else than 0 or 255 on the transistor pin the readings from the rangefinder are incorrect. It is a nano, hc-sr04 rangefinder and a tip120 transistor. The 12V input is in the upper right corner and the led output is the white and grey wire top left.
Thanks! /Jan
Is the reading correct if you disconnect Pin 9 (the LED pin)? If so that might mean that the LED circuit is causing problems with the power going to the distance sensor. The PWM pulses can create a lot of noise.
I don't see a resistor between the Arduino and the Transistor. If that is an NPN transistor the Base-Emitter junction acts like a diode straight to Ground. Without a resistor (try 1K) it will draw too much current from the Arduino pin.
The 1k resistor did it. Thanks!

