Sei sulla pagina 1di 18

You can use any RC car or you can build one.

If you haven't one, you only need to put the 2


geared motors, the caster wheels, one protoboard and the li-po battery in the acrylic
chassis. I use a bluetooth controlled car like base for HandBot.

2+98’\

First you need to verify to correct operation of the RF devices. This will be easy by a LED
indicator, the control will be managed by two keys "w" and "s" of your computer's keyboard.

Connect VCC to 5V pin.

GND to GND pin.

Data to pin 12 in both Arduinos.

LED to pin 13 in the receptor Arduino.

Transmitter module:

Receiver module:
LED off:

LED on:

You need to download VirtualWire library.


Code for TX:

#include<VirtualWire.h>
int key = 0;
char *controller;
void setup(){
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_set_tx_pin(12);
vw_setup(4000);
}
void loop(){
if(Serial.available() > 0){
key = Serial.read();
switch(key){
case 'w': controller = "1";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx();
break;
case 's': controller = "0";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx();
break;
}
}
}
Code for RX:
#include <VirtualWire.h>
void setup(){
vw_set_ptt_inverted(true);
vw_set_rx_pin(12);
vw_setup(4000);
pinMode(13,OUTPUT);
vw_rx_start();
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)){
if(buf[0]=='1'){
digitalWrite(13,HIGH);
delay(1000);
}
if(buf[0]=='0'){
digitalWrite(13,LOW);
delay(1000);
}
}
}
Now, you need to verify visually with LEDs the four outputs that should go to the H bridge,
reds colors indicate forward, greens colors indicate backward, one red and one green colors
indicate the turn left or right respectively. The control will be by the keyboard of your
computer "8" fordward, "2" backward, "6" turn right, "4" turn left, "5" stop.

Connect the red LEDs to pin 9 and 7, the green LEDs to pin 8 and 6.

Forward key "8":

Backward key "2":

Turn right key "6":


Turn left key "4":

Stop key "5":

Code for TX:


#include<VirtualWire.h>

int key = 0;

char *controller;

