Hi everyone, this is my first time posting here and also my first project for Arduino.
Currently my setup right now is a basic RC car bought from Target and the motors, power, steering (steppers?) are connected to the motorshield which is then connected to the arduino.
which is also connected to the motor shield. Everything seems to be working fine, I'm still trying to figure out how to work the steering, which seems to be called the steppers I believe.
Here's the code:
It's just a simple go forward if the sensor is reading more than 200 cm, go forward and steer left if it's 100-200 cm, and go backwards if it's less than 100 cm. The distance calculations were found with a google search.
#include <AFMotor.h>
int IRpin = 0; // analog pin for reading the IR sensor
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_Stepper stepper(2, 2);
void setup() {
Serial.begin(9600); // start the serial port
motor.setSpeed(120);
stepper.setSpeed(10);
motor.run(RELEASE);
stepper.release();
}
void loop() {
float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
if ( distance > 200 ) {
motor.run(BACKWARD);
}
else if ( distance < 100 ) {
motor.run(FORWARD);
}
else if ( distance > 100 && distance < 200 )
{
stepper.step(1, FORWARD, SINGLE);
motor.run(BACKWARD);
}
}
The problem is when the board is turned on, there is a high pitched sound that is played from the board and I, for the life of me, can not figure out how to turn it off. Anyone got any ideas? Also if someone had instructions on how to use the steppers or steering that would be extremely helpful!
I'd be surprised if it was a stepper motor for steering. It would usually be a servo. Does the car have proportional steering, or just full left, centre, full right?
Probably not, but I don't think it would be a stepper motor either. I don't have a car like that around to look at. Maybe someone else knows how to drive the steering. It might be something like a solenoid.
might not be relevent but what kind of wires do you have comming from the steering assembly? just asking because most cheap rc's dont use steppers or servos,just a crappy dc motor with physical limits mounted in the plastic housing....
I am doing something similar to you. I suggest you use a servo, therefore you can control the degree of turn when something is sensed. I am using a $10 dollar remote controlled car that only turns in reverse. I am trying to figure out how to get it to reverse for a period of time (basically long enough for the car to turn 90degrees) when the pressure sensor is activated.
For my setup, I have the motors that drive the card forward and reverse plugged into M3. I have a set of wires coming out from the front of the car where the 2 wheels that turn plugged into M1. Does anyone have any tutorials or guidance on how to use the servo? I can't find the library for afmotor.h
Also how do I get rid of this annoying high pitched sound that turns on whenever I turn the car on?
For my setup, I have the motors that drive the card forward and reverse plugged into M3. I have a set of wires coming out from the front of the car where the 2 wheels that turn plugged into M1. Does anyone have any tutorials or guidance on how to use the servo? I can't find the library for afmotor.h
Also how do I get rid of this annoying high pitched sound that turns on whenever I turn the car on?
How about some pictures of the car - got any of those?
I suspect that the steering actuator is either a simple motor or electromagnet device; either way, you likely apply voltage/current one way (+V to one wire, GND to the other) to get it to steer in one direction, and the reverse to steer in the other; no current/voltage applied is "center". In other words, hook it up to an h-bridge motor controller that can handle the current (you'll want to measure this -first-).
I am also curious why (you might have a good reason) you didn't reverse engineer the controller board of the car instead of buying motor driver/controller boards (because they already exist on the car - and likely that car uses an TX2/RX2 chipset, which is extremely hackable)...?