Hello, Recently I have been trying to make a 4 door mechanism which consists of 4 servo motors that are operated by potentiometer using arduino.
but Now I want to make it wireless using my HC 05 master/slave bluetooth pair. I wanted to keep the connection binded and secured to only one master module so i didn't used phone bluetooth for it but i dont know how to control servos using two HC 05 bluetooth modules between two arduino by potentiometer. Can anyone help me with it.
is it just like the normal code ?
Can anyone help me out
I'm not sure I'm understanding your question, but, I do know that connecting a phone to 2 BT devices is possible, but tricky
Why do you want to use 2 arduinos ?
Is this for 2 separate locations ?
Your transmitter code appears to suffer from the same issues as a recent post to which I have replied to... as for your receiver code, there is nothing wrong with it, but I'd like to suggest an alternative if it doesn't hinder your design goals:
For example, from this:
char val = Serial.read(); if(val == 'A') { digitalWrite(led, HIGH); } else if(val == 'a') { digitalWrite(led, LOW); }
To this:
String ledState = Serial.readStringUntil('\n'); if(ledState.equals("on")) { digitalWrite(led, HIGH); } else if(ledState.equals("off")) { digitalWrite(led, LOW); }
The reason I am providing this alternative, is because to often, code can become very unreadable, not only to oneself, but to others who try to interpret it. I think it's much better to state the intent of the code, rather than taking shortcuts with single letter acronyms for variables, etc... programming languages are written to accommodate readable code, and that means you can in the end, include less comments too.
Given that this example is to turn an led on or off, doesn't it make sense to actually write the program code to reflect the intent of the actions desired?
It does not take anymore time to write the example I provided over your original. If this code was to be used in MQTT for a light switch, wouldn't it be better to read "on" or "off" vs "A" or "a"?
I know which on I would choose every time... just some food for thought 🙂
As for your Bluetooth question, you haven't provided any code for that at all, so like the big @spyder, I'm a little confused too. I have never worked with Bluetooth, so not sure I can really help with that, but unless I see some code and any associated error messages I won't know for sure, nor will anyone else.
Have you tried any of the library examples to start with, and if so, what were the errors?
Cheers.
if I understand correctly you have managed to transmit and receive a value such as 'A' or 'a' between your arduino's but cannot see your way to using a potentiometer on one arduino to control a motor on an other arduino.
A potentiometer should be connected to an AD pin and can be made to read values from 0 to 1023 (assuming you use one of the Arduinos AD pins) as you increase the voltage through the potentiometer. You can output this number to the serial monitor as well as using to control your servo motor. (no doubt you have seen the excellent dronebot video on this). Likewise you can transmit this number just as you did when you sent the 'A' or 'a' values. Then at the receiving arduino end you take this number and use it to control the attached motor.
As you have not submitted any code in relation to this, its not clear a what point along this chain you might be stuck at.
is it just like the normal code
yes, nothing special, and what with your transmit and receive code and the code in the dronebot article you are almost there. 😀
@frogandtoad Thank you again, i am gonna try changing it again tomorrow.
Sorry for the late reply actually i was quarantined so all i could do is read your reply but couldn't reply back to you.
No problem... you have no idea what kind of totalitarian dictatorship I'm going through here in Aus!
Go Trump!
Anyway, back to the fun stuff!
Here is my problem the led is blinking as it should be but in my setup but i have a joystick
module at the transmitter end which controls the servo motor of the receiver end and it is not
working, the servo motor are not even responding to it and i can't understand why. Cause i thought potentiometer and joystick module were
suppose to be same thing
Ok, assuming they are connected via serial, I think I can see your problem.
Serial.write(...) has overloaded versions of it so it can send a single byte, or a string etc... you are using the byte overload of write() to send an integer of 2 bytes, and on the receiving end, read() is also looking to read one character at a time.
The easiest way to solve this problem, is to write a string or array of bytes from the transmitter end, and then read it back using on the receiver end using Serial.parseInt(), or if you have a need to stuff it in a string for some reason, Serial.readLine() or Serial.readLineUntil('\n').
Cheers.
i thought potentiometer and joystick module were
suppose to be same thing
My joystick has 2 potentiometers for the x and y axis and additionally has an addition switch connection. (so 3 signal wires). The joystick potentiometer will be centralised so the values can go up or down and the analogue signals are usually mapped something like
mapX = map(xPosition, 0, 1023, -512, 512); mapY = map(yPosition, 0, 1023, -512, 512);
So your 'potentiometer' mapping looks wrong to me if using a joystick. Have you checked you are on the right track by getting the joystick/motor working with just one Arduino to check out the correct wiring etc.?