Coding and daughters power wheels=failing father(help)

Either way.

However, when we are troubleshooting things, it might be best to keep things minimal; then add in one component at a time and get it to work etc. …

1 Like

Very good sign ! :+1:

Wait a a few minutes, I’ll post code to test the pedal.

This sketch is not tested.

Connect the pedal/potentiometer to A0.

The code should raise and lower the motor speed in one direction.

// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>

SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial);      // Use SWSerial as the serial port.

const byte speedPot            = A0;

const byte heartbeatLED        = 13;
const byte forwardSwitch       = 3;
const byte backwardSwitch      = 2;

//timing stuff
unsigned long heartbeatTime;
unsigned long checkSwitchesTime;
unsigned long checkSSpeedPotTime;


//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(115200);
  
  SWSerial.begin(9600);

  pinMode(heartbeatLED, OUTPUT);

  pinMode(forwardSwitch, INPUT_PULLUP);
  pinMode(backwardSwitch, INPUT_PULLUP);  

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************              T I M E R  heartbeatLED
  //is it time to toggle heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //************************************************              T I M E R  checkSwitchesTime
  //is it time to read the switches and sensors ?
  if (millis() - checkSwitchesTime >= 50ul)
  {
    //restart this TIMER
    checkSwitchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  checkSpeedPot
  //is it time to read the switches and sensors ?
  if (millis() - checkSSpeedPotTime >= 50ul)
  {
    //restart this TIMER
    checkSSpeedPotTime = millis();

    checkSpeedPot();
  }

} //END of   loop()


//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

//  //*******************************************                       resetSwitch
//  state = digitalRead(resetSwitch);
//
//  //has there been a change reset switch state ?
//  if (lastResetSwitch != state)
//  {
//    //update to this new state
//    lastResetSwitch = state;
//
//    //is the reset switch pushed ?
//    if (state == PUSHED)
//    {
//      //disable object TIMER
//      detectedFlag = DISABLED;
//
//      digitalWrite(LED_PIN, LEDoff);
//    }
//
//  } //END of this switch

} //END of   checkSwitches()


//********************************************^************************************************
//                             c h e c k S p e e d P o t ( )
//********************************************^************************************************
void checkSpeedPot()
{
  //*******************************************                       speedPot
  int speed = (analogRead(speedPot)) / 8;

  Serial.println(speed);
  
  ST.motor(1, speed);

} //END of   checkSpeedPot()

If the sketch above works, connect the forward and reverse swithces and test this sketch.

This sketch is not tested:

// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>

//************************************************
#define Sabertooth

#ifdef Sabertooth
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial);      // Use SWSerial as the serial port.
#endif
//************************************************

#define PUSHED                   LOW
#define RELEASED                 HIGH

const byte speedPot            = A0;

const byte heartbeatLED        = 13;
const byte forwardSwitch       = 3;
const byte backwardSwitch      = 2;

byte lastForwardSwitch          = RELEASED;
byte lastBackwardSwitch         = RELEASED;

enum {REVERSE = -1, NEWTRAL = 0, FORWARD = 1 };

int directionFlag              = NEWTRAL;
int speed                      = 0;

//timing stuff
unsigned long heartbeatTime;
unsigned long checkSwitchesTime;
unsigned long checkSSpeedPotTime;


//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

#ifdef Sabertooth
  SWSerial.begin(9600);
#endif

  pinMode(heartbeatLED, OUTPUT);

  pinMode(forwardSwitch, INPUT_PULLUP);
  pinMode(backwardSwitch, INPUT_PULLUP);

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************              T I M E R  heartbeatLED
  //is it time to toggle heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //************************************************              T I M E R  checkSwitchesTime
  //is it time to read the switches and sensors ?
  if (millis() - checkSwitchesTime >= 50ul)
  {
    //restart this TIMER
    checkSwitchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  checkSpeedPot
  //is it time to read the switches and sensors ?
  if (millis() - checkSSpeedPotTime >= 50ul)
  {
    //restart this TIMER
    checkSSpeedPotTime = millis();

    checkSpeedPot();
  }

} //END of   loop()


