24V proximitiy switch, NPN transistor, Arduino interrupt input

24varduinonpnswitchestransistors

I build circuit which take proximitiy sensor as input to circuit (24V). With this 24V we switch on and off NPN transistor.

On the side is Arduino with interrupt enable when pin is LOW. So I need circuit that convert 24V pulses to 0V and 5V pulse for Arduino input.
Switching speed is 3kHz.

So we can take 24V and with NPN transistor turn it ON/OFF?.

This is circuit in multisim.
Circuit in Multisim

and results:
enter image description here

Yellow: Input signal (signal generator)

Blue: Voltage base of the transistor
Violet: Output NPN Voltage
As input is

Why is there so much spikes? Should i use different circuit for this purpose?

Best Answer

The spikes are coming from C4. Everytime the input switches, C4 passes a short spike to the base of the transistor.

C4 and R5 and R11 form a sort of high pass filter that lets the edges of the signal from the sensor through.

Remove C4 and the spikes should go away.