vehicle that starts on a button push

I will start out by saying that I have never done any coding before. In my engineering 1201 course we were challenged with making a vehicle that with the push of a button travels for 5 seconds then stops and then does that every time the button is pushed. I have the mechanical part of the vehicle build but I have no idea how to code or build the Arduino and breadboard. The materials I have are a SparkFun Red board, a bread board, jumper cables, a button, then transistors and resistors. Please help me I don't know what else to do.

“Transistors and resistors” is a bit non-specific.

Start from the motor. What is the specification on the motor for voltage and current? You really need the “stall current” which is not usually quoted for motors. If you have the running current then multiply that by 4 to get an idea of the stall current.

Then you need batteries or a power supply which can supply that current and voltage.

Then you need a motor controller (or “driver”) to control the power to the motor. That’s going to be the most important part of the electronic hardware.

You can use this as a basic framework for the code. I haven't added any motor control stuff but indicated where it would go.

//state machine state names
#define LOOK_FOR_PRESS      0
#define RUN_MOTOR           1

#define MOTOR_RUN_TIME      5000ul      //5000mS == 5-seconds run time

const byte pinSwitch = 2;
//const byte motor control pins

//variables
unsigned long
    tMotor;             //stores time in millis() motor was started
byte
    state,              //tracks what state we're in
    swLast;             //tracks the last button read state
    
void setup() 
{
    //set the pin modes
    //button is NO-MOM that is grounded when pressed
    pinMode( pinSwitch, INPUT_PULLUP );
    swLast = digitalRead( pinSwitch );

    //pinMode for motor controls

    state = LOOK_FOR_PRESS;
    
}//setup

void loop() 
{
    switch( state )
    {
        case    LOOK_FOR_PRESS:
            //here we look for a press of the button using state-change
            byte swNow = digitalRead( pinSwitch );
            if( swNow != swLast )
            {
                //this sw reading is not the same as the reading
                swLast = swNow;
                if( swNow == LOW )
                {
                    //button reads low now indicating a state change from high to low (i.e. a "press")
                    
                    //turn on motor
                    //...
                    
                    //save the time the motor is turned on
                    tMotor = millis();
                    //next time through loop() we go to the RUN_MOTOR case/state
                    state = RUN_MOTOR;
                }//if
                
            }//if
            
        break;

        case    RUN_MOTOR:
            //has the motor been on for 5-sec?
            if( millis() - tMotor >= MOTOR_RUN_TIME )
            {
                //yes; turn motor off
                //...

                //then go back to looking for a button press
                state = LOOK_FOR_PRESS;
            }//if
            
        break;
        
    }//switch

}//loop

Please help me I don't know what else to do.

Work through the examples in the Arduio IDE, on this web site and else where, that will give you an understanding of basic programming. If you get stuck with an example ask for help. Also search these fora for examples of similar projects and study those.

Good luck.

@thockey16

DUPLICATE DELETED.

Please read THIS POST to help you get the best out of the forum.

Bob.

Blackfin:
You can use this as a basic framework for the code. I haven't added any motor control stuff but indicated where it would go.

//state machine state names

#define LOOK_FOR_PRESS      0
#define RUN_MOTOR          1

#define MOTOR_RUN_TIME      5000ul      //5000mS == 5-seconds run time

const byte pinSwitch = 2;
//const byte motor control pins

//variables
unsigned long
    tMotor;            //stores time in millis() motor was started
byte
    state,              //tracks what state we're in
    swLast;            //tracks the last button read state
   
void setup()
{
    //set the pin modes
    //button is NO-MOM that is grounded when pressed
    pinMode( pinSwitch, INPUT_PULLUP );
    swLast = digitalRead( pinSwitch );

//pinMode for motor controls

state = LOOK_FOR_PRESS;
   
}//setup

void loop()
{
    switch( state )
    {
        case    LOOK_FOR_PRESS:
            //here we look for a press of the button using state-change
            byte swNow = digitalRead( pinSwitch );
            if( swNow != swLast )
            {
                //this sw reading is not the same as the reading
                swLast = swNow;
                if( swNow == LOW )
                {
                    //button reads low now indicating a state change from high to low (i.e. a "press")
                   
                    //turn on motor
                    //...
                   
                    //save the time the motor is turned on
                    tMotor = millis();
                    //next time through loop() we go to the RUN_MOTOR case/state
                    state = RUN_MOTOR;
                }//if
               
            }//if
           
        break;

case    RUN_MOTOR:
            //has the motor been on for 5-sec?
            if( millis() - tMotor >= MOTOR_RUN_TIME )
            {
                //yes; turn motor off
                //...

//then go back to looking for a button press
                state = LOOK_FOR_PRESS;
            }//if
           
        break;
       
    }//switch

}//loop

Thank you so much this was so helpful, will keep yall updated on how it goes