void setup(){

Serial.begin(9600);

vw_set_ptt_inverted(true);

vw_set_tx_pin(12);

vw_setup(4000);

void loop(){

if(Serial.available() > 0){

key = Serial.read();

switch(key){

case '8':controller = "8";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

break;

case '2': controller = "2";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

break;

case '6':controller = "6";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

break;

case '4':controller = "4";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

break;

case '5':controller = "5";

vw_send((uint8_t *)controller, strlen(controller));


vw_wait_tx();

break;

Code for RX:

#include <VirtualWire.h>

void setup(){

vw_set_ptt_inverted(true);

vw_set_rx_pin(12);

vw_setup(4000);

pinMode(9,OUTPUT);

pinMode(8,OUTPUT);

pinMode(7,OUTPUT);

pinMode(6,OUTPUT);

vw_rx_start();

void loop(){

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;

if(vw_get_message(buf, &buflen)){

if(buf[0]=='8'){

digitalWrite(9, HIGH);

digitalWrite(8, LOW);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

if(buf[0]=='2'){

digitalWrite(9, LOW);

digitalWrite(8, HIGH);

digitalWrite(7, LOW);
digitalWrite(6, HIGH);

if(buf[0]=='6'){

digitalWrite(9, HIGH);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

if(buf[0]=='4'){

digitalWrite(9, LOW);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

if(buf[0]=='5'){

digitalWrite(9, LOW);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

Once you have the correct programming of what will be the engine performance you need
review the functioning and values of the MPU-6050 accelerometer. The X and Y axes are as
the device is marked on the card.

VCC to 5V pin.

GND to GND pin.

SCL to A5 pin.

SDA to A4 pin.

Accelerometer sensor:
Values of the accelerometer and gyro:

Code for read values:

//SDA a A4, SCL a A5

#include<MPU6050.h>

#include<I2Cdev.h>

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

#include<Wire.h>

#endif

MPU6050 accelgyro;

int16_t ax, ay, az;


int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO

//#define OUTPUT_BINARY_ACCELGYRO

void setup(){

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

Wire.begin();

#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE

Fastwire::setup(400, true);

#endif

Serial.begin(38400); //38400 es la velocidad optima pero puede modificarse

accelgyro.initialize();

Serial.println(accelgyro.testConnection() ? "GY-521 conexion exitosa" : "GY-521 conexion


fallida");

void loop(){

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

#ifdef OUTPUT_READABLE_ACCELGYRO

Serial.print("Acel x, y, z: ");

Serial.print(ax);

Serial.print(", ");

Serial.print(ay);

Serial.print(", ");

Serial.println(az);

Serial.print("Gyro x, y, z: ");

Serial.print(gx);

Serial.print(", ");

Serial.print(gy);

Serial.print(", ");

Serial.println(gz);

Serial.println();

#endif
#ifdef OUTPUT_BINARY_ACCELGYRO

Serial.write((uint8_t)(ax >> 8));

Serial.write((uint8_t)(ax & 0xFF));

Serial.write((uint8_t)(ay >> 8));

Serial.write((uint8_t)(ax & 0xFF));

Serial.write((uint8_t)(az >> 8));

Serial.write((uint8_t)(ax & 0xFF));

Serial.write((uint8_t)(gx >> 8));

Serial.write((uint8_t)(ax & 0xFF));

Serial.write((uint8_t)(gy >> 8));

Serial.write((uint8_t)(ax & 0xFF));

Serial.write((uint8_t)(gz >> 8));

Serial.write((uint8_t)(ax & 0xFF));

#endif

delay(3000);

Once the correct reading of the accelerometer is verified, you will need to set values of
operation and you are going to insert this code in the visual engine performance code.
Operation will be visually checked by the LEDs before connecting to the the circuit.

Check the change of the outputs while turning the sensor:


Before you can connect the outputs of the arduino to the motors, you need a H bridge
L293D, this device can manage high voltage to power the motors (max 36V). Check its
datasheet before you connect it.

Complete transmitter circuit:

Complete receiver circuit:


Main TX code:

#include<VirtualWire.h>

#include<MPU6050.h>

#include<I2Cdev.h>

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

#include<Wire.h>

#endif

MPU6050 accelgyro;

int16_t ax, ay, az;

int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO

int key = 0;

char *controller;

void setup(){

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

Wire.begin();

#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE

Fastwire::setup(400, true);
#endif

Serial.begin(9600);

accelgyro.initialize();

vw_set_ptt_inverted(true);

vw_set_tx_pin(12);

vw_setup(4000);

void loop(){

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

#ifdef OUTPUT_READABLE_ACCELGYRO

if(ax <= -10000){

controller = "8";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

}else{

if(ax >= 10000){

controller = "2";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

}else{

if(ay >= 10000){

controller = "6";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

}else{

if(ay <= -10000){

controller = "4";

vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

}else{

controller = "5";
vw_send((uint8_t *)controller, strlen(controller));

vw_wait_tx();

#endif

Main RX Code:

#include <VirtualWire.h>

void setup(){

vw_set_ptt_inverted(true);

vw_set_rx_pin(12);

vw_setup(4000);

pinMode(9,OUTPUT);

pinMode(8,OUTPUT);

pinMode(7,OUTPUT);

pinMode(6,OUTPUT);

vw_rx_start();

void loop(){

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;

if(vw_get_message(buf, &buflen)){

if(buf[0]=='8'){

digitalWrite(9, HIGH);

digitalWrite(8, LOW);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

if(buf[0]=='2'){
digitalWrite(9, LOW);

digitalWrite(8, HIGH);

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

if(buf[0]=='6'){

digitalWrite(9, HIGH);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

if(buf[0]=='4'){

digitalWrite(9, LOW);

digitalWrite(8, HIGH);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

if(buf[0]=='5'){

digitalWrite(9, LOW);

digitalWrite(8, LOW);

digitalWrite(7, LOW);

digitalWrite(6, LOW);

Finally you put the controll circuit inside the fabric wristband and put it in the hand or arm of
the user.

Transmitter circuit:
Car:

Control band:
HandBot complete!

Potrebbero piacerti anche