Ahmed Hamdy Mahmoud HassaneinGarry Gerwer
Published © GPL3+

Super Easy to Build 1Sheeld 2 Wheel Drive Robot

This tutorial guides you through using 1Sheeld, Arduino and an Android phone to make an RC robot car at a glance.

BeginnerFull instructions provided1 hour30,133
Super Easy to Build 1Sheeld 2 Wheel Drive Robot

Things used in this project

Story

Read more

Schematics

Robot Chassis

Author
https://grabcad.com/library/chassis-of-a-2wd-autonomous-robot-1

Code

Robot control code

Arduino
Differential drive robot code
/*

Gamepad Shield Example

This example shows an application on 1Sheeld's gamepad shield.

OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.

*/

int ledPin = 13;
#define CUSTOM_SETTINGS
/* Use the game pad */
#define INCLUDE_GAMEPAD_SHIELD

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

// Motor objects, motor number on the motor shield board
AF_DCMotor motorLeft(1);
AF_DCMotor motorRight(2);

void setup()
{
	/* Start communication. */
	OneSheeld.begin();

	// The LED just works as an indicator that the 1Sheeld is working fine
	pinMode(ledPin, OUTPUT);

	motorLeft.setSpeed(100);
	motorRight.setSpeed(100);
}

void loop()
{
	/* Always check the status of gamepad buttons. */
	if (GamePad.isDownPressed())
	{
		motorLeft.run(BACKWARD);
		motorRight.run(BACKWARD);


		digitalWrite(ledPin, HIGH);
	}
	else if (GamePad.isUpPressed())
	{
		motorLeft.run(FORWARD);
		motorRight.run(FORWARD);
		digitalWrite(ledPin, HIGH);
	}
	else if (GamePad.isLeftPressed())
	{
		motorLeft.run(BACKWARD);
		motorRight.run(FORWARD);
		digitalWrite(ledPin, HIGH);
	}
	else if (GamePad.isRightPressed())
	{
		motorLeft.run(FORWARD);
		motorRight.run(BACKWARD);
		digitalWrite(ledPin, HIGH);
	}
	else
	{
		motorLeft.run(RELEASE);
		motorRight.run(RELEASE);
		digitalWrite(ledPin, LOW);
	}
}

Modified code for v2.3 library by Garry Gerwer

Arduino
Created by Garry Grewer, this code works for the newer version of the motor shield v2.3
/*Gamepad Shield Example
This example shows an application on 1Sheeld's gamepad shield.

******* This is modified to use the adafruit motorshield V2.3 *********

OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.*/

int ledPin = 13;
#define CUSTOM_SETTINGS
/* Use the game pad /
/ Include 1Sheeld library. */
#define INCLUDE_GAMEPAD_SHIELD
#include <OneSheeld.h>
//#include <AFMotor.h>
#include <Adafruit_MotorShield.h> //for v2.3 motorshield

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

// Motor objects, motor number on the motor shield board
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

void setup()
{
/* Start communication. */
OneSheeld.begin();
AFMS.begin();

// The LED just works as an indicator that the 1Sheeld is working fine
pinMode(ledPin, OUTPUT);
myMotor->setSpeed(150);
myOtherMotor->setSpeed(150);

}
void loop()
{
/* Always check the status of gamepad buttons. */
if (GamePad.isDownPressed())
{
myMotor->run(BACKWARD);
myOtherMotor->run(BACKWARD);

digitalWrite(ledPin, HIGH);
}
else if (GamePad.isUpPressed())
{
myMotor->run(FORWARD);
myOtherMotor->run(FORWARD);
digitalWrite(ledPin, HIGH);
}
else if (GamePad.isLeftPressed())
{
myMotor->run(BACKWARD);
myOtherMotor->run(FORWARD);
digitalWrite(ledPin, HIGH);
}
else if (GamePad.isRightPressed())
{
myMotor->run(FORWARD);
myOtherMotor->run(BACKWARD);
digitalWrite(ledPin, HIGH);
}
else
{
myMotor->run(RELEASE);
myOtherMotor->run(RELEASE);
digitalWrite(ledPin, LOW);
}
}

Credits

Ahmed Hamdy Mahmoud Hassanein

Ahmed Hamdy Mahmoud Hassanein

8 projects • 129 followers
I'm a Muslim Computer Engineer, I do a bit of hardware and any software I'm glad to receive your questions >> ahmedhamdyau@gmail.com peace!
Garry Gerwer

Garry Gerwer

1 project • 8 followers
Hobbyist

Comments