Things used in this project

Hardware components:
12757 01
SparkFun RedBoard
×1

Code

Redbot SoftwareC/C++
/*****************************************************************
XBee_Remote_Control.ino

*****************************************************************/
#include <RedBot.h>  // This line "includes" the RedBot library into your sketch.
// Provides special objects, methods, and functions for the RedBot.
RedBotMotors motors; // Instantiate the motor control object. This only needs

#include "notes.h"  // Individual "notes" have been #defined in the notes.h tab to make
// playing sounds easier. noteC4, for example, is defined as 262, the
// frequency for middle C. See the tab above?

RedBotSoftwareSerial XBee;  // version of SoftwareSerial that will work with Redbot

const int buzzerPin = 9;

int xval;
int yval;
int swval=1023;
int leftmotorspeed;
int rightmotorspeed;

float temp;

void setup()
{
	// Initialize XBee Software Serial port. Make sure the baud
	// rate matches your XBee setting (9600 is default).
	XBee.begin(9600);
	Serial.begin(9600);
	pinMode(buzzerPin, OUTPUT);
}

void loop()
{

//	if (XBee.available())
	if (XBee.available())
	{
		xval = XBee.read();
		yval = XBee.read();
		swval = XBee.read();
		//xval = Serial.read();
		//yval = Serial.read();
		//swval = Serial.read();

		//normalize the values to a 1 byte value

		temp = (float)xval / (float)255;
		xval = temp * 1023;

		temp = (float)yval / (float)255;
		yval = temp * 1023;

		temp = (float)swval / (float)255;
		swval = temp * 1023;

		xval = map(xval, 0, 1023, -255, 255);
		yval = map(yval, 0, 1023, -255, 255);

	}

	if(swval == 0) 
	{
		XBee.end();
	//	playSmallWorld();
		blowhorn();
		XBee.begin(9600);
	}
	
	if (xval > -40 && xval < 40)  			// If we are not turning
	{										
		if ((yval < -40) || (yval > 40))    // set motor speed
		{
			rightmotorspeed = yval;
			leftmotorspeed = -yval; 
		}
		else
		{
			rightmotorspeed = 0;
			leftmotorspeed = 0;		
		}
     
	}
	else if (xval>40)  // Turning Left, are we moving while turning left or 
	{					// spinning
		if ((yval < -40) || (yval > 40)) // User is moving forward or backwards
		{
			rightmotorspeed = yval; 	// drive right motor 100% forward
			leftmotorspeed = -yval/2;	// runt left by slowing left wheel
		}
		else    						// spin
		{
			rightmotorspeed = 200;
			leftmotorspeed = 200;
		}
	}
	else			// We are not going straight or turning left, must be right
	{
		if ((yval < -40) || (yval > 40))    // user is moving forward or backwards
		{
			leftmotorspeed = -yval;
			rightmotorspeed = yval/2;
		}
		else
		{
			rightmotorspeed = -200;
			leftmotorspeed = -200;
		}
	}

	motors.rightMotor(rightmotorspeed);
	motors.leftMotor(leftmotorspeed);
	delay(50);
}

void blowhorn()
{
	tone(buzzerPin, 1000);   // Play a 1kHz tone on the pin number held in
	//  the variable "buzzerPin".
	delay(125);   // Wait for 125ms.
	noTone(buzzerPin);   // Stop playing the tone.

	tone(buzzerPin, 2000);  // Play a 2kHz tone on the buzzer pin

	delay(500);   // delay for 1000 ms (1 second)

	noTone(buzzerPin);       // Stop playing the tone.

}

