Things used in this project

Schematics

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

Code

Robot control codeArduino
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 GerwerArduino
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

Msp
Ahmed Hamdy

Computer and Communications engineering student, Programming addict, Arduino lover, Teaching the future generations

Contact
E7483e9a8f0f6e8bdefd7ee6845d9430
Garry Gerwer

Hobbyist

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Using CA and CC RGB LED by Current Sourcing and Sinking!
Easy
  • 562
  • 48

Protip

RGB LEDs are of two types, common cathode and common anode which behave differently with same Arduino code; how to resolve this.

Arduino Amiga Floppy Disk Reader
Easy
  • 5,504
  • 8

Work in progress

An Arduino powered floppy disk controller and reader for making disk images from old AmigaDOS floppy disks.

Simple Dark Sensor
Easy
  • 105
  • 2

A simple dark sensor with or without Arduino.

Quadrature Encoder Demo
Easy
  • 724
  • 4

Full instructions

Use a 3D printed encoder wheel, LED, and 2 photocells to demonstrate how a quadrature encoder works.

Physical Computing - Scratch for Arduino
Easy
  • 233
  • 3

Full instructions

Scratch is a great tool to teach beginners how to code, program interactive stories, and do Physical Computing!

How to use the accelerometer- gyroscope GY-521
Easy
  • 326
  • 2

Full instructions

Find out how the world turns. Read the values of the accelerometer and the gyroscope.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login