DIY bluetooth controlled car - Page 1
Forum section: electronics / general

author: Adhith
author_rank: Frequent Contributor
timestamp: August 04, 2019, 07:32:35 pm
content: Hello there,I'm a newbie in Arduino and coding sort of things. I was doing an automobile related hobby project and building a Bluetooth controlled car was part of the project. I found some resources online and I'm sharing the schemamtic and the arduino codes of it. The movements are controlled through a mobile app.However this was only a part of my project and the real intention is to turn on and off a separate motor(apart from the 4 geared motors used in the project) through the same mobile app. So my question is, could I change the code to form a new ON and OFF signal from one of the outputs of the motor driver to run the seperate motor ?? Also the controls from the app should be any combination keys or something. So is it possible?Any help would be highly appreciated. Thank you in advance.codechar t;void setup() {pinMode(13,OUTPUT); //left motors forwardpinMode(12,OUTPUT); //left motors reversepinMode(11,OUTPUT); //right motors forwardpinMode(10,OUTPUT); //right motors reversepinMode(9,OUTPUT); //LedSerial.begin(9600);}void loop() {if(Serial.available()){t = Serial.read();Serial.println(t);}if(t == 'F'){ //move forward(all motors rotate in forward direction)digitalWrite(13,HIGH);digitalWrite(11,HIGH);}else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)digitalWrite(12,HIGH);digitalWrite(10,HIGH);}else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)digitalWrite(11,HIGH);}else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)digitalWrite(13,HIGH);}else if(t == 'W'){ //turn led on or off)digitalWrite(9,HIGH);}else if(t == 'w'){digitalWrite(9,LOW);}else if(t == 'S'){ //STOP (all motors stop)digitalWrite(13,LOW);digitalWrite(12,LOW);digitalWrite(11,LOW);digitalWrite(10,LOW);}delay(100);}

author: admiralk
author_rank: Regular Contributor
timestamp: August 05, 2019, 01:36:04 am
content: I am not sure I understand what you are asking or how your interface works, but I can make a couple suggestions on your code.First, using a switch statement makes the code easier to read instead of all the if elses, imo.Code:switch(Serial.read()){case 'F':digitalWrite(13, HIGH);digitalWrite(11, HIGH);break;//...}As you have it, you would need to hit stop between every action. If you are moving forward and then try to turn right or left, without stopping first, what do you think will happen? I am not sure what would happen if you tried reversing, but it probably would not be good.Adding more motors, or anything else, should not be a problem as long as you have free pins to connect to. Key combinations would be a little trickier as they could not be reprecented by a single char. Arduino does have readString() and readByteArray() functions, they might be called something a little different(?), but how well they work depends on what the app sends. I ran into this problem were the micro was expecting a '/n' that was never sent. It was easy enough to fix by changing the delimiter, but something to be aware of especially if you are not writing the code for the app also.

author: ledtester
author_rank: Super Contributor
timestamp: August 05, 2019, 01:40:02 am
content: To independently control a motor you need an H-bridge dedicated to that motor.That board you are using has two H-bridges. This video should help explain how it works:Whether it is a good idea to place motors in parallel like they are doing is another question.So if you want to add another motor and be able to control it independently of the others you'll need another L289N board and allocate another two or three digital IO pins to control it.QuoteI have no idea how to interpret this. How about explaining it in terms of a usage scenario: "if the user does X, then one thing happens; if the user does Y then Z happens; if user does W then ..."This video which came out last week might be of interest:

author: Adhith
author_rank: Frequent Contributor
timestamp: August 05, 2019, 07:57:27 pm
content: Quote from: admiralk on August 05, 2019, 01:36:04 amThank you very much for your detailed answer. I think I was not that good in explaining my need through my previous question. Also I have made some alteration to my project. So I'll try to explain things in a better way.I'm driving 4 geared motor through the motor driver for my project. The movement is controlled through an mobile app connected to the Bluetooth module on the car. Apart from this, I also need a relay switch from the Arduino via the same app. I'm planing to use a transistor or mechanical relay for this.This relay is used to drive a separate geared motor which serves a different function. I'm directly driving this motor with the relay and without any driver.It should be capable of rotating the motor in clockwise and anti clockwise directions. Since All the keys of the app are already coded for the movement of the car, I was wondering If by the using a pair of combination keys, could I drive the separate motor in clockwise and anticlockwise directions.

author: Adhith
author_rank: Frequent Contributor
timestamp: August 05, 2019, 08:00:34 pm
content: Quote from: ledtester on August 05, 2019, 01:40:02 amThank you very much for you help and link to the video. I had a quick look and the video and got some basic idea. I'll fully watch it within a day. I have updated my question in the quote above. Could you please have a look.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 05, 2019, 08:26:33 pm
content: Just to be reassured: you're talking about a model car here, not a real car?

author: admiralk
author_rank: Regular Contributor
timestamp: August 05, 2019, 11:54:56 pm
content: That second video should give you just about all you need to get a good jump on things.

author: Psi
author_rank: Super Contributor
timestamp: August 06, 2019, 12:04:19 am
content: Quote from: SiliconWizard on August 05, 2019, 08:26:33 pmMaybe he's been hired to work on Tesla summon mode.

author: ledtester
author_rank: Super Contributor
timestamp: August 06, 2019, 12:43:44 am
content: QuoteYou need an H-bridge to do that.QuoteFrom your code it appears that the phone app sends signals which are transmitted to the Arduino via the serial interface. If the code in your original post works, then this is what I expect happends:If you press the forward button, then the character 'F' is transmitted to the Arduino.If you press the turn right button then the character 'R' is transmitted to the Arduino.If you press the forward and turn right buttons "at the same time" the Arduino will either see the character 'F' followed by the character 'R' or it might see the character 'R' followed by the character 'F' depending on how the phone app works. In any case, you'd get the same result if the user hit the forward button and then hit the turn right button a millisecond later. In other words, I doubt the Arduino can tell if a bunch of keys were pressed at the same time versus pressed within a very small timespan of each other.You can record the time between key presses, so you could do something special if, say, the user hit the forward button three times real fast. If you receive three 'F' characters within, say, a 10th of a second you could interpret that as some other command.But I would just use the RC Car control app for Android phones that I linked to -- it has extra buttons you can bind your own custom commands to.

author: Adhith
author_rank: Frequent Contributor
timestamp: August 08, 2019, 06:50:56 pm
content: Quote from: SiliconWizard on August 05, 2019, 08:26:33 pmHaayeah a model car. but it is capable of re configuring the shape of the wheels. i.e from normal tire to a caterpillar track.

author: Adhith
author_rank: Frequent Contributor
timestamp: August 08, 2019, 06:52:18 pm
content: Quote from: admiralk on August 05, 2019, 11:54:56 pmYeah, I saw it. I got a lot idea about. I think I could use the additional buttons on it to individually allocate a different function for the project.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 08, 2019, 06:58:54 pm
content: Quote from: Adhith on August 08, 2019, 06:50:56 pmIt's a transformer?

author: Adhith
author_rank: Frequent Contributor
timestamp: August 08, 2019, 07:01:50 pm
content: Quote from: ledtester on August 06, 2019, 12:43:44 amYeah. by reading your reply I got a better understanding about it. Thank you for that. So for a clockwise and anticlockwise rotation I definitely need another H bridge module right ? could I create a sort of H bridge with one or two mechanical relay ? The reason is, I have a lot of relays with me so that I could cut down the cost of project without buying an additional driver.Since the app contain two individual switch for turning the front and back light of the car, I was hoping that I could code it for clockwise and anti clock wise rotation by two seperated relay connected to the Arduino. could I do that?

author: Adhith
author_rank: Frequent Contributor
timestamp: August 08, 2019, 07:03:56 pm
content: Quote from: SiliconWizard on August 08, 2019, 06:58:54 pmNo, just though to do a hobby project around this concept of reconfigurable wheel.

author: ledtester
author_rank: Super Contributor
timestamp: August 08, 2019, 08:19:47 pm
content: QuoteHave a look at this:https://www.instructables.com/id/Two-Relay-DC-Motor-Control-Simple-H-bridge/

author: Adhith
author_rank: Frequent Contributor
timestamp: August 09, 2019, 07:39:34 pm
content: Quote from: ledtester on August 08, 2019, 08:19:47 pmThank you. I got a clear picture now. I'll work on it and let you guys know about the progress.