Accelerometer Car

12K4833

Intro: Accelerometer Car

This is my 'FIRST' post so am sorry if i missed something or made a mistake, please bear with me.

This is kind of a side project my friend and I made based on Arduino micro-controller and MSP-430 micro-controller. And I would like to share the steps we took to come up with this accelerometer car.

Hope you like it =)

STEP 1: The Remote

For this you will need:

1. RF Tx and Rx
2. Accelerometer Module
3. Arduino uno
4. Jumper cables 
5. Ardunio usb cable

I'm using an Encoder board along with the RF Tx i.e the HT-12E board.

Connect the Accelerometer Module Pin
X------Analog Pin ------ A1
Y------Analog Pin ------ A2
All Gnds and Vcc should be short separately.


We wont be needing the z-axis as am trying to use the module to replicate the actions of a real driving style.
So if ,
I bend the board Forward the car moves Forward.
I tilt it Left/ Right the car moves Left/Right.
I bend the board Backwards the car Stops.

So on those lines we have to first get the readings of the module for various triggering points so that we can move the car accordingly when a trigger point has been hit.

First run just the module on the Arduino and note the readings of the various tilt positions.
(acc test code in the download file)

Make sure u place all the components on some sorta board so that your actions can be interpreted easily.

For me i got the trigger values for,
Forward----- x= xxx   y>= 400 
Stop---------- x= xxx   y<= 300
Left----------- x<= 300  y= xxx
Right--------- x>= 380  y= xxx

'xxx' means dont' care because those values doesn't trigger in the directions we are looking for.


Once you got all these info,
Go on and connect the Accelerometer Module and the RF Tx to the Arduino to the pins given below

Accelerometer Modlue 
x--------- A1
y--------- A2

RF tx board
b0------- 7
b1------- 6
b2------- 5
b3------- 4

All Gnds and Vcc should be short separately.

Place all the components on the same board.
You plug in the Arduino to the computer and dump the code on the Arduino.
(Acc-Rf-Tx  code in the download file)

There you go, now you have the Remote READY.

NEXT STEP!!!!!

STEP 2: The Car

For this u will need:

1. RF Tx and Rx
2. H-Bridge 
3. MSP-430
4. Jumper cables
5. 4 AA Battery holder x 1
6. AA Battery x 4
7. MSP-430 usb cable
8. Car along with DC motors and wheels

I'm using a Decoder board along with the RF Rx i.e the HT-12D board.
I'm using Energia IDE for the MSP-430.

First assemble the car with the wheels and dc motors i.e if you don't already have a car lying around.

Then you will have to do the following connections.

RF Rx

b0 -------- 7
b1 -------- 8
b2 -------- 13
b3 -------- 14

H-Bridge

The two wires of each dc motor is given to the output of each input on the board 
and the input of the board is given to

taking A is for the right motor
inp A1 ------ 10
inp A2 ------ 9

taking B is for the left motor
inp B1 ------ 11
inp B2 ------ 12

The battery in connected to the h-bridge.
The enable pins of motor A and B are short to any Vcc pin.

P.S
The Gnd pins of all the boards involved are shorted separately and the Vcc pins of all the boards involved are shorted separately. 

Once you are done with the setup, connect the MSP-430 to the computer and dump the code on to it.
(Acc-RF-Rx code in the download file)

Make sure all the components are properly connected and attached on to the chassis of the car and nothing is falling off.

You now have the car ready.

NOW TEST IT!!!! 

STEP 3: Thank You

Thank You for your patience and time for going through this instuctable.
Hope you liked it.

If you have any doubts or questions, mail them to me at,

pineapple.exprs@gmail.com


Here's the video of the working model =)

Ohh!!! I Almost forgot, here are the code files.

Acc-test

Acc-Rf-Rx

Acc-Rf-Tx

If your car starts going in a different direction other than the prompted direction, then alter the codes and check the motor pins.

35 Comments

hello, robobot3112 thanx for ur help but the code u have written is
wrong u mixed up two codes

dont mind but u copied the code from controlling robot using rfs

THANK YOU !! :)

ASWAMY, msp430 is not convenient to me, so i wanna use something another such as arduino. woulb be thier any changes in their source code

can u give me ur mail id robobot3112

?

transmitter code is working fine but the reciever code is wrong as remote is transmitting 1,2,3,4,5 etc and reciever is recieving data from serial monitor

like f,b,r,l,s

robobot3112 thanx for ur help but the code u have written is wrong u mixed up two codes

dont mind but u copied the code from controlling robot using rfs

got my problem abhay reply to it asap

tx code


// TRANSMITTER CODE

