First, I don’t know much about electronic, this is my first project.
This works but should I expect smoke soon? The pin 9 on the Arduino micro is set to INPUT_PULLUP.
Thanks.
First, I don’t know much about electronic, this is my first project.
This works but should I expect smoke soon? The pin 9 on the Arduino micro is set to INPUT_PULLUP.
Thanks.
You should really include a pull-down resistor between the base and GND, as the optocoupler is effectively a button.
Also you really don't need the transistor at all, as the optocoupler is doing the same job as the transistor.
When a pin is INPUT_PULLUP it's perfectly safe to put any voltage between 0V and 5V on it (assuming
a 5V supply), as the only currents that can flow are pretty small.
Just don't make pin 9 an OUTPUT (!)
majenko:
You should really include a pull-down resistor between the base and GND, as the optocoupler is effectively a button.
Don’t know what you mean by "between the base and GND"?
majenko:
Also you really don't need the transistor at all, as the optocoupler is doing the same job as the transistor.
Right, I see that now. I should just connect Pin9 and GND from the arduino directly to pin 5 and 4 on the CNY17?
Harald_K:
Right, I see that now. I should just connect Pin9 and GND from the arduino directly to pin 5 and 4 on the CNY17?
Yes.
MarkT:
When a pin is INPUT_PULLUP it's perfectly safe to put any voltage between 0V and 5V on it (assuming
a 5V supply), as the only currents that can flow are pretty small.Just don't make pin 9 an OUTPUT (!)
When I power up my project the CNY17-4 is open so the power will run from Pin 9 til GND, but it will take a second or two before my program is ready and the Pin 9 has been set to INPUT_PULLUP. Could this damage the Arduino?
Harald_K:
When I power up my project the CNY17-4 is open so the power will run from Pin 9 til GND, but it will take a second or two before my program is ready and the Pin 9 has been set to INPUT_PULLUP. Could this damage the Arduino?
No. The only way to damage it is OUTPUT HIGH.
That circuit will work (although it might need the base pulldown resistor already mentioned), but why use the transistor at all? Just connect pin 4 of the CNY17-4 to ground and pin 5 to the Arduino input pin, with pin mode INPUT_PULLUP. That's the usual way of connecting an opto isolator to an Arduino.
dc42:
That circuit will work (although it might need the base pulldown resistor already mentioned), but why use the transistor at all? Just connect pin 4 of the CNY17-4 to ground and pin 5 to the Arduino input pin, with pin mode INPUT_PULLUP. That's the usual way of connecting an opto isolator to an Arduino.
Your prescience is running a bit late today... The OP has already realised that's what he should do
majenko:
Your prescience is running a bit late today... The OP has already realised that's what he should do
Mental note to self; read ALL of all the previous replies before replying!