I need help with my Arduino project for school

Hello thanks for reading this😁, I'm currently making a robot for school that should move his servo motors and must play saved wav files from the SD card, when a letter (for example h) gets sent trough Bluetooth (with HC-05) to the Arduino. My only issue is that for some reason I can't use the HC-05 and the SD Card Memory Modul at the same time. I can use the HC-05 while SD Card Memory Modul is unplugged and the letters arrive at the Arduino and the servo motors will move without any issue. And I also can send letters trough a USB cable connected to my pc, while the HC-05 is unplugged, and those letters arrive to the Arduino, the SD card will play the wav file and will move its servo motors without any problems. But every time I use both at the same time (HC-05 and SD Card Memory Modul, that's my goal) it seems like the letter gets sent to the HC-05 but will never arrive at the Arduino itself. I think the problem could be that the SPI of the HC-05 and the SPI of the SD Card Memory Modul are interrupting each other somehow, but I almost don't know anything about SPI lol😅. I used Chat-GPT and watched tutorials online but nothing worked for me, I don't know how to fix this issue . I hope someone in this Discord server can help me with my issue . I would really appreciate it. The Arduino code is attached down here (it might be a bit messy)⬇ Thanks for helping.😁
No description
49 Replies
AnonEngineering
AnonEngineering5mo ago
right away this is an issue:
c++
SoftwareSerial BT(5, 6); // RX, TX

// define sonar sensor's pins
int trig = 5;
int echo = 6;
c++
SoftwareSerial BT(5, 6); // RX, TX

// define sonar sensor's pins
int trig = 5;
int echo = 6;
you can't use pins 5 & 6 for multiple things
noobhoch12
noobhoch12OP5mo ago
these r not in use right now so its not important I used before that pin 0 and 1 (rx and tx) on arduino uno for the bluetooth module and there is the same issue ofc
AnonEngineering
AnonEngineering5mo ago
not sure I understand, but you shouldn't use pins 0 & 1 on an Uno for BT
noobhoch12
noobhoch12OP5mo ago
okey
AnonEngineering
AnonEngineering5mo ago
0 & 1 are used by hardware serial
noobhoch12
noobhoch12OP5mo ago
I removed trig end echo and bt is on 5 and 6 and I still cant use them both at the same time could the power supply be to low? I'm using a powerbank to power the arduino with 5V output and 3,1A. @AnonEngineering so do you got any idea how to make it work?
AnonEngineering
AnonEngineering5mo ago
without the code and wiring you are using? no
noobhoch12
noobhoch12OP5mo ago
The script is that 😁: https://discord.com/channels/420594746990526466/1370715689928622140/1370715719687213087 And I'm providing my wiring as soon as I'm back at home.
noobhoch12
noobhoch12OP5mo ago
OR YOU CAN JUST USE THIS
AnonEngineering
AnonEngineering5mo ago
the barrel jack requires 7v - 12v in, if that is connected to a 5v power bank that is a problem, it looks like you are trying to power several servos from the Uno 5v pin, you can't do that.
noobhoch12
noobhoch12OP5mo ago
@AnonEngineering , Thanks that was the problem. I gave the barrel jack 9V and it works. Last issue is that I'm only able to run the .wav file from letter h and the function hi will never start, and the other letters only work if you don't run h before running them (so theyre functions r working). So the issue must me the SD card. If you can help me with this last issue I should not have any issues anymore. The script is this attached file. Thanks for helping😊
AnonEngineering
AnonEngineering5mo ago
what calls the hi function?
noobhoch12
noobhoch12OP5mo ago
that hi function never starts because somehow the wav file stops everything else you can send h again in serial the sound gets player but function hi never starts. The same thing with the other if loops
No description
AnonEngineering
AnonEngineering5mo ago
after cool.play("abcd.wav"); runs then it'll go to the hi function is it playing abcd.wav?
noobhoch12
noobhoch12OP5mo ago
Yes But the hi function never starts because my servo doesnt move at all
AnonEngineering
AnonEngineering5mo ago
put a print in the hi function, maybe it runs but the servo has a problem
noobhoch12
noobhoch12OP5mo ago
Yep you are god damn right again its appearing in the hi function and in every other function too.... it should be the servos. Does that mean the Arduino needs more voltage or something else. Thanks for helping. You are helping me so much.
AnonEngineering
AnonEngineering5mo ago
you cannot power servos from the Arduino 5v pin (that pin can deliver at most 0.5 amps, your servos can easily draw 1 amp each)
noobhoch12
noobhoch12OP5mo ago
from where do I have to power them? From 3,3V?
AnonEngineering
AnonEngineering5mo ago
that's even worse 😉 use a 4xAA battery pack for servo power (look up "Arduino external power")
noobhoch12
noobhoch12OP5mo ago
so something like that?
No description
noobhoch12
noobhoch12OP5mo ago
or just a basic 4xAA battery slot
No description
AnonEngineering
AnonEngineering5mo ago
the breadboard PSU only does 500mA too, use the battery pack (it'll do a few amps peak) the positive lead goes to servo + leads (only), the ground gets tied to Arduino ground that way servos draw power from battery, arduino only supplies a low current control signal
noobhoch12
noobhoch12OP3mo ago
Hey, Thanks for responding. I'll try that as soon as I can. I'll let you know then (sadly I can test that in a week or so). Does the ground really just get tied to the arduino? And the arduino ground to the servos?
AnonEngineering
AnonEngineering3mo ago
all things in the project get tied to a common reference point (ground)
noobhoch12
noobhoch12OP3mo ago
Yeah but the servos dont need the battery ground? Just the arduino's?
AnonEngineering
AnonEngineering3mo ago
yes they do, servo ground = arduino ground
noobhoch12
noobhoch12OP3mo ago
So the ground from the battery is only connected to the arduino to complete the curcuit? So it has no other practical use
AnonEngineering
AnonEngineering3mo ago
you connect the battery pack ground to both the arduino ground and the servo grounds battery + goes only to the servo + leads
noobhoch12
noobhoch12OP3mo ago
To both, that was the missing information thx But maybe we need help later on...
AnonEngineering
AnonEngineering3mo ago
that way the battery supplies the high current to power the servos, the arduino only supplies low current control to the servos
noobhoch12
noobhoch12OP3mo ago
Through the normal pins like 11, 12...
AnonEngineering
AnonEngineering3mo ago
through whatever GPIO pins you chose
noobhoch12
noobhoch12OP3mo ago
Ok thx
AnonEngineering
AnonEngineering3mo ago
here the battery is shown as "Vcc" and "GND"
No description
noobhoch12
noobhoch12OP3mo ago
Yeah than i got it right Thank u very much again
noobhoch12
noobhoch12OP3mo ago
Hey @AnonEngineering, We have connected the batteries like u told us to ,and the servo motors are moving at the beginning. But unfortunately our SD Card Module is no longer working (and we migh have other issues aswell). I haven't added all the parts, we have on our circuit on the cuircuit designer, because we still have some unused wires and parts on our circuit board. I will send our circuit and our updated script in here. I hope you can find some errors we're unable to find. We're almost out of time for the project ,so we really appreciate your help. Thanks https://app.cirkitdesigner.com/project/02e643e5-e284-43d1-9caa-d76e4469e8d0
Cirkit Designer IDE
Cirkit Designer IDE is an all-in-one circuit design tool that helps you create and share electronic circuits with ease.
noobhoch12
noobhoch12OP3mo ago
No description
AnonEngineering
AnonEngineering3mo ago
You can't feed the servos 9v for one thing And I'm on my phone, can't really check code
noobhoch12
noobhoch12OP3mo ago
Thanks for the information. We’re facing another issue and its more frustrating. Its the SD card module. We suspect it may have been damaged during development, as we’re unable to run even a basic test script—neither on an Arduino nor on a Funduino. We consistently receive the error part of the script in the Serial Monitor, even though the SD card is currently empty and formatted in FAT32. Here’s the test code:
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
Serial.begin(9600);
while (!Serial);

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("Failed. SD module might be defective?");
return;
}
Serial.println("SD card successfully detected!");
}

