Can Arduino Code press a button on an Input Pin?

I have a button with Input_PULLUP on pin6, which turns the LED on pin13 and change some variables. Can the button on Pin6 be virtually pressed by the code? So if I press a button on pin 2, he should execute a code AND press the button on pin 6 virtual.
I have tried InputWrite on Pin6. But it does not work.

const int buttonPin = 2;
const int DummyPin = 6;
const int ledPin =  13;      

int buttonState = 0;        
int DummyState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(DummyPin, INPUT_PULLUP);

void loop() {
  buttonState = digitalRead(buttonPin);
  DummyState = digitalRead(DummyPin);

  if (DummyState == LOW) {
    digitalWrite(ledPin, HIGH);
  else {
    digitalWrite(ledPin, LOW);

// ------------ virtual button press ----------------  
if (buttonState == LOW) {

 digitalWrite(DummyPin, HIGH);
 else {

 digitalWrite(DummyPin, LOW);

// -----------------------------------------------  


You cannot control an INPUT pin, only an OUTPUT pin.

And I don't understand why you would want to. If your program knows that it wants a pin to be HIGH it does not need to set it high to have that information. INPUT pins are for giving information to the Arduino. If it already has the information there is no need to give it again.

Please explain what you are trying to achieve.


I just want to know if that works. I am actually VB.NET programmers and there is that possible.

Hi Skino. I'm having trouble understanding how what you want to do is any different to the following :

If either the button on pin6 OR the button on pin2 is pressed then "turn the LED on pin13 and change some variables".

Something about this sounds like an x/y type of problem.

I can solve this with a variable that can be controlled by pin 6 and pin 2.
I just wanted to know if the virtual button press is possible on Arduino, regardless of its use or special code. And obviously that is not.

So the question is already answered. :slight_smile: