bigboystoys13
Published

R/C Traxxas Slash with Arduino and 1Sheeld

Control a R/C truck using your smartphone.

IntermediateWork in progress14,761

Things used in this project

Hardware components

1Sheeld
1Sheeld
×1
Traxxas Slash
Steering Servo, Electronic Speed Control (ESC), Motor and Battery
×1
Arduino UNO
Arduino UNO
DIYmall ( http://amzn.com/B010DHHD5O )
×1
JBtek Breadboard Power Supply
×1

Story

Read more

Schematics

Project Diagram

Code

Untitled file

Arduino
#define CUSTOM_SETTINGS
#define INCLUDE_ORIENTATION_SENSOR_SHIELD

/* Include 1Sheeld and Servo library. */
#include <OneSheeld.h>
#include <Servo.h>

// Create two servo objects
Servo myservo; 
Servo myservo2;

// Setup a few variables
int posY = 90;   
int posZ = 90;
int posY2 = 90;
int posZ2 = 90;

void setup()
{
 // Attach servo objects to output pins
  myservo.attach(9);  // Steering server
  myservo2.attach(10);  // Electronic Speed Control (ESC) for motor

  OneSheeld.begin();
}

void loop()
{
// Pull in Y/Z values for orientation sensor, constrain them to certain limits
  posY2 = constrain(OrientationSensor.getY(), -40, 40);
/* I turned the phone left/right, and figured that it was going -40 to 40 degrees
 * Your device may have different values.
 */
  
  posZ2 = constrain(OrientationSensor.getZ(), 0, 70);
// Phone flat = 0
  
  posY = map(posY2, -40, 40, 145, 35);
  posZ = map(posZ2, 0,70,90,135);
/* Used the map function to tie the orienation sensor ranges to servo position values
 * Servo position values are 0 to 180
 * For steering (posY) I used 35 to 145, which seemed to be the limits of the steering setup
 * For motor (pos Z) I used 90 to 135.  This is basically 0 to 50% power, no reverse/brake
 */

 // Sent position to servo
  myservo.write(posY);  
  myservo2.write(posZ);
  delay(5);
}

Untitled file

Arduino
#define CUSTOM_SETTINGS
#define INCLUDE_ORIENTATION_SENSOR_SHIELD

/* Include 1Sheeld and Servo library. */
#include <OneSheeld.h>
#include <Servo.h>

// Create two servo objects
Servo myservo; 
Servo myservo2;

// Setup a few variables
int posY = 90;   
int posZ = 90;
int posY2 = 90;
int posZ2 = 90;

void setup()
{
 // Attach servo objects to output pins
  myservo.attach(9);  // Steering server
  myservo2.attach(10);  // Electronic Speed Control (ESC) for motor

  OneSheeld.begin();
}

void loop()
{
// Pull in Y/Z values for orientation sensor, constrain them to certain limits
  posY2 = constrain(OrientationSensor.getY(), -40, 40);
/* I turned the phone left/right, and figured that it was going -40 to 40 degrees
 * Your device may have different values.
 */
  
  posZ2 = constrain(OrientationSensor.getZ(), 0, 70);
// Phone flat = 0
  
  posY = map(posY2, -40, 40, 145, 35);
  posZ = map(posZ2, 0,70,90,135);
/* Used the map function to tie the orienation sensor ranges to servo position values
 * Servo position values are 0 to 180
 * For steering (posY) I used 35 to 145, which seemed to be the limits of the steering setup
 * For motor (pos Z) I used 90 to 135.  This is basically 0 to 50% power, no reverse/brake
 */

 // Sent position to servo
  myservo.write(posY);  
  myservo2.write(posZ);
  delay(5);
}

Codebender

Credits

bigboystoys13

bigboystoys13

11 projects • 46 followers

Comments