Mike86
Published

Joystick Wireless Remote Control Car

In this application note, we will combine several products in imall.iteadstudio.com to make a joystick wireless remote control car.

BeginnerFull instructions provided30 minutes1,390
Joystick Wireless Remote Control Car

Things used in this project

Hardware components

Iteaduino-BT Arduino Compatible Board With Master/Slave Bluetooth Wireless Module HC-05
×1
ITEAD 4 Buttons Joystick Shield Module For Arduino UNO MEGA R3 Mega2560
×1
Itead MBoard Arduino Board Kit For Home Automation Or Robot Control
×1
Itead Starter Robot Car Kit
×1
Itead BTBee
×1
9V lithium battery
×2

Story

Read more

Schematics

Schematics of Iteaduino BT

Schematics of Itead Joystick Shield

Schematics of Mboard

Schematics of BT Bee

Code

Untitled file

C/C++
#define _US 0x5553
#define _DS 0x4453
#define _LS 0x4C53
#define _RS 0x5253
#define _UL 0x554C
#define _DL 0x444C
#define _UR 0x5552
#define _DR 0x4452

#define _SS 0x5353

#define ENA 10
#define ENB 11
#define IN1 7
#define IN2 8
#define IN3 12
#define IN4 13

#define LOWSPEED 100
#define HIGHSPEED 200

#define IN1_HIGH	PORTE |=0x40
#define IN1_LOW		PORTE &=~0x40
#define IN2_HIGH	PORTB |=0x10
#define IN2_LOW		PORTB &=~0x10
#define IN3_HIGH	PORTD |=0x40
#define IN3_LOW		PORTD &=~0x40
#define IN4_HIGH	PORTC |=0x80
#define IN4_LOW		PORTC &=~0x80
#define ENA_HIGH	PORTB |=0x40
#define ENA_LOW		PORTB &=~0x40
#define ENB_HIGH	PORTB |=0x80
#define ENB_LOW		PORTB &=~0x80

uint16_t value;

uint8_t r_buffer[4];

uint8_t number;
uint8_t command;


void setup(){
	pinMode(ENA,OUTPUT);
	pinMode(ENB,OUTPUT);
	pinMode(IN1,OUTPUT);
	pinMode(IN2,OUTPUT);
	pinMode(IN3,OUTPUT);
	pinMode(IN4,OUTPUT);
	//ENA_HIGH;   
	//ENB_HIGH 

	
       run(0);


Serial1.begin(9600);

}

void loop(){

	if(Serial1.available())
	{
		uint8_t readbuf = Serial1.read();
		r_buffer[number]=readbuf;
		number++;
		
		if(readbuf==0x3B)
		{	
			if(number==3)
			{
				value = (r_buffer[0]<<8) | (r_buffer[1]);
			}
			number=0;
			command=1;

		}
	

	
	}



	if(command)
	{
		command=0;
		switch(value)
		{
  			case _SS:	run(0);break;
			case _US:	run(1);break;
			case _DS:	run(2);break;
			case _LS:	run(3);break;
			case _RS:	run(4);break;
			case _UL:	run(5);break;
			case _UR:	run(6);break;
			case _DL:	run(7);break;
			case _DR:	run(8);break;

		
		}
	
	
	}





}



void forward()
{
	ENA_HIGH; 
	ENB_HIGH;
	IN1_HIGH; 
	IN2_LOW;
	IN3_HIGH; 
	IN4_LOW; 
}

void backward()
{
	ENA_HIGH; 
	ENB_HIGH;
	IN1_LOW; 
	IN2_HIGH;
	IN3_LOW; 
	IN4_HIGH; 
}

void turnleft()
{
	ENA_HIGH; 
	ENB_HIGH;
	IN1_LOW; 
	IN2_LOW;
	IN3_HIGH; 
	IN4_LOW; 
}

void turnright()
{
	ENA_HIGH; 
	ENB_HIGH;
	IN1_HIGH; 
	IN2_LOW;
	IN3_LOW; 
	IN4_LOW; 
}

void stopcar()
{
	ENA_LOW; 
	ENB_LOW;
	IN1_LOW; 
	IN2_LOW;
	IN3_LOW; 
	IN4_LOW; 
}

void run(int direct)
{
	switch(direct)
	{
		case 0: 
				IN1_LOW; 
				IN2_LOW;
				IN3_LOW; 
				IN4_LOW; 
				analogWrite(ENA,0);
				analogWrite(ENB,0);
				break;
		case 1: 
				IN1_HIGH; 
				IN2_LOW;
				IN3_HIGH; 
				IN4_LOW; 
				analogWrite(ENA,LOWSPEED);
				analogWrite(ENB,LOWSPEED+30);
				break;
		case 2:
				IN1_LOW; 
				IN2_HIGH;
				IN3_LOW; 
				IN4_HIGH; 
				analogWrite(ENA,LOWSPEED-15);
				analogWrite(ENB,LOWSPEED+40);
				break;		
		case 3:
				IN1_LOW; 
				IN2_LOW;
				IN3_HIGH; 
				IN4_LOW; 
				analogWrite(ENA,0);
				analogWrite(ENB,LOWSPEED+50);
				break;		
		case 4:
				IN1_HIGH; 
				IN2_LOW;
				IN3_LOW; 
				IN4_LOW; 
				analogWrite(ENA,LOWSPEED);
				analogWrite(ENB,0);
				break;	
		case 5: 
				IN1_HIGH; 
				IN2_LOW;
				IN3_HIGH; 
				IN4_LOW; 
				analogWrite(ENA,LOWSPEED);
				analogWrite(ENB,HIGHSPEED);
				break;
		case 6:
				IN1_HIGH; 
				IN2_LOW;
				IN3_HIGH; 
				IN4_LOW; 
				analogWrite(ENA,HIGHSPEED);
				analogWrite(ENB,LOWSPEED);
				break;		
		case 7:
				IN1_LOW; 
				IN2_HIGH;
				IN3_LOW; 
				IN4_HIGH; 
				analogWrite(ENA,LOWSPEED);
				analogWrite(ENB,HIGHSPEED);
				break;		
		case 8:
				IN1_LOW; 
				IN2_HIGH;
				IN3_LOW; 
				IN4_HIGH; 
				analogWrite(ENA,HIGHSPEED);
				analogWrite(ENB,LOWSPEED);
				break;		
	
	}

}

Credits

Mike86

Mike86

15 projects • 12 followers

Comments