One solution came in mind for RC car steering.
Control servo (planned or RC car steering) with potentiometer.
Testing setup is very simple.
Servo setup: +, – and control pin. Same as here:
Simple servo setup
Potentiometer will work as voltage divider.
Here is more info about it: Voltage divider.
Connection to arduino would be also pretty much simple:
Potentiometer is like this whole divider system.
So when potentiometer is with big enough resistivity (I think mine is 10Kohms) – One end goes to 5v, other to ground, and the one in the middle, goes to analog read.
In this setup voltage output goes from 0V (when top resistor is 0ohms) to 5V (when bottom resistor is 0ohms).
Code:
// steering.ino
#include
Servo myServo;
int servoPin = 12;
int wheelPin = 0;
int degree = 0;
void setup() {
myServo.attach(servoPin);
}
void loop() {
degree = map(analogRead(wheelPin), 0, 1023, 45, 135);
myServo.write(degree);
delay(50);
}
Should be pretty much clear, as most part of code was reviewed in post about servo here.
New thing here – map command.
Map command takes variable, and maps new value.
So in my case 0-1023 (values that analog input may read) translate in to values between 45 and 135 (we don’t need all 180 degree values on steering, don’t we ?).
This setup in action:
Leave a Reply