I'm trying to read a tachogenerator from a washing machine. It outputs an alternating current, with multiple periods per revolution. The voltage for my test case (constant rpm) reads 5.5V. I attached the tachogenerator to Digital 2 and GND and ran this sketch, just to see if a change is detected:

int ledPin = 13;
volatile int state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  attachInterrupt(0, blink, RISING);

void loop() {
  digitalWrite(ledPin, state);

void blink() {
  if (state == LOW) state != state;

Unfortunately, the LED does not light when I start the motor. When I measure the voltage while it is connected to the Arduino, it shows only about 0.7V, which would explain why the LED is not reacting. But why is this?

1 Answer 1


There's an obvious code problem in your blink() function:

state != state;

The above statement will never modify your state variable. The != operator in C/C++ does not perform an assignment (unlike operators such as += and -=). It's a comparison operator which just tests for inequality. You presumably meant to do this:

state = !state;

That may not fix your problem entirely though. You might find that the interrupt doesn't get reliably triggered anyway because it's not designed to handle AC. I'd recommend using an external comparator circuit to generate a clean digital signal, such as a Schmitt trigger.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.