I'm stepping down my 24V signal to a 5V signal using an octocoupler as shown in the attached picture. The 5V signal is powered via a phone charging block (5V, 1A).
The serial monitor on my Arduino sporadically reads a mixture of 0s and 'cycling', no matter whether I am sending the voltage output or not. Any ideas on why I'm not properly getting steady 0s when my voltage output is off or steady 'cycling' when my voltage output is on.
Thanks for any help.
const int PWM = 2;
const int inPin = 52;
void setup() {
Serial.begin(9600);
pinMode(PWM, OUTPUT);
pinMode(inPin, INPUT);
}
void loop() {
Serial.println(digitalRead(inPin));
while(digitalRead(inPin) == HIGH){
digitalWrite(PWM, HIGH);
delay(10);
digitalWrite(PWM, LOW);
delay(10);
Serial.print("Cycling");
}
}

