Opto-isolator

Hello, I was curious if anyone could give me a sample of code or some directions on how to code an optoisolator photocoupler to control a servo motor with if statements. I have 4-channel 5KVrms 16-pin DIP Liteon LTV-847 optoisolators.

What do you want the servo to do exactly ?
What will be providing the control input ?
Why is the opto isolator required ?

You can monitor the opto output as you do a switch.

When LOW, do LOW stuff.

When HIGH, do HIGH stuff.

Not any more difficult than that.

So essentially does the option isolator act as an analog input? I am attempting to use the optoisolator to control a servo based on a light source I can’t control without a photoresistor. I heard you could use an optoisolator to almost mimic signals i.e. if the LED I can’t control is turned on I can use it as a HIGH or LOW input and control a servo using a simply of statement, however I am unsure if an optoisolator deals directly with a high or low reading or if it’s actually an analog output

The opto isolator is like an on/off switch, gives HIGH/LOW

I have not tried to do so yet, but could I theoretically use the HIGH LOW sequences to as essentially the controls for servos via if statements?

As with switches, your opto isolator o/p can be used in an if() line of code.

myOptoIsolatorState = digitalRead(myInputPin);

if(myOptoIsolatorState == HIGH)
{
// position your servo to a specific angle
}

Awesome! Is there anywhere I may be able to find a full sample code for optoisolators? The portion you provided me was extremely helpful, but I do not believe I am literate enough to fully comprehend it. I believe myoptoisolatorstate was simply a variable you created as a demonstration to show, but am unsure if there is a library out there somewhere with a set of examples that has it configured differently

Have a look at the datasheet.

Top right page 1 shows the pin numbers; bottom right page 5 shows how to hook it up.

So you wire the collector of the opto’s transistor to an Arduino pin, using INPUT_PULLUP in pinMode instead of that resistor RL they show,

You still need to put a voltage across the opto’s internal led, the pin the y label Input, with a series resistor RD whose value depends on the voltage you’re putting in there.

It’s an inverter. When the Input is high, the led inside there shines on the transistor which then conducts. That shorts the pin labeled Output to ground, so it’s low, opposite to Input. when Input is low, the led is off, the transistor doesn’t conduct, and Output is made high to Vcc through RL, which would likely be the internal one.

Perfect! Thank you very much for both of your time and efforts! I believe I am now able to do exactly what I’m looking for!

I must say it's not clear to me what you want the opto to do...

Do you have an Input (to use the term as they use it on page 5) of some dodgy voltage that you can't put directly into the Arduino? Because that's really all it's going to do: isolate that high voltage from that of the Arduino through the led / transistor inside.

Yeah, I actually was attempting to use a fluctuating input voltage as a control (had some success, but results inconsistent) but opted to find a more dependable alternative.