//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

  //*******************************************                       forwardSwitch
  state = digitalRead(forwardSwitch);

  //has there been a change in the switch's state ?
  if (lastForwardSwitch != state)
  {
    //update to this new state
    lastForwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = FORWARD;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

  //*******************************************                       backwardSwitch
  state = digitalRead(backwardSwitch);

  //has there been a change in the switch's state ?
  if (lastBackwardSwitch != state)
  {
    //update to this new state
    lastBackwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = REVERSE;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

} //END of   checkSwitches()


//                             c h e c k S p e e d P o t ( )
//********************************************^************************************************
void checkSpeedPot()
{
  //*******************************************                       speedPot
  speed = directionFlag * (analogRead(speedPot)) / 8;

  Serial.println(speed);

#ifdef Sabertooth
  ST.motor(1, speed);
#endif

} //END of   checkSpeedPot()



//********************************************^************************************************

to this test i tried it the motor still runs constantly but does rev up with pedal. i tried to read volts on input to arduino i got 3.06v pedal not pushed. and .75v for pedal fully pressed.im wondering if my pedal is faulty even tho its brand new

(edit) or should i switch what voltage it reads to go and stop just reverse the numbers?

Please open your Serial monitor, set it to 115200 baud.

What is the maximum and minimum values printed on the monitor ?

setting (new line) 115200 baud, started at 4 im at 22 now but slowly going up. do i wait for it to complete? i havent used this part of software yet?

(edit) looks like its holding at 23, i see a 24 once in awile but goes back to 23

Is your monitor looking like this ?

2023-08-26_12-00-28

Please try this sketch, report what the maximum and minimum values printed are ?

// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>

//************************************************
//#define Sabertooth

#ifdef Sabertooth
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial);      // Use SWSerial as the serial port.
#endif
//************************************************

#define PUSHED                   LOW
#define RELEASED                 HIGH

const byte maximum             = 100;
const byte minimum             = 50;

const byte speedPot            = A0;

const byte heartbeatLED        = 13;
const byte forwardSwitch       = 3;
const byte backwardSwitch      = 2;

byte lastForwardSwitch          = RELEASED;
byte lastBackwardSwitch         = RELEASED;

enum {REVERSE = -1, NEWTRAL = 0, FORWARD = 1 };

int directionFlag              = NEWTRAL;
int speed                      = 0;

//timing stuff
unsigned long heartbeatTime;
unsigned long checkSwitchesTime;
unsigned long checkSSpeedPotTime;


//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

#ifdef Sabertooth
  SWSerial.begin(9600);
#endif

  pinMode(heartbeatLED, OUTPUT);

  pinMode(forwardSwitch, INPUT_PULLUP);
  pinMode(backwardSwitch, INPUT_PULLUP);

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************              T I M E R  heartbeatLED
  //is it time to toggle heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //************************************************              T I M E R  checkSwitchesTime
  //is it time to read the switches and sensors ?
  if (millis() - checkSwitchesTime >= 50ul)
  {
    //restart this TIMER
    checkSwitchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  checkSpeedPot
  //is it time to read the switches and sensors ?
  if (millis() - checkSSpeedPotTime >= 50ul)
  {
    //restart this TIMER
    checkSSpeedPotTime = millis();

    checkSpeedPot();
  }

} //END of   loop()


