How would i write a simple program that put out a certain voltage

I am trying to spoof a switch by put the proper amount of voltage on the other side of the switch so it turn the object on. Does anyone have any code that fits this description that they can post so I can change it.
Also can you comment were I need to change the amount of volts