How to replace a button with a transistor or with an opto

How should I replace a button with a transistor or an opto?
How I've to connect it?

Thanks in advance

Sorry for my English

Collector to input pin, emitter to ground and enable the internal pull up resistor.

Grumpy_Mike:
Collector to input pin, emitter to ground and enable the internal pull up resistor.

@Grumpy Mike : Trying to get my head around this and at the risk of sounding dumb...

  • which internal pull-up resistor would that be?
  • is there no connection to base?

Your English is fine. Your statement of the problem is not. What are you actually trying to do? What have you tried? What error messages are you getting? Can you post your complete code?

aisc:
@Grumpy Mike : Trying to get my head around this and at the risk of sounding dumb...

  • which internal pull-up resistor would that be?
  • is there no connection to base?

Yes, with an opto there is no connection to the base.
See the reference that comes with the IDE for help with the pullup. See pinMode().

  • which internal pull-up resistor would that be?

Well I would try the internal pull up resistor connected to the pin you are trying to use.

As aarg pointed out you gave connections for an opto - dumb me assumed a transistor.
Also the assumption is the switch replacement will be driven by an Arduino output - something the OP did not state.
OK - got my head around it now. Hope the OP does too.