Components and supplies
ESP32
PAM8302
Stepper Motors
Loudspeaker
Jumper wires (generic)
Tools and machines
Soldering iron (generic)
Solder Wire, Lead Free
Apps and platforms
Arduino IDE
MIT App Inventor
Project description
Code
Arduino Code for Wood RC-Truck
arduino
Arduino Code for Wood RC-Truck
1//By Marco Bobinger - 2020 2// 3/*Pin assignment: 4 * GPIO16: Mute PM8302 sound card on SD (Shutdown PIN) 5 * GPIO25: DAC (digital-to-analog-converter) on A+ pin on PM8302 6 * VCC of PM8302 on 3.3V 7 * L298N Micro stepper card: right wheels on MOTOR A output of L298N 8 * L298N Micro stepper card: LEFT wheels on MOTOR B output of L298N 9 * Right Motor: see GPIO below 10 * Left motor: see GPIO below 11 */ 12//This example creates a bridge between Serial and Classical Bluetooth (SPP) 13//and also demonstrate that SerialBT have the same functionalities of a normal Serial 14/* 15F: Forward : 70 16B: Back : 66 17S: Stop : 83 18L: Left : 76 19R: Right : 82 20I: Forward right : 73 21J: Back right : 74 22H: back left : 72 23G: forward left : 71 24u: u-turn : 117 25t: u-turn : 116 26M: Sound1 77 27N: Sound2 78 28O: Sound3 79 29K: Light off 75 30Z: light on 90 31 */ 32#include "BluetoothSerial.h" 33#include "hupen.h" 34#include "XT_DAC_Audio.h" 35int mutepin = 16; 36XT_Wav_Class hupenclass(hupen); 37XT_DAC_Audio_Class DacAudio(25,0); 38 39 40#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) 41#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it 42#endif 43 44byte incoming; 45int counter = 0; 46int lightpin = 15; 47 48//left motor 49int rmotorpinA = 33; //change to 32 50int rmotorpinB = 32; 51 52//right motor 53int lmotorpinA = 14; //change to 14 54int lmotorpinB = 27; 55 56BluetoothSerial SerialBT; 57 58void stop() { 59 digitalWrite(rmotorpinA, LOW); 60 digitalWrite(rmotorpinB, LOW); 61 digitalWrite(lmotorpinA, LOW); 62 digitalWrite(lmotorpinB, LOW); 63} 64void setup() { 65 Serial.begin(115200); 66 SerialBT.begin("Lasercut24 - 2912"); //Bluetooth device name 67 Serial.println("The device started, now you can pair it with bluetooth!"); 68//pin settings for digitalwrite GPIO Pins 69pinMode(rmotorpinA, OUTPUT); 70pinMode(rmotorpinB, OUTPUT); 71pinMode(lmotorpinA, OUTPUT); 72pinMode(lmotorpinB, OUTPUT); 73pinMode(mutepin, OUTPUT); 74pinMode(lightpin, OUTPUT); 75digitalWrite(mutepin, LOW); 76} 77 78void loop() { 79 /* 80 if (Serial.available()) { 81 SerialBT.write(Serial.read()); 82 } 83 if (SerialBT.available()) { 84 Serial.write(SerialBT.read()); 85 } 86 */ 87 if (SerialBT.available()) { 88 incoming = SerialBT.read(); 89 Serial.println(incoming); 90 counter = 0; 91 } 92 if (incoming == 70) 93 { 94 Serial.println("Driving forward"); 95 SerialBT.println("Forward"); 96 digitalWrite(rmotorpinA, LOW); 97 digitalWrite(rmotorpinB, HIGH); 98 digitalWrite(lmotorpinA, LOW); 99 digitalWrite(lmotorpinB, HIGH); 100 } 101 102 if (incoming == 66) 103 { 104 Serial.println("Driving back"); 105 SerialBT.println("Back"); 106 digitalWrite(rmotorpinA, HIGH); 107 digitalWrite(rmotorpinB, LOW); 108 digitalWrite(lmotorpinA, HIGH); 109 digitalWrite(lmotorpinB, LOW); 110 } 111 112 if (incoming == 83) 113 { 114 Serial.println("Stopping now"); 115 SerialBT.println("Stopping"); 116 digitalWrite(rmotorpinA, LOW); 117 digitalWrite(rmotorpinB, LOW); 118 digitalWrite(lmotorpinA, LOW); 119 digitalWrite(lmotorpinB, LOW); 120 } 121 delay(20); 122 123 if (incoming == 76) 124 { 125 Serial.println("Driving left"); 126 SerialBT.println("Left"); 127 digitalWrite(rmotorpinA, LOW); 128 digitalWrite(rmotorpinB, HIGH); 129 digitalWrite(lmotorpinA, LOW); 130 digitalWrite(lmotorpinB, LOW); 131 } 132 133if (incoming == 82) 134 { 135 Serial.println("Driving right"); 136 SerialBT.println("Right"); 137 digitalWrite(rmotorpinA, LOW); 138 digitalWrite(rmotorpinB, LOW); 139 digitalWrite(lmotorpinA, LOW); 140 digitalWrite(lmotorpinB, HIGH); 141 } 142 143 if (incoming == 73) 144 { 145 Serial.println("Forward right"); 146 SerialBT.println("F-Right"); 147 if (counter >= 1) 148 { 149 counter = 0; 150 digitalWrite(rmotorpinA, LOW); 151 digitalWrite(rmotorpinB, LOW); 152 delay(100); 153 } 154 else if (counter < 1) 155 { 156 counter = counter + 1; 157 digitalWrite(rmotorpinA, LOW); 158 digitalWrite(rmotorpinB, HIGH); 159 } 160 digitalWrite(lmotorpinA, LOW); 161 digitalWrite(lmotorpinB, HIGH); 162 } 163 164 if (incoming == 74) 165 { 166 Serial.println("Back right"); 167 SerialBT.println("B-Right"); 168 if (counter >= 1) 169 { 170 counter = 0; 171 digitalWrite(rmotorpinA, LOW); 172 digitalWrite(rmotorpinB, LOW); 173 delay(100); 174 } 175 else if (counter < 1) 176 { 177 counter = counter + 1; 178 digitalWrite(rmotorpinA, HIGH); 179 digitalWrite(rmotorpinB, LOW); 180 } 181 digitalWrite(lmotorpinA, HIGH); 182 digitalWrite(lmotorpinB, LOW); 183 } 184 185 if (incoming == 72) 186 { 187 Serial.println("Back left"); 188 SerialBT.println("B-Left"); 189 digitalWrite(rmotorpinA, HIGH); 190 digitalWrite(rmotorpinB, LOW); 191 if (counter >= 1) 192 { 193 counter = 0; 194 digitalWrite(lmotorpinA, LOW); 195 digitalWrite(lmotorpinB, LOW); 196 delay(100); 197 } 198 else if (counter < 1) 199 { 200 counter = counter + 1; 201 digitalWrite(lmotorpinA, HIGH); 202 digitalWrite(lmotorpinB, LOW); 203 } 204 } 205 206 if (incoming == 71) 207 { 208 Serial.println("Forward left"); 209 SerialBT.println("F-Left"); 210 digitalWrite(rmotorpinA, LOW); 211 digitalWrite(rmotorpinB, HIGH); 212 if (counter >= 1) 213 { 214 counter = 0; 215 digitalWrite(lmotorpinA, LOW); 216 digitalWrite(lmotorpinB, LOW); 217 delay(100); 218 } 219 else if (counter < 1) 220 { 221 counter = counter + 1; 222 digitalWrite(lmotorpinA, LOW); 223 digitalWrite(lmotorpinB, HIGH); 224 } 225 } 226 227 if (incoming == 117) // u turn with letter u 228 { 229 SerialBT.println("U-turn"); 230 Serial.println("U-turn"); 231 digitalWrite(rmotorpinA, LOW); 232 digitalWrite(rmotorpinB, HIGH); 233 digitalWrite(lmotorpinA, HIGH); 234 digitalWrite(lmotorpinB, LOW); 235 } 236 237 if (incoming == 116) // u turn with letter t 238 { 239 SerialBT.println("U-turn"); 240 Serial.println("U-turn"); 241 digitalWrite(rmotorpinA, HIGH); 242 digitalWrite(rmotorpinB, LOW); 243 digitalWrite(lmotorpinA, LOW); 244 digitalWrite(lmotorpinB, HIGH); 245 } 246 247 if (incoming == 77) // Play sound 1 248 { 249digitalWrite(mutepin, HIGH); 250Serial.println("Now Playing Sound 1"); 251SerialBT.println("Sound 1"); 252DacAudio.FillBuffer(); 253if(hupenclass.Playing==false){ 254DacAudio.Play(&hupenclass); 255incoming = 0; 256digitalWrite(mutepin, LOW); 257 } 258 } 259 260 if (incoming == 89) 261 { 262 SerialBT.println("Muting"); 263 Serial.println("Muting"); 264 digitalWrite(mutepin, LOW); 265 } 266 267 if (incoming == 90) 268 { 269 SerialBT.println("Light on"); 270 Serial.println("Light on"); 271 digitalWrite(lightpin, HIGH); 272 } 273 if (incoming == 75) 274 { 275 SerialBT.println("Light off"); 276 Serial.println("Light off"); 277 digitalWrite(lightpin, LOW); 278 } 279}
Arduino Code for Wood RC-Truck
arduino
Arduino Code for Wood RC-Truck
1//By Marco Bobinger - 2020 2// 3/*Pin assignment: 4 * GPIO16: Mute PM8302 sound card on SD (Shutdown PIN) 5 * GPIO25: DAC (digital-to-analog-converter) on A+ pin on PM8302 6 * VCC of PM8302 on 3.3V 7 * L298N Micro stepper card: right wheels on MOTOR A output of L298N 8 * L298N Micro stepper card: LEFT wheels on MOTOR B output of L298N 9 * Right Motor: see GPIO below 10 * Left motor: see GPIO below 11 */ 12//This example creates a bridge between Serial and Classical Bluetooth (SPP) 13//and also demonstrate that SerialBT have the same functionalities of a normal Serial 14/* 15F: Forward : 70 16B: Back : 66 17S: Stop : 83 18L: Left : 76 19R: Right : 82 20I: Forward right : 73 21J: Back right : 74 22H: back left : 72 23G: forward left : 71 24u: u-turn : 117 25t: u-turn : 116 26M: Sound1 77 27N: Sound2 78 28O: Sound3 79 29K: Light off 75 30Z: light on 90 31 */ 32#include "BluetoothSerial.h" 33#include "hupen.h" 34#include "XT_DAC_Audio.h" 35int mutepin = 16; 36XT_Wav_Class hupenclass(hupen); 37XT_DAC_Audio_Class DacAudio(25,0); 38 39 40#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) 41#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it 42#endif 43 44byte incoming; 45int counter = 0; 46int lightpin = 15; 47 48//left motor 49int rmotorpinA = 33; //change to 32 50int rmotorpinB = 32; 51 52//right motor 53int lmotorpinA = 14; //change to 14 54int lmotorpinB = 27; 55 56BluetoothSerial SerialBT; 57 58void stop() { 59 digitalWrite(rmotorpinA, LOW); 60 digitalWrite(rmotorpinB, LOW); 61 digitalWrite(lmotorpinA, LOW); 62 digitalWrite(lmotorpinB, LOW); 63} 64void setup() { 65 Serial.begin(115200); 66 SerialBT.begin("Lasercut24 - 2912"); //Bluetooth device name 67 Serial.println("The device started, now you can pair it with bluetooth!"); 68//pin settings for digitalwrite GPIO Pins 69pinMode(rmotorpinA, OUTPUT); 70pinMode(rmotorpinB, OUTPUT); 71pinMode(lmotorpinA, OUTPUT); 72pinMode(lmotorpinB, OUTPUT); 73pinMode(mutepin, OUTPUT); 74pinMode(lightpin, OUTPUT); 75digitalWrite(mutepin, LOW); 76} 77 78void loop() { 79 /* 80 if (Serial.available()) { 81 SerialBT.write(Serial.read()); 82 } 83 if (SerialBT.available()) { 84 Serial.write(SerialBT.read()); 85 } 86 */ 87 if (SerialBT.available()) { 88 incoming = SerialBT.read(); 89 Serial.println(incoming); 90 counter = 0; 91 } 92 if (incoming == 70) 93 { 94 Serial.println("Driving forward"); 95 SerialBT.println("Forward"); 96 digitalWrite(rmotorpinA, LOW); 97 digitalWrite(rmotorpinB, HIGH); 98 digitalWrite(lmotorpinA, LOW); 99 digitalWrite(lmotorpinB, HIGH); 100 } 101 102 if (incoming == 66) 103 { 104 Serial.println("Driving back"); 105 SerialBT.println("Back"); 106 digitalWrite(rmotorpinA, HIGH); 107 digitalWrite(rmotorpinB, LOW); 108 digitalWrite(lmotorpinA, HIGH); 109 digitalWrite(lmotorpinB, LOW); 110 } 111 112 if (incoming == 83) 113 { 114 Serial.println("Stopping now"); 115 SerialBT.println("Stopping"); 116 digitalWrite(rmotorpinA, LOW); 117 digitalWrite(rmotorpinB, LOW); 118 digitalWrite(lmotorpinA, LOW); 119 digitalWrite(lmotorpinB, LOW); 120 } 121 delay(20); 122 123 if (incoming == 76) 124 { 125 Serial.println("Driving left"); 126 SerialBT.println("Left"); 127 digitalWrite(rmotorpinA, LOW); 128 digitalWrite(rmotorpinB, HIGH); 129 digitalWrite(lmotorpinA, LOW); 130 digitalWrite(lmotorpinB, LOW); 131 } 132 133if (incoming == 82) 134 { 135 Serial.println("Driving right"); 136 SerialBT.println("Right"); 137 digitalWrite(rmotorpinA, LOW); 138 digitalWrite(rmotorpinB, LOW); 139 digitalWrite(lmotorpinA, LOW); 140 digitalWrite(lmotorpinB, HIGH); 141 } 142 143 if (incoming == 73) 144 { 145 Serial.println("Forward right"); 146 SerialBT.println("F-Right"); 147 if (counter >= 1) 148 { 149 counter = 0; 150 digitalWrite(rmotorpinA, LOW); 151 digitalWrite(rmotorpinB, LOW); 152 delay(100); 153 } 154 else if (counter < 1) 155 { 156 counter = counter + 1; 157 digitalWrite(rmotorpinA, LOW); 158 digitalWrite(rmotorpinB, HIGH); 159 } 160 digitalWrite(lmotorpinA, LOW); 161 digitalWrite(lmotorpinB, HIGH); 162 } 163 164 if (incoming == 74) 165 { 166 Serial.println("Back right"); 167 SerialBT.println("B-Right"); 168 if (counter >= 1) 169 { 170 counter = 0; 171 digitalWrite(rmotorpinA, LOW); 172 digitalWrite(rmotorpinB, LOW); 173 delay(100); 174 } 175 else if (counter < 1) 176 { 177 counter = counter + 1; 178 digitalWrite(rmotorpinA, HIGH); 179 digitalWrite(rmotorpinB, LOW); 180 } 181 digitalWrite(lmotorpinA, HIGH); 182 digitalWrite(lmotorpinB, LOW); 183 } 184 185 if (incoming == 72) 186 { 187 Serial.println("Back left"); 188 SerialBT.println("B-Left"); 189 digitalWrite(rmotorpinA, HIGH); 190 digitalWrite(rmotorpinB, LOW); 191 if (counter >= 1) 192 { 193 counter = 0; 194 digitalWrite(lmotorpinA, LOW); 195 digitalWrite(lmotorpinB, LOW); 196 delay(100); 197 } 198 else if (counter < 1) 199 { 200 counter = counter + 1; 201 digitalWrite(lmotorpinA, HIGH); 202 digitalWrite(lmotorpinB, LOW); 203 } 204 } 205 206 if (incoming == 71) 207 { 208 Serial.println("Forward left"); 209 SerialBT.println("F-Left"); 210 digitalWrite(rmotorpinA, LOW); 211 digitalWrite(rmotorpinB, HIGH); 212 if (counter >= 1) 213 { 214 counter = 0; 215 digitalWrite(lmotorpinA, LOW); 216 digitalWrite(lmotorpinB, LOW); 217 delay(100); 218 } 219 else if (counter < 1) 220 { 221 counter = counter + 1; 222 digitalWrite(lmotorpinA, LOW); 223 digitalWrite(lmotorpinB, HIGH); 224 } 225 } 226 227 if (incoming == 117) // u turn with letter u 228 { 229 SerialBT.println("U-turn"); 230 Serial.println("U-turn"); 231 digitalWrite(rmotorpinA, LOW); 232 digitalWrite(rmotorpinB, HIGH); 233 digitalWrite(lmotorpinA, HIGH); 234 digitalWrite(lmotorpinB, LOW); 235 } 236 237 if (incoming == 116) // u turn with letter t 238 { 239 SerialBT.println("U-turn"); 240 Serial.println("U-turn"); 241 digitalWrite(rmotorpinA, HIGH); 242 digitalWrite(rmotorpinB, LOW); 243 digitalWrite(lmotorpinA, LOW); 244 digitalWrite(lmotorpinB, HIGH); 245 } 246 247 if (incoming == 77) // Play sound 1 248 { 249digitalWrite(mutepin, HIGH); 250Serial.println("Now Playing Sound 1"); 251SerialBT.println("Sound 1"); 252DacAudio.FillBuffer(); 253if(hupenclass.Playing==false){ 254DacAudio.Play(&hupenclass); 255incoming = 0; 256digitalWrite(mutepin, LOW); 257 } 258 } 259 260 if (incoming == 89) 261 { 262 SerialBT.println("Muting"); 263 Serial.println("Muting"); 264 digitalWrite(mutepin, LOW); 265 } 266 267 if (incoming == 90) 268 { 269 SerialBT.println("Light on"); 270 Serial.println("Light on"); 271 digitalWrite(lightpin, HIGH); 272 } 273 if (incoming == 75) 274 { 275 SerialBT.println("Light off"); 276 Serial.println("Light off"); 277 digitalWrite(lightpin, LOW); 278 } 279}
Downloadable files
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
Circuit Schematic for RC Wood Truck
Comments
Only logged in users can leave comments
lasercut24
0 Followers
•0 Projects
Table of contents
Intro
1
0