//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

  //*******************************************                       forwardSwitch
  state = digitalRead(forwardSwitch);

  //has there been a change in the switch's state ?
  if (lastForwardSwitch != state)
  {
    //update to this new state
    lastForwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = FORWARD;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

  //*******************************************                       backwardSwitch
  state = digitalRead(backwardSwitch);

  //has there been a change in the switch's state ?
  if (lastBackwardSwitch != state)
  {
    //update to this new state
    lastBackwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = REVERSE;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

} //END of   checkSwitches()


//                             c h e c k S p e e d P o t ( )
//********************************************^************************************************
void checkSpeedPot()
{
  //*******************************************                       speedPot
  speed = analogRead(speedPot);
  
  //speed = map(speed, maximum, minimum, 127, 0);
  //speed = constrain(speed, 0, 127);

  //speed = directionFlag * speed;

  Serial.println(speed);

#ifdef Sabertooth
  ST.motor(1, speed);
#endif

} //END of   checkSpeedPot()



//********************************************^************************************************

hmm will this write to arduino i dont have a laptop to record finding?

because the power wheels in my garage,im going back and forth between my pc doing all this lol

(edit) sorry forgot to say i did serial monitor while arduino was on pc not the power wheel.

  • The motor controller is disconnected from the Arduino.

  • The laptop needs to be connected to the UNO via USB.

  • The laptop serial monitor needs to be opened.

  • The pedal needs to be connected to the Arduino A0 pin as in your schematic.

ok sorry for misunderstanding. with the pedal im getting 176 depressed and 867 fully pressed.

thats same buad setup 115200 as before

Please reword ?

sorry i see 176 on monitor when the pedal is in "no go" postion just sitting there. When i fully push the pedal like to make motors go i see 867 on monitor. So my guess is arduino is seeing a higher than 176 reading and thats why motors are going constantly and not stopping.

Try this to see what gets printed on the serial monitor now ?

// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>

//************************************************
//#define Sabertooth

#ifdef Sabertooth
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial);      // Use SWSerial as the serial port.
#endif
//************************************************

#define PUSHED                   LOW
#define RELEASED                 HIGH

const int maximum             = 867;
const int minimum             = 176;

const byte speedPot            = A0;

const byte heartbeatLED        = 13;
const byte forwardSwitch       = 3;
const byte backwardSwitch      = 2;

byte lastForwardSwitch          = RELEASED;
byte lastBackwardSwitch         = RELEASED;

enum {REVERSE = -1, NEWTRAL = 0, FORWARD = 1 };

int directionFlag              = NEWTRAL;
int speed                      = 0;

//timing stuff
unsigned long heartbeatTime;
unsigned long checkSwitchesTime;
unsigned long checkSSpeedPotTime;


//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

#ifdef Sabertooth
  SWSerial.begin(9600);
#endif

  pinMode(heartbeatLED, OUTPUT);

  pinMode(forwardSwitch, INPUT_PULLUP);
  pinMode(backwardSwitch, INPUT_PULLUP);

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************              T I M E R  heartbeatLED
  //is it time to toggle heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //************************************************              T I M E R  checkSwitchesTime
  //is it time to read the switches and sensors ?
  if (millis() - checkSwitchesTime >= 50ul)
  {
    //restart this TIMER
    checkSwitchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  checkSpeedPot
  //is it time to read the switches and sensors ?
  if (millis() - checkSSpeedPotTime >= 50ul)
  {
    //restart this TIMER
    checkSSpeedPotTime = millis();

    checkSpeedPot();
  }

} //END of   loop()