//NOTE :- THIS TRANSMITTER CODE IS USED WHEN YOU WANT TO CONTROL THE ROBOT VIA THE BREADBOARD REMOTE
#include <VirtualWire.h>

//Assigning controller buttons to Digital Pins
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)



void setup()
{
Serial.begin(9600); // Debugging only
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_set_tx_pin(3); //Transmitter Data Pin to Digital Pin 3


for(int i = 0; i<6 ; i++)
{


}

}//close setup

void loop()
{
int xs= analogRead (xpin);
int ys = analogRead (ypin);

char *msg2;

if(ys >= 400); //if the forward values are received
{
char *msg2 = "1"; //send 1 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2)); //send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}

if(ys <= 300)//if the back button is pressed
{
char *msg2 = "5"; ///send 5 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2)); //send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}

if(xs >= 380);
{
char *msg2 = "3"; //send 3 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2)); //send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}

if(xs >= 300);//if the right button is pressed
{
char *msg2 = "4"; //send 4 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the message to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}


}//close loop

// End Of Code

rx code


#include <VirtualWire.h>

//declaring pin Nos of FIRST L293D
int en1 = 5;
int en2 = 6;
int in1 = 7;
int in2 = 8;
int in3 = 9;
int in4 = 10;
//declaring pin nos of SECOND L293D
int en1o2 = 3;
int en2o2 = 11;
int in1o2 = 4;
int in2o2 = 12;
int in3o2 = 14;
int in4o2 = 15;
int motorPin[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15};//array for storing pin nos

void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_set_rx_pin(2);//Receiver at Digital Pin 2
vw_rx_start();// Start the receiver PLL running


for (int i = 0; i < 12; i++)
{
pinMode(motorPin[i], OUTPUT);
}//close for loop


}//close setup

void loop()
{



uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;

digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.

for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]);
if(buf[i] == 'f')
{
forward();//go forward when f is pressed
}
if(buf[i] == 's')
{
stopMotor();//stop/brake when s is pressed
}
if(buf[i] == 'l')
{
left();//go left when l is presed
}
if(buf[i] == 'r')
{
right();//go right when r is pressed
}

}//close for loop

digitalWrite(13, false);

}//close main if
}//close loop
//you can print the data entered when debugging by adding Serial.println

////////////////////////////////////////////////////////////////////////////////////////

//set of functions
void forward()
{
digitalWrite(en1,HIGH);
digitalWrite(en2,HIGH);
digitalWrite(en1o2,HIGH);
digitalWrite(en2o2,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in1o2,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in2o2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in3o2,LOW);
digitalWrite(in4,HIGH);
digitalWrite(in4o2,HIGH);
}



void left()
{
digitalWrite(en1,HIGH);
digitalWrite(en2,HIGH);
digitalWrite(en1o2,HIGH);
digitalWrite(en2o2,HIGH);
digitalWrite(in1,LOW);
digitalWrite(in1o2,LOW);
digitalWrite(in2,LOW);
digitalWrite(in2o2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in3o2,LOW);
digitalWrite(in4,HIGH);
digitalWrite(in4o2,HIGH);

}

void right()
{
digitalWrite(en1,HIGH);
digitalWrite(en2,HIGH);
digitalWrite(en1o2,HIGH);
digitalWrite(en2o2,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in1o2,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in2o2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in3o2,LOW);
digitalWrite(in4,LOW);
digitalWrite(in4o2,LOW);

}

void stopMotor()
{
digitalWrite(en1,HIGH);
digitalWrite(en2,HIGH);
digitalWrite(en1o2,HIGH);
digitalWrite(en2o2,HIGH);
digitalWrite(in1,LOW);
digitalWrite(in1o2,LOW);
digitalWrite(in2,LOW);
digitalWrite(in2o2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in3o2,LOW);
digitalWrite(in4,LOW);
digitalWrite(in4o2,LOW);
}
//End Of Code

abhay listen my arduinos are working fine but i am using only rf modules not the rf boards so please give me an code for that:) :)

hey can you tell me wat exactly is the role of msp4 in this project?

listen my communication is not occuring what should i do.

can you please elaborate on ur problem ?

can u suggest me another microcontroller i can use...i don't want to use msp430...what should i use if i don't want to use it....

hey, you can use an aduino uno it self.

listen my communication is not occuring what should i do.

can u suggest me another microcontroller i can use...i don't want to use msp430...what should i use if i don't want to use it....

can u suggest me another microcontroller i can use...i don't want to use msp430...what should i use if i don't want to use it....

can u suggest me another microcontroller i can use...i don't want to use msp430...what should i use if i don't want to use it....

When i uploaded the program and switched on the car it started rotating automatically
More Comments