lasercut24mbobinger
Published © CC BY-NC

RC Wood Truck, Car (DIY): Arduino + ESP32 + MIT App Inventor

Build your own wooden monstertruck around Arduino IDE with Bluetooth control, loudspeaker and lights using an ESP32.

IntermediateFull instructions provided3,053
RC Wood Truck, Car (DIY): Arduino + ESP32 + MIT App Inventor

Things used in this project

Hardware components

ESP32
×1
Adafruit PAM8302
×1
Loudspeaker
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Stepper Motors
×4

Software apps and online services

MIT App Inventor
MIT App Inventor
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Circuit Schematic for RC Wood Truck

Circuit Schematic for RC Wood Truck
- ESP32 Wiring
- PAM8302 Wiring
- L298N micro board stepper motor card wiring
- Loudspeaker connection

Code

Arduino Code for Wood RC-Truck

Arduino
Arduino Code for Wood RC-Truck
//By Marco Bobinger - 2020
//
/*Pin assignment:
 * GPIO16: Mute PM8302 sound card on SD (Shutdown PIN)
 * GPIO25: DAC (digital-to-analog-converter) on A+ pin on PM8302
 * VCC of PM8302 on 3.3V
 * L298N Micro stepper card: right wheels on MOTOR A output of L298N
 * L298N Micro stepper card: LEFT wheels on MOTOR B output of L298N
 * Right Motor: see GPIO below
 * Left motor: see GPIO below
 */
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
/*
F: Forward : 70
B: Back : 66
S: Stop : 83
L: Left : 76
R: Right : 82
I: Forward right : 73
J: Back right : 74
H: back left : 72
G: forward left : 71
u: u-turn : 117
t: u-turn : 116
M: Sound1 77
N: Sound2 78
O: Sound3 79
K: Light off 75
Z: light on 90
 */
#include "BluetoothSerial.h"
#include "hupen.h"
#include "XT_DAC_Audio.h"
int mutepin = 16;
XT_Wav_Class hupenclass(hupen);                                  
XT_DAC_Audio_Class DacAudio(25,0);


#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

byte incoming;
int counter = 0;
int lightpin = 15;

//left motor
int rmotorpinA = 33; //change to 32
int rmotorpinB = 32;

//right motor
int lmotorpinA = 14; //change to 14
int lmotorpinB = 27;

BluetoothSerial SerialBT;

void stop() {
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, LOW);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, LOW); 
}
void setup() {
  Serial.begin(115200);
  SerialBT.begin("Lasercut24 - 2912"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
//pin settings for digitalwrite GPIO Pins
pinMode(rmotorpinA, OUTPUT);
pinMode(rmotorpinB, OUTPUT);
pinMode(lmotorpinA, OUTPUT);
pinMode(lmotorpinB, OUTPUT);
pinMode(mutepin, OUTPUT);
pinMode(lightpin, OUTPUT);
digitalWrite(mutepin, LOW);
}

void loop() {
  /*
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  */
  if (SerialBT.available()) {
    incoming = SerialBT.read();
    Serial.println(incoming);
    counter = 0;
  }
      if (incoming == 70)
  {
  Serial.println("Driving forward");
  SerialBT.println("Forward");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, HIGH);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, HIGH);
  }

  if (incoming == 66)
  {
  Serial.println("Driving back");
  SerialBT.println("Back");
  digitalWrite(rmotorpinA, HIGH);
  digitalWrite(rmotorpinB, LOW);
  digitalWrite(lmotorpinA, HIGH);
  digitalWrite(lmotorpinB, LOW);
  }

  if (incoming == 83)
  {
  Serial.println("Stopping now");
  SerialBT.println("Stopping");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, LOW);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, LOW);
  }
  delay(20);

  if (incoming == 76)
  {
  Serial.println("Driving left");
  SerialBT.println("Left");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, HIGH);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, LOW);
  }
  
if (incoming == 82)
  {
  Serial.println("Driving right");
  SerialBT.println("Right");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, LOW);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, HIGH);
  }

  if (incoming == 73)
  {
  Serial.println("Forward right");
  SerialBT.println("F-Right");
  if (counter >= 1)
  {
  counter = 0;
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, LOW);
  delay(100);
  }
  else if (counter < 1)
  {
  counter = counter + 1;
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, HIGH);
  }
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, HIGH);
  }

  if (incoming == 74)
  {
  Serial.println("Back right");
  SerialBT.println("B-Right");
  if (counter >= 1)
  {
  counter = 0;
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, LOW);
  delay(100);
  }
  else if (counter < 1)
  {
  counter = counter + 1;
  digitalWrite(rmotorpinA, HIGH);
  digitalWrite(rmotorpinB, LOW);
  }
  digitalWrite(lmotorpinA, HIGH);
  digitalWrite(lmotorpinB, LOW);
  }

  if (incoming == 72)
  {
  Serial.println("Back left");
  SerialBT.println("B-Left");
  digitalWrite(rmotorpinA, HIGH);
  digitalWrite(rmotorpinB, LOW);
  if (counter >= 1)
  {
  counter = 0;
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, LOW);
  delay(100);
  }
  else if (counter < 1)
  {
    counter = counter + 1;
  digitalWrite(lmotorpinA, HIGH);
  digitalWrite(lmotorpinB, LOW);
  }
  }

  if (incoming == 71)
  {
  Serial.println("Forward left");
  SerialBT.println("F-Left");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, HIGH);
  if (counter >= 1)
  {
  counter = 0;
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, LOW);
  delay(100);
  }
  else if (counter < 1)
  {
  counter = counter + 1;
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, HIGH); 
  }
  }
  
  if (incoming == 117) // u turn with letter u
  {
  SerialBT.println("U-turn");
  Serial.println("U-turn");
  digitalWrite(rmotorpinA, LOW);
  digitalWrite(rmotorpinB, HIGH);
  digitalWrite(lmotorpinA, HIGH);
  digitalWrite(lmotorpinB, LOW);
  }

  if (incoming == 116) // u turn with letter t
  {
  SerialBT.println("U-turn");
  Serial.println("U-turn");
  digitalWrite(rmotorpinA, HIGH);
  digitalWrite(rmotorpinB, LOW);
  digitalWrite(lmotorpinA, LOW);
  digitalWrite(lmotorpinB, HIGH); 
  }
  
  if (incoming == 77) // Play sound 1
  {
digitalWrite(mutepin, HIGH);
Serial.println("Now Playing Sound 1");
SerialBT.println("Sound 1");
DacAudio.FillBuffer();
if(hupenclass.Playing==false){
DacAudio.Play(&hupenclass);
incoming = 0;
digitalWrite(mutepin, LOW);  
  }
  }
  
  if (incoming == 89)
  {
  SerialBT.println("Muting");
  Serial.println("Muting");
  digitalWrite(mutepin, LOW);   
  }

  if (incoming == 90)
  {
  SerialBT.println("Light on");
  Serial.println("Light on");
  digitalWrite(lightpin, HIGH);   
  }
  if (incoming == 75)
  {
  SerialBT.println("Light off");
  Serial.println("Light off");
  digitalWrite(lightpin, LOW);   
  }
}

Credits

lasercut24

lasercut24

1 project • 0 followers
mbobinger

mbobinger

1 project • 1 follower

Comments