//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

  //*******************************************                       forwardSwitch
  state = digitalRead(forwardSwitch);

  //has there been a change in the switch's state ?
  if (lastForwardSwitch != state)
  {
    //update to this new state
    lastForwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = FORWARD;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

  //*******************************************                       backwardSwitch
  state = digitalRead(backwardSwitch);

  //has there been a change in the switch's state ?
  if (lastBackwardSwitch != state)
  {
    //update to this new state
    lastBackwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = REVERSE;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

} //END of   checkSwitches()


//                             c h e c k S p e e d P o t ( )
//********************************************^************************************************
void checkSpeedPot()
{
  //*******************************************                       speedPot
  speed = analogRead(speedPot);
  speed = (map(speed, minimum, maximum, 0, 1023)) / 8;
  speed = constrain(speed, 0, 127);
  Serial.println(speed);
  //speed = directionFlag * speed;



#ifdef Sabertooth
  ST.motor(1, speed);
#endif

} //END of   checkSpeedPot()



//********************************************^************************************************

oh awesome, now it show 0 to 127 which i did see in original code,does this mean that i needed to convert the signal to work in the original code? im still learning the process just trying to follow what your doing,

Try this sketch version:

// Software Serial Sample
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>

//************************************************
#define Sabertooth

#ifdef Sabertooth
#include <SabertoothSimplified.h>
SoftwareSerial SWSerial(NOT_A_PIN, 11); // RX on no pin (unused), TX on pin 11 (to S1).
SabertoothSimplified ST(SWSerial);      // Use SWSerial as the serial port.
#endif
//************************************************

#define PUSHED                   LOW
#define RELEASED                 HIGH

const int maximum             = 867;
const int minimum             = 176;

const byte speedPot            = A0;

const byte heartbeatLED        = 13;
const byte forwardSwitch       = 3;
const byte backwardSwitch      = 2;

byte lastForwardSwitch          = RELEASED;
byte lastBackwardSwitch         = RELEASED;

enum {REVERSE = -1, NEWTRAL = 0, FORWARD = 1 };

int directionFlag              = NEWTRAL;
int speed                      = 0;

//timing stuff
unsigned long heartbeatTime;
unsigned long checkSwitchesTime;
unsigned long checkSSpeedPotTime;


//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  Serial.begin(115200);

#ifdef Sabertooth
  SWSerial.begin(9600);
#endif

  pinMode(heartbeatLED, OUTPUT);

  pinMode(forwardSwitch, INPUT_PULLUP);
  pinMode(backwardSwitch, INPUT_PULLUP);

} //END of   setup()


//                                       l o o p ( )
//********************************************^************************************************
void loop()
{
  //************************************************              T I M E R  heartbeatLED
  //is it time to toggle heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {
    //restart this TIMER
    heartbeatTime = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //************************************************              T I M E R  checkSwitchesTime
  //is it time to read the switches and sensors ?
  if (millis() - checkSwitchesTime >= 50ul)
  {
    //restart this TIMER
    checkSwitchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  checkSpeedPot
  //is it time to read the switches and sensors ?
  if (millis() - checkSSpeedPotTime >= 50ul)
  {
    //restart this TIMER
    checkSSpeedPotTime = millis();

    checkSpeedPot();
  }

} //END of   loop()


//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

  //*******************************************                       forwardSwitch
  state = digitalRead(forwardSwitch);

  //has there been a change in the switch's state ?
  if (lastForwardSwitch != state)
  {
    //update to this new state
    lastForwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = FORWARD;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

  //*******************************************                       backwardSwitch
  state = digitalRead(backwardSwitch);

  //has there been a change in the switch's state ?
  if (lastBackwardSwitch != state)
  {
    //update to this new state
    lastBackwardSwitch = state;

    //is the switch pushed ?
    if (state == PUSHED)
    {
      directionFlag = REVERSE;
    }

    else
    {
      directionFlag = NEWTRAL;
    }

  } //END of this switch

} //END of   checkSwitches()


//                             c h e c k S p e e d P o t ( )
//********************************************^************************************************
void checkSpeedPot()
{
  //*******************************************                       speedPot
  speed = analogRead(speedPot);
  speed = (map(speed, minimum, maximum, 0, 1023)) / 8;
  speed = constrain(speed, 0, 127);
  speed = directionFlag * speed;
  //Serial.println(speed);

#ifdef Sabertooth
  ST.motor(1, speed);
#endif

} //END of   checkSpeedPot()



//********************************************^************************************************

Connect the project as here:

Make sure the laptop is disconnected from the UNO when the Motor Controller is connected !

  • The heartbeatLED does not need to be connected.

I tried it out couldnt get it to work arduino is blinking,problem i have is getting 5v to everything that needs it,i use the 5v on motor controller to vin on arduino to power that, i will have to find a distribution block so i can 5v to 3 way switch and the pedal/potentiometer.unless i just delete the switch and make forward only..which would be fine also.

also i left dip switches on 9600, do i need to change those to 115200?