Arduino - linear speed / servo control with potentiometers - Page 1
Forum section: electronics / general

author: Matthew98
author_rank: Regular Contributor
timestamp: April 21, 2017, 03:01:33 pm
content: Hello.How can i change PWM lineally with potentiometer ? Im using PWM for servo and motor speed on my RC formula I made.There are two potentiometers in remote control (x and y axis) which values i want to transfer via 2.4Ghz transmitter to the RC car and change lineally speed of motor and position of servo (with dead zones at middle and max values )I have no idea how to do it, though... any help ?

author: CatalinaWOW
author_rank: Super Contributor
timestamp: April 21, 2017, 03:10:43 pm
content: Servo control with pots is easy on Arduino. I think examples are posted. You just hook the pots across the power supply, feed the wiper to an analogue input (the 10 bit A-D), scale down to 8 bits and feed the PWM software.Going through the air at 2.4 GHz makes it slightly more difficult. And somewhat pointless. You need a receiver with the right frequency hop etc to receive the transmitted signal. You could then convert the PWM of the appropriate receiver channel to a DC with an RC filter and feed the analog input. But since the receiver already drives servos there is little to be gained by going through the Arduino. You can set dead zones and the like, but going through the Arduino will add latency. Something most are trying to avoid.

author: Matthew98
author_rank: Regular Contributor
timestamp: April 21, 2017, 06:14:09 pm
content: Well i know how to do all the other stuff...im just asking on how to change the pwm according to the potentiometers ... because the numbers wont fit my needs and i probably cant figure out the algorythm to make the numbers I need from them. Im I suppose to make a map ? I really dont know how to do only this part...

author: CatalinaWOW
author_rank: Super Contributor
timestamp: April 21, 2017, 07:03:42 pm
content: Are you using the SERVO package? Which wants a number from 0 to 180 as an input. The units are degrees, with 0 representing 90 degrees left rotation, 90 represents the center position and 180 representing 90 degrees right rotation. So the problem is to scale the output of the A/D which has a value range of 0 to 1023 to this range. If you are using floating point math it is simply a matter of multiplying by a scale factor. Floating point uses a lot of time/resources on the Arduino so using a slightly more complex, but acceptable result can be achieved by converting the A/D reading to a long variable type, then multiplying by 180 and dividing by 1023.If you are using the microseconds input of servo the math is slightly more complex, but the ideas are very similar.

author: rstofer
author_rank: Super Contributor
timestamp: April 24, 2017, 03:48:23 pm
content: You may find that dividing by 1024 is close enough.Take your reading (0..1023) and multiply by 180 and shift right 10 places rather than dividing by 1023. That will give you an output range of 0..179.8 and you could always round up by adding 512 before dividing by 1024 because, ultimately, you need an integer <= 180.Yes, you will have to do 32 bit arithmetic, probably 'unsigned long'.

author: Ian.M
author_rank: Super Contributor
timestamp: April 24, 2017, 04:53:03 pm
content: Electro-Tech-Online.com: Why ADC/1024 is correct, and ADC/1023 is just plain wrong!

author: CatalinaWOW
author_rank: Super Contributor
timestamp: April 24, 2017, 05:17:56 pm
content: I agree. Fingers engaged before brain.It really only matters for computation if doing the divide by shifting. I defy you to find a servo application where one part in 1024 makes a real difference. To engineering precision the numbers are identical.

author: retrolefty
author_rank: Super Contributor
timestamp: April 24, 2017, 05:56:49 pm
content: Quote from: Matthew98 on April 21, 2017, 06:14:09 pmThe Arduino IDE does provide a map function.fragment minus includes and setup.Code:{int val = analogRead(0);int angle = map(val, 0, 1023, 0, 180); // 0-1023 is analog input pot range. 0-180 is servo position// range.servo.write(angle);}

author: rrinker
author_rank: Super Contributor
timestamp: April 24, 2017, 06:18:52 pm
content: Keep in mind not all the servos, especially the cheap ones, don' actually go all the way from 0 to 180 degrees. When commanded to 0 (or 180) they go most of the way and then buzz, drawing a ton of current and heating up the motor. So you may want o check and find out what the usable range of your servos actually is and use that in the conversion or in the MAP function.

author: Matthew98
author_rank: Regular Contributor
timestamp: April 24, 2017, 07:17:02 pm
content: Thank you all guys for responses and sorry for myself not responding. Im in the middle of very important exams and its hard to slip arduino inWill take a look at it this weekend. Thanks !