Hey guys
I want to make a gesture robotic car using
Accelerator adxl 345 (hand)
2 Bluetooth one slave (car) and the other is master (hand)
4 DC motors with motor driver
2 Arduino uno
I can't find a code that is working
Can you help me out
Code of the hand
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <SoftwareSerial.h>
#define ADXL345_ADDR (0x53)
SoftwareSerial bluetooth(2, 3); // RX, TX
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
if(!accel.begin()) {
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
float x = event.acceleration.x;
float y = event.acceleration.y;
float z = event.acceleration.z;
Serial.print("X: "); Serial.print(x); Serial.print(" ");
Serial.print("Y: "); Serial.print(y); Serial.print(" ");
Serial.print("Z: "); Serial.println(z);
bluetooth.print(x);
bluetooth.print(",");
bluetooth.print(y);
bluetooth.print(",");
bluetooth.println(z);
delay(500);
}
`````````````````````````````````````
Code of the car
#include <SoftwareSerial.h>
#include <AFMotor.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
#define ENA 11
#define IN1 10
#define IN2 9
#define ENB 6
#define IN3 7
#define IN4 8
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
if(bluetooth.available() > 0){
String data = bluetooth.readStringUntil('\n');
int commaIndex1 = data.indexOf(',');
int commaIndex2 = data.indexOf(',', commaIndex1 + 1);
if(commaIndex1 != -1 && commaIndex2 != -1){
float x = data.substring(0, commaIndex1).toFloat();
float y = data.substring(commaIndex1 + 1, commaIndex2).toFloat();
float z = data.substring(commaIndex2 + 1).toFloat();
// Do something with the received data (e.g., control motors)
// For demonstration purposes, just printing received values
Serial.print("X: "); Serial.print(x); Serial.print(" ");
Serial.print("Y: "); Serial.print(y); Serial.print(" ");
Serial.print("Z: "); Serial.println(z);
}
}
}