Problemas Montando Fotos an Error Occurred in the Upload. Please Try Again Later.
In this tutorial I'll show you how to command 2 DC motors via bluetooth with an Android app created with MIT App Inventor 2. MIT App Inventor is a nifty platform to become you lot started with Android development.
In a previous tutorial (click here to see that project), I was controlling i DC motor using an app called "BlueTerm". That app did the chore, simply it's not ideal to send constantly different commands in an easy manner.
The app that y'all're going to build is perfect to control whatever Arduino pin or to integrate with your own robot automobile. You tin edit this app for your specific needs.
Bluetooth module HC-05
To establish the bluetooth communication between your smartphone and your Arduino, you need a bluetooth module. This projection uses the HC-05 bluetooth module (as shown in the effigy below).
This bluetooth module works with serial information. This means that the Arduino sends information and the bluetooth module receives it via serial (and vice-versa).
By default the HC-05 bluetooth module operates at a baud rate of 9600.
Creating your Android app
The Android App will be created using a gratis web awarding chosen MIT App Inventor. MIT App Inventor is a slap-up place to become started with Android evolution, because it allows you lot to build simple apps with drag-n-drop.
Yous demand a Google business relationship to sign upwardly for MIT App Inventor and here'southward the login page: http://ai2.appinventor.mit.edu.
Click here to download the .aia file, then watch the video below:
If yous go to the Projects tab, you tin can upload the .aia file for this projection
With MIT App Inventor you have two main sections: designer and blocks. The designer is what gives you the ability to add buttons, add text, add screens and edit the overall app look.
The blocks sections is what allows to create custom functionality for your app, so when you press the buttons it actually does something with that data.
I recommend that you start past following this project and using the app without modifying it.
If want to make whatsoever changes to the app, when you're done and y'all want to install the app in your smartphone, go to the Build tab.
- You can either generate a QR code that you can scan with your smartphone and automatically install the app in your smartphone.
- Or you can download the .apk file, connect your smartphone to your calculator and move the .apk file to the phone.
Just follow the installation magician to install the app and it'southward done!
Lawmaking
For this project, you don't need to install any Arduino libraries. So, you just have to download or copy the following lawmaking to your Arduino IDE, and upload it to your Arduino board. Make certain that you take the right Board and COM port selected.
/* * created by Rui Santos, https://randomnerdtutorials.com * Control ii DC motors with Smartphone via bluetooth */ int motor1Pin1 = 3; // pin 2 on L293D IC int motor1Pin2 = 4; // pin seven on L293D IC int enable1Pin = 6; // pin 1 on L293D IC int motor2Pin1 = 8; // pivot x on L293D IC int motor2Pin2 = 9; // pivot 15 on L293D IC int enable2Pin = 11; // pivot 9 on L293D IC int country; int flag=0; //makes sure that the serial only prints in one case the state int stateStop=0; void setup() { // sets the pins as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(enable1Pin, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enable2Pin, OUTPUT); // sets enable1Pin and enable2Pin high so that motor can plough on: digitalWrite(enable1Pin, High); digitalWrite(enable2Pin, HIGH); // initialize serial communication at 9600 bits per second: Serial.brainstorm(9600); } void loop() { //if some date is sent, reads it and saves in land if(Series.available() > 0){ state = Series.read(); flag=0; } // if the state is 'F' the DC motor volition become frontward if (state == 'F') { digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, Low); digitalWrite(motor2Pin1, Low); digitalWrite(motor2Pin2, HIGH); if(flag == 0){ Series.println("Go Forrard!"); flag=1; } } // if the state is 'R' the motor will turn left else if (state == 'R') { digitalWrite(motor1Pin1, Loftier); digitalWrite(motor1Pin2, Low); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); if(flag == 0){ Serial.println("Plough LEFT"); flag=one; } filibuster(1500); country=3; stateStop=1; } // if the state is 'Due south' the motor will Stop else if (land == 'S' || stateStop == one) { digitalWrite(motor1Pin1, Depression); digitalWrite(motor1Pin2, Depression); digitalWrite(motor2Pin1, Low); digitalWrite(motor2Pin2, LOW); if(flag == 0){ Serial.println("STOP!"); flag=one; } stateStop=0; } // if the state is '50' the motor volition turn correct else if (state == 'L') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, Low); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, High); if(flag == 0){ Serial.println("Plough RIGHT"); flag=1; } delay(1500); state=3; stateStop=1; } // if the state is 'B' the motor volition Reverse else if (country == 'B') { digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, High); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); if(flag == 0){ Serial.println("Reverse!"); flag=1; } } //For debugging purpose //Serial.println(state); }
View raw lawmaking
Note: before uploading the code, make sure you accept the TX and RX pins disconnected from the bluetooth module!
Parts Required
- Arduino UNO – read Best Arduino Starter Kits
- Bluetooth module HC-04 or HC-05 or HC-06
- 1x L293D IC
- 2x DC motors
- Breadboard
- Jumper wires
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Schematics
Follow the schematic diagram in the post-obit figure to wire your circuit.
Launching your app
If yous haven't generated the .apk file in a previous step, yous tin canclick hither to download the .apk file (which is the Android app installation file). Move that file to your smartphone and open it. Follow the installation wizard to install the app.
Turn on your smartphone'due south Bluetooth.
Tap on the newly installed app. Printing the "Connect" push to connect your application to your Arduino Bluetooth module.
Now you tin can easily control the 2 DC motors with your app:
Sentry this video demonstration
Troubleshooting:
- Remove the RX and TX cables when you're uploading a new sketch to your Arduino lath
- People frequently connect the TX from the bluetooth module to the TX of the Arduino, that won't piece of work. Make sure you connect: TX goes to RX and RX goes to TX.
- If the HC-04/HC-06&HC-05 bluetooth module asks for a countersign, it'due south '1234′.
Wrapping up
I hope you found this useful.
Do you know a friend that would like to come across this project? Brand sure y'all share this project with your friend!
Do y'all want to learn more about building apps for Arduino? Go admission to our course: Android Apps for Arduino with MIT App Inventor two.
Thanks for reading,
Rui
P.S. If y'all don't have a bluetooth module, read my HC-05 review hither.
Source: https://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/
Enregistrer un commentaire for "Problemas Montando Fotos an Error Occurred in the Upload. Please Try Again Later."