Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Transmitter module:
Receiver module:
LED off:
LED on:
#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.
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(){
key = Serial.read();
switch(key){
vw_wait_tx();
break;
vw_wait_tx();
break;
vw_wait_tx();
break;
vw_wait_tx();
break;
break;
#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];
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.
SCL to A5 pin.
SDA to A4 pin.
Accelerometer sensor:
Values of the accelerometer and gyro:
#include<MPU6050.h>
#include<I2Cdev.h>
#include<Wire.h>
#endif
MPU6050 accelgyro;
#define OUTPUT_READABLE_ACCELGYRO
//#define OUTPUT_BINARY_ACCELGYRO
void setup(){
Wire.begin();
Fastwire::setup(400, true);
#endif
accelgyro.initialize();
void loop(){
#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
#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.
#include<VirtualWire.h>
#include<MPU6050.h>
#include<I2Cdev.h>
#include<Wire.h>
#endif
MPU6050 accelgyro;
#define OUTPUT_READABLE_ACCELGYRO
int key = 0;
char *controller;
void setup(){
Wire.begin();
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(){
#ifdef OUTPUT_READABLE_ACCELGYRO
controller = "8";
vw_wait_tx();
}else{
controller = "2";
vw_wait_tx();
}else{
controller = "6";
vw_wait_tx();
}else{
controller = "4";
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];
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!