Coding and daughters power wheels=failing father(help)

Hi everyone, I hope this is the correct place to post this?I'm sorry if it isnt i will delete if needed.

So my daughters power wheels controller went out and i had motor controller sitting for a rc mower project. Anyways thought i'd try my hand at an arduino as a controller. Got someone on fivver to do some code for me as im not any good at it yet. i got everything wired up to spec 13.07v from battery, sabertooth 2x60 seems to be working order no error lights, but when i power up system my switch for fwd,ntl,rvs, changes the speeds? and the motor constantly runs without pedel being pushed. I will post code if anyone can give me advice it would be appreciated.Use code tags to format code for the forum





#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 int forward_pin=3;
const int backward_pin=2;

void setup()
{
  SWSerial.begin(9600);
  pinMode(forward_pin,INPUT_PULLUP);
  pinMode(backward_pin,INPUT_PULLUP);
}

void loop()
{
  int Speed=analogRead(A0);
  int F=digitalRead(forward_pin);
  int B=digitalRead(backward_pin);
  int dir=0;
  int power=0;
  
  if (F==0 && B==1)
  {
    dir=1;
    power=map(Speed,0,1023,64,127);
    ST.motor(1, power);
    delay(20);
    power=power+128;
    ST.motor(1, power);
    delay(20);
  }
  else if (F==1 && B==0)
  {
    dir=2;
    power=map(Speed,0,1023,1,64);
    ST.motor(1, power);
    delay(20);
    power=power+128;
    ST.motor(1, power);
    delay(20);
  }
  else if (F==1 && B==1)
  {
    dir=0;
    
    ST.motor(1, 64);
    delay(20);
  
    ST.motor(1, 192);
    delay(20);
  
    ST.motor(1, 0);
    delay(20);
  }
//1 is full reverse, 64 is stop and 127 is full forward. 
//128 is full reverse, 192 is stop and 255 is full forward.

}


this is my version of wiring diagram using paint haha it works for me.

The Red wire on Arduino Vin pin goes where ?

Vin should be 7-9 volts.


Suggest you add a fuse to the 12V battery connection.

1 Like

maybe thats my problem,sabertooth said i could power arduino off the 5v of motor controller to
vin arduino, while i use the 5v on arduino to operate pedal.but now that you said that if i need 5v for pedal...how is arduino being powered?proly underpowered?

An UNO can be powered by it’s 5v pin.

i.e. An external 5v power supply connected to the Arduino 5v pin will work.

Note, don’t power the UNO via the USB when an external 5v power supply is connected to the UNO 5v pin.

roger that, so im thinking then i need a dedicated 5v power source for arduino and i can then use the 5v of sabertooth to complete the pedal system? does sound correct? since vin is "in" power only not a output like 5v correct?

If the controller has a 5v output pin, this can be used to power the UNO 5v pin; just avoid plugging a PC USB cable into the UNO when the controller is connected to the UNO 5v pin.

i can do that. I have no need for usb in this project. so the problem most likely lies in my code then,or the pedal i have is faulty and not sending right signals.

When the pedal is operated, what is the range in voltage on your A0 UNO pin ?

Is the baud rate correct ?
This is the baud rate you chose with the DIP switches

i will have to check the voltage on the pedal but baud rate is 9600 and per sabertooth support my dip switches are correct.


    ST.motor(1, power);
    delay(20);

You do know 20 milliseconds is very fast ?

Did you mean delay(2000); //2 seconds ?

i can change it and try that. it will take some time though thank you.

Always comment your lines of code with good descriptions.


Does this example work ?


// 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.
void setup()
{
  SWSerial.begin(9600);
}
void loop()
{
  int power;
  
  // Ramp from -127 to 127 (full reverse to full forward), waiting 20 ms (1/50th of a second) per value.
  for (power = -127; power <= 127; power ++)
  {
    ST.motor(1, power);
    delay(20);
  }
  
  // Now go back the way we came.
  for (power = 127; power >= -127; power --)
  {
    ST.motor(1, power);
    delay(20);
  }
}

I haven't analysed the schematic of an arduino Uno. From ESP8266 / ESP32 it is very common that between USB-5V and Vin there is a protection schottky-diode (voltage-drop across diode 0,2V) to stop current flowing from Vin into USB.

And the Arduino does not have such a protection-diode?
If not you could add one externally.

Arduino 5V-Pin-----------|<------------external 5V-power-supply

best regards Stefan

1 Like

The UNO does not have this diode, there is the possibility when powering the 5v pin it can feed back to the PC through to the USB cable.

When programming the UNO, disconnect the external power supply going the the UNO 5v pin if connected.

1 Like

Am I running this code like this? or am i removing some and adding this to it?

It is a known example that should move the motor back and forth.

We often use a basic sketch (that has been proven to work in the past) which confirms our hardware is properly connected; if the sketch works, we can conclude our wiring is okay.

This example can be compared to a sketch that doesn’t work to help us find programming problems.

We can modify this basic sketch, a bit at a time, which hopefully prevents errors in our code generation.

1 Like

ok i will upload sketch and try it thank you.should i plug all periperials in like pedal and 3 way switch or just motor controller

https://youtube.com/shorts/SlVX_sxaJSM

this is a video i sent to my fiverr guy,hes not really helpful honestly,might pay someone on here to redo code if need be.but this is the problems i am having.

i tried the sketch it worked and the wheels ramped up in speed slowly and slowed down to stop in repeat. so does that mean the wiring is ok?