I would appreciate if someone could help me.
Here is my connection to Arduino:
wires, yellow and red are for AC current. Other 3 in my arduino, orange pin 2, blue ground and red 5V power.
I am using h11aa1 optoisolator.
Here is my code:
const uint8_t ledPin = 13; // Digital output pin that has the on board LED
const uint8_t zeroPin = 2; // Digital input pin to which the zero crossing detector is connected
uint8_t zeroCounter = 0;
bool zeroState = 0;
bool ledState = 0;
void setup() {
Serial.begin(9600);
pinMode( ledPin , OUTPUT ); // Enable output driver for LED pin
pinMode( zeroPin , INPUT );
}
void loop() {
Serial.println(digitalRead(zeroPin));
while ( digitalRead(zeroPin) == zeroState ) { // Wait for the state of the zero crossing detector to change
zeroState != zeroState;
zeroCounter++;
if ( zeroCounter == 50 ) { // Every 50 zero crossings change the LED state
Serial.println(zeroState);
ledState != ledState;
digitalWrite( ledPin , ledState );
zeroCounter = 0;
}
};
}
I get always 1 for digitalRead(zeroPin) and because of it Serial.println(zeroState) will never run...
Anyone can help me make this work?