void playSmallWorld()
{
	// we use a custom function below called playNote([note],[duration])
	// to play a note and delay a certain # of milliseconds.
	//
	// Both notes and durations are #defined in notes.h -- WN = whole note,
	// HN = half note, QN = quarter note, EN = eighth note, SN = sixteenth note.
	//
	playNote(noteG5, HN + QN);
	playNote(noteG5, QN);
	playNote(noteB5, HN);
	playNote(noteG5, HN);
	playNote(noteA5, HN + QN);
	playNote(noteA5, QN);
	playNote(noteA5, HN + QN);
	playNote(Rest, QN);
	playNote(noteA5, HN + QN);
	playNote(noteA5, QN);
	playNote(noteC6, HN);
	playNote(noteA5, HN);
	playNote(noteB5, HN + QN);
	playNote(noteB5, QN);
	playNote(noteB5, HN + QN);
	playNote(Rest, QN);
	playNote(noteB5, HN + QN);
	playNote(noteB5, QN);
	playNote(noteD6, HN);
	playNote(noteB5, HN);
	playNote(noteC6, HN + QN);
	playNote(noteC6, QN);
	playNote(noteC6, HN);
	playNote(noteB5, QN);
	playNote(noteA5, QN);
	playNote(noteD5, WN);
	playNote(noteFs5, WN);
	playNote(noteG5, WN);
}

void playNote(int note, int duration)
// This custom function takes two parameters, note and duration to make playing songs easier.
// Each of the notes have been #defined in the notes.h file. The notes are broken down by
// octave and sharp (s) / flat (b).
{
	tone(buzzerPin, note, duration);
	delay(duration);
}
XBee ControllerC/C++
/*****************************************************************
XBee_Remote_Controller.ino

*****************************************************************/
// SoftwareSerial is used to communicate with the XBee
#include <SoftwareSerial.h>

// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX

//values read from joy stick i.e. (0-1023)
int xval = 0;
int yval = 0;
int swval = 0;
int xval2 = 0;
int yval2 = 0;
int swval2 = 0;
float temp;


const int xpin = A1;
const int ypin = A2;
const int swpin = A0;   // this is the

const int xpin2 = A4;
const int ypin2 = A5;
const int swpin2 = A3;




void setup()
{
	// Initialize XBee Software Serial port. Make sure the baud
	// rate matches your XBee setting (9600 is default).
	XBee.begin(9600);
	Serial.begin(9600);
	
	// enable pull up on analog pins that are connected to the SEL output
	// of the joystick
	//digitalWrite(A0, HIGH);
	//digitalWrite(A3, HIGH);
}

void loop()
{
	xval = analogRead(xpin);
	temp = (float)xval / (float)1023;
	xval = 255 * temp;

	swval = analogRead(swpin);			// only concered if swval is 0
	if (swval != 0) swval = 255;

	yval2 = analogRead(ypin2);
	temp = (float)yval2 / (float)1023;
	yval2 = 255 * temp;

	swval2 = analogRead(swpin2);


	if (swval2 != 0) swval2 = 255;


	XBee.write(xval);  // This first code will be interpreted for steering
	XBee.write(yval2);  // motor drive
	XBee.write(swval);

	Serial.print("swval = ");
	Serial.println(swval);
	delay(50);
	if (swval == 0) delay(600);  // horn was pressed, give user time to release'

}

Credits

Eeaaadbab52b1bceca5051c9ec1cc4fa
David A Riewe

Engineering Tech who enjoys hacking electronics, learning about new devices and programming. Founder of HackerSpaceTech

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

Save your life with the Building Collapse Monitor
Easy
  • 105
  • 4

Work in progress

Analyse concrete, metal, wood structures for bends and angles and alerts if they have deviated from the original position.

near-perfect gyroscope
Easy
  • 483
  • 7

Work in progress

this code lets you make an accelerometor & gyroscope give the best results.

Chug Meter for St. Patrick's Day by Circuito.io
Easy
  • 1,968
  • 11

Full instructions

Let’s settle once and for all - who is the fastest chugger of ‘em all?

ExaGear Desktop Virtual Machine for Raspberry Pi
Easy
  • 68
  • 2

Full instructions

Make common solutions for PC work on ARM-based for any purpose and level of difficulty.

ESP8266 + L298N Motor Drive + Smartphone
Easy
  • 1,689
  • 7

Protip

Control an Arduino robot with a smartphone using ESP8266.

Run Dropbox on Raspberry Pi
Easy
  • 179
  • 3

Protip

Host files with popular app Dropbox on your Raspberry Pi device. Easy and fast step-by-step guide.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback