Can I use a transistor instead of a push button?

Hi guys,

I need some help with my project please, basically Im trying to make a circuit which controls a motor in forward and reverse mode but wirelessly using a USB Host Shield + Bluetooth dongle and controlling it with a ps3 controller but the problem is I have seen a circuit on the web its this one: http://api.ning.com/files/jFhR10F2nKDm5cJ0p2jcpgHpKd4hNPz01QgMS8OF6QUh82aIgvr-dp1uzQSopb*PQgSlhFEgj5ALhek3X56Zq6xDZuw-9vwD/l293dmontagem.jpeg

basically in that picture there is a push button and what I wanted to do was have a wireless project but because of the push button it is not allowing me to advance further so I was wondering could I use some sort of transistor to act as that switch but that the switiching would be controlled by the arduino itself? or is there any other way where I could get the arduino to do the switching

here is the Arduino code that was on the website where I found that picture:

int switchPin = 2; // switch input
int motor1Pin1 = 3; // pin 2 on L293D
int motor1Pin2 = 4; // pin 7 on L293D
int enablePin = 9; // pin 1 on L293D

void setup() {    // set the switch as an input:    

pinMode(switchPin, INPUT);    // set all the other pins you're using as outputs:    
pinMode(motor1Pin1, OUTPUT);    pinMode(motor1Pin2, OUTPUT);    pinMode(enablePin, OUTPUT);    // set enablePin high so that motor can turn on:    

digitalWrite(enablePin, HIGH);

}

void loop() {    // if the switch is high, motor will turn on one direction:    

if (digitalRead(switchPin) == HIGH) 

{        

digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low

digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D high    

}    // if the switch is low, motor will turn in the opposite direction:    

else

{        

digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high        

digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low

  }
}

I think you’re overthinking this… The “if” that checks if the switch is pressed or not, does the reversing of the motor through the L293 which is already a bunch of transistors.

If the Arduino is accessible to you via USB and BT, about which I know <0 I might add, you already have access to the L293 tht way.

So you could do something like this… instead of:

if (digitalRead(switchPin) == HIGH)

… say something like:

if (blueToothSignal == ClockWise)

That’s totally conceptual of course, I have no idea what a BT signal looks like, but I’m sure you can pick up from here.

I tried that in the below code it didnt work too well but yea what i actually wanted to do was if I pressed the UP button the motor would run forward and if I pressed DOWN it would run in reverse but I cant seem to figure it out hence why I asked about the switching

 #include <PS3BT.h>
#include <Servo.h>
Servo manzoorsServo;

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);
 
int motor1Pin1 = 3; // pin 2 on L293D 
int motor1Pin2 = 4; // pin 7 on L293D 
int servoPin = 6;

void setup()

  { 
    
    pinMode(motor1Pin1, OUTPUT);       
    pinMode(motor1Pin2, OUTPUT);    
    manzoorsServo.attach(servoPin);

  {
    Serial.begin(115200);
    if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while(1);
  }
    Serial.print(F("\r\nPS3 Bluetooth Library Started"));
 }

}
 
void loop() {
  Usb.Task();

  if(PS3.PS3Connected || PS3.PS3NavigationConnected) 

       {
       manzoorsServo.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 120));
       }
       else
       {
       manzoorsServo.write(115);
       }      

if (PS3.getButtonClick(UP))

{

digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low   

digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high        

}

if (PS3.getButtonClick(DOWN))

{

digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high          

digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low     
      
}

       if(PS3.getButtonClick(PS)) {
       manzoorsServo.write(115);
       PS3.disconnect();
       }
      }

As you can see from this I have removed the switchpin because like I said I want the motor to go forward when I press UP and reverse when I press DOWN

Greats minds thinking alike then....

If I were you I'd use Serial.println() to print messages to the console so you can see if the logic is actually taking you where you expect / hope. Print a message like "I should be going forward now" or whatever, in the appropriate legs of the if statements.