Code for counter

But the signal cable is coming out of the sensor, isn't it? So, normally a signal should variate between GND and Vcc, Vcc being 12 volts in your case.