Code for counter

Hi, Yes i know. I haven't connected the 12v sensor to the Arduino - only the signal cable. I think this could cause the problem. I will be looking for exambles to get an idea... thanks