9V DC motor doesnt work when i want to control it with my bluetooth modul

Hey everyone!
I wanted to control my dc motor through bluetooth today. For this i used L293D driver like in the picture that i attached. I made an easy code for this and it worked. It went to both directions and stopped, no problem.
After that, i attached my bluetooth modul to the board and controlled the motor with my phone. It worked for a while, I could control the speed of the motor and stop it. I wanted to do some more things so i plugged my usb out and write some more things in my code. I plugged my usb in and my dc motor didnt work anymore with my bluetooth. The bluetooth is okay(i wrote some messages to the serial port with it). If i dont use bluetooth, just write an easy code for the motor itself that is working too.
So my question is: Is it some supply problem? If you dont think so, what else could cause this problem? I have read that it is not recommended to have the same supply for dc motor and the rest of the arduino, but i found many webpages that use just one power supply( like the page where is the image from)

const int motorIn1 = 9;  
const int motorIn2 = 10;  

int mv;

void setup()

{
  Serial.begin(9600);
  pinMode(motorIn1,OUTPUT);  
  pinMode(motorIn2,OUTPUT); 

}


void loop()

{
if (Serial.available()>0)
  {
    char data = Serial.read();
    mv = (int)data;
    Serial.print(data);
    Serial.print("  ");
    Serial.print(mv);
    switch (mv) {
    case  49: Serial.println("aa");   analogWrite(motorIn1,170); analogWrite(motorIn2,0); 
    break;
    case  50: Serial.println("bb");  analogWrite(motorIn1,0); analogWrite(motorIn2,0); 
    break;
    case  51: ;Serial.println("cc"); analogWrite(motorIn1,220); analogWrite(motorIn2,0);
    break;
    case  52: ;Serial.println("dd"); analogWrite(motorIn1,10); analogWrite(motorIn2,0);
    break;
    }
  }
 

}

Here is my code too, but the problem is something else, since it worked for a while

The Arduino is not a power supply, and the 5V output cannot safely provide enough current to run motors or servos. Nor can a laptop.

Use a separate power supply for the motor/driver as electrical noise generated by the motor will often cause the Arduino to malfunction. Don't forget to connect the grounds.

i found many webpages that use just one power supply( like the page where is the image from)

Ignore those. They are all written by people who have no idea what they are doing, but managed to get something to work, at least once.

I tried to use a 9v battery as a power supply for the board and gave power to the arduino through usb, but it still doesnt work. The bluetooth led blinked so i could give power from the battery(and connect to the modul) but the motor didnt do anything. I uploaded the "easy code" for the motor and that works. So my problem is still the same.
Edit: I used only the usb as a power supply for the easy code, i should have tried that with the battery. By easy code i mean a code that makes the motor working at a certain speed then it stops and it starts again. I turned off my pc tomorrow i will try some other things but i dont really have an idea
Thanks for your answer tho

It looks like you are reading the bluetooth with a hardware serial connection which is fine if you disconnect the module when you dowload code to the board over usb.

Does you sketch work to control the motor correctly when you use the serial monitor to enter the commands instead of bluetooth?

A 9V block battery cannot supply enough power for a motor. They are for smoke alarms.

Use a 9 to 12V AA battery pack or power brick.

Okay so today the code without the bluetooth isnt working either. If i give direct power to the motor it works, so yeah i didnt ruin it yet. If my supplies are not enough, why did the following code work yesterday?

const int motorIn1= 9;  
const int motorIn2= 10; 

void setup()
{
  pinMode(motorIn1,OUTPUT);  //initialize the motorIn1 pin as output 
  pinMode(motorIn2,OUTPUT);  //initialize the motorIn2 pin as output 
}

void loop()
{
analogWrite(motorIn1,80); 
analogWrite(motorIn2,0); 
}

It shouldnt had worked yesterday either then.

Can i use the 9V battery for a dc motor that has less than 9V?
Or its not enoguh for any motor at all?

Can i use the 9V battery for a dc motor that has less than 9V?
Or its not enough for any motor at all?

The little 9v PP3 batteries are not good for any motor use. Don't use them. They won't even power a bare Arduino for very long.

If my supplies are not enough, why did the following code work yesterday?

Perhaps the bluetooth module draws extra current.
Perhaps the analogWrite duty cycle was low enough for the battery to handle.
Perhaps you were lucky.

@freasy

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.
Please take a few moments to Learn and Use The Forum

It will help you get the very best out of the forum in the future.

  • Your OS and version can be valuable information, please include it along with extra security you are using. Antivirus etc.

  • Always list the version of the IDE you are using and the board version if applicable.

  • Use quote or add error messages as an attachment NOT a picture.

  • How to insert an image into your post. ( Thanks @sterretje )

  • Add your sketch where applicable but please use CODE TAGS https://drive.google.com/file/d/1vF0OE4HozgyW_3oFENjem8DCrbrNoZ88/view?usp=share_link

  • Add a SCHEMATIC were needed even if it is hand drawn

  • Add working links to any specific hardware as needed (NOT links to similar items)

  • Remember that the people trying to help cannot see your problem so give as much information as you can

COMMON ISSUES

  • Ensure you have FULLY inserted the USB cables.

  • Check you have a COMMON GROUND where required. ( Thanks @Perry)

  • Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.

  • Try other computers where possible.

  • Try other USB leads where possible.

  • You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI

  • There may be a problem with the board check or remove your wiring first.

  • Remove any items connected to pins 0 and 1.

COMPUTER RELATED

  • Close any other serial programs before opening the IDE.

  • Ensure you turn off any additional security / antivirus just to test.

  • There may be a problem with the PC try RESTARTING it.

  • You may be selecting the wrong COM port.

  • Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.

  • Clear your browsers CACHE.

  • Close the IDE before using any other serial programs.

  • Preferably install IDE’s as ADMINISTRATOR or your OS equivalent

ARDUINO SPECIFIC BOARDS

  • CH340/341 based clones do not report useful information to the “get board info” button.

  • NANO (Old Types) some require you to use the OLD BOOTLOADER option.

  • NANO (ALL Types) See the specific sections lower in the forum.

  • NANO (NEW Types) Install your board CORE’s.

  • Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.

  • Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

CREATE editor install locations.

  • On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini

  • On Linux ~/ArduinoCreateAgent-1.1/config.ini

  • On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

Performing the above actions may help resolve your problem without further help.

Language problem ?

Try a language closer to your native language:

Thanks to all those who helped and added to this list.

I would have deleted it but i couldnt find any options to delete my topic

That is why you need to read those links !

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.