void loop() {
}
#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
Serial.begin(9600);
while (!Serial);

Serial.print("Initializing SD card...");

if (!SD.begin(chipSelect)) {
Serial.println("Failed. SD module might be defective?");
return;
}
Serial.println("SD card successfully detected!");
}

void loop() {
}
No description
pseud0
pseud03mo ago
If the wiring is exactly as depicted it's correct. Try a different SD card.
AnonEngineering
AnonEngineering3mo ago
as Max said, it should be working. your code runs fine in the Wokwi simulator
noobhoch12
noobhoch12OP3mo ago
Hi thanks for responding @max and @AnonEngineering . Yes the SD Card Module was the problem it somehow broke and with the new one I have no longer that issue. But now to the more important part: I think I know what the issue is with the servo motors. As I said they work before I run the
lautsprecher.play
lautsprecher.play
command (so before I run the speaker). But after that I've realised it never stops trying to play something (it keeps making a small noice the speaker). So it seems like it's not a voltage problem. More like a SPI or a code problem. But I don't know alot about that stuff. I hope that helps you guys to understand my problem. Thanks:a_heart:
pseud0
pseud03mo ago
https://github.com/TMRh20/TMRpcm/blob/v1.3.6/pcmConfig.h#L37-L39 TMRpcm library by default takes control of both pin 9 and 10 and a hardware timer, so it does affect those pins plus PWM output on possibly other pins you need to chose the pins and configuration very carefully
noobhoch12
noobhoch12OP3mo ago
Oh okay I got it I checked that all out and I've found a solution. We use for the servos timer 2 instead of timer 1 (I've found a libary that does that). Well unfortunately we only have one timer 2 pin that is usable (because we already use pin 11) would ya guys recommend using an Arduino Mega, instead of the Uno even though we had issues with it. Or is there any other solution?
noobhoch12
noobhoch12OP3mo ago
@AnonEngineering @max Hey thanks for helping with all those issues. We are now on the last step on adding all the arduino stuff into the body of the robot. We haven't reduced the 9V from the batteries that are only get feeded to the three servos, because we had no issue for now. And we were somehow able to power 2 servos, even though we only had only one usable timer 2 pin, that is currently not in use. Thans for helping
No description
AnonEngineering
AnonEngineering3mo ago
expect the lifespan of the servos to be reduced at 9v however, if you measure the voltage I bet it's closer to 7v, 9v batteries can't supply much current so the load will drag down the voltage.
noobhoch12
noobhoch12OP2mo ago
Hey, I forgot to mention. Our robot works perfectly now. Thanks for helping😁

Did you find this page helpful?