# Air core gauge control

Hello; I'm trying to control an old car dashboard which uses an air core motor for displaying the speed. I'm using Arduino uno board with l293d driver. I followed this for wiring l293d wiring

and for the code air core arduino

my problem is that the needle only reaches 90 degree and returns back to zero ?? I'm also asking how can I point to only specific angle without using the loop, I need the pwm values and the directions of coils !!!

You will get more help if you post the code you used. A link to a thread is not a clear indication of what code you are using. Post your code. Use code tags.

here is the code :

``````const float pi = 3.14159;

const float stepSize = 0.01; //This is the step size for incrementing the angle (in radians)

//this is the maximum resolution of the PWM output.
const int maxAnalogRes = 255;

/* Define the pins the meter is connected to. We need 1 PWM to vary the voltage in
* each coil, and two more pins to reverse the polarity in that coil. So a total
* of 6 pins (3 per coil).
*/
const int aircore1SinPin = 10; //this controls the voltage to the "sine" coil
const int aircore1CosPin = 11; //this controls the voltage to the "cosine" coil
const int aircore1SinDirPin1 = 2;//these two control the polarity to the "sine" coil
const int aircore1SinDirPin2 = 4;
const int aircore1CosDirPin1 = 7;//these two control the polarity to the "cosine" coil
const int aircore1CosDirPin2 = 8;

// milliseconds between each angular step.
int delayTime = 40;
void setup()
{
Serial.begin(115200);
//Set the pins to OUTPUT
pinMode(aircore1SinPin,OUTPUT);
pinMode(aircore1CosPin,OUTPUT);
pinMode(aircore1SinDirPin1,OUTPUT);
pinMode(aircore1SinDirPin2,OUTPUT);
pinMode(aircore1CosDirPin1,OUTPUT);
pinMode(aircore1CosDirPin2,OUTPUT);
// Set the initial direction as "forward". Of course it could be "reverse" depending on which lead you connected :-).
digitalWrite(aircore1SinDirPin1, HIGH);
digitalWrite(aircore1SinDirPin2, LOW);
digitalWrite(aircore1CosDirPin1, HIGH);
digitalWrite(aircore1CosDirPin2, LOW);
}

void loop()// run over and over again
{
//Rotate 0 through 360 degrees (OK, really 2*pi radians, but who cares?)
for(float i = 0; i < (2*pi); i = i + stepSize){
setMeterPosition(aircore1SinPin, aircore1SinDirPin1, aircore1SinDirPin2, aircore1CosPin, aircore1CosDirPin1, aircore1CosDirPin2, i);
//delay(delayTime);// waits for delayTime milliseconds
}

//Rotate 360 through 0 degrees
for(float i = (2*pi); i > 0; i = i - stepSize){
setMeterPosition(aircore1SinPin, aircore1SinDirPin1, aircore1SinDirPin2, aircore1CosPin, aircore1CosDirPin1, aircore1CosDirPin2, i);
delay(delayTime);// waits for delayTime milliseconds
}

}

// setMeterPosition() - put it at the angle in radians
void setMeterPosition(int sinPin, int sinDirPin1, int sinDirPin2, int cosPin, int cosDirPin1, int cosDirPin2, float pos){
// Calculate the voltage on the PWM pins based on the angle we want
float sinCoilValue = maxAnalogRes*sin(pos);
float cosCoilValue = maxAnalogRes*cos(pos);
// change the polarity of the coil depending on the sign of the voltage level
if (sinCoilValue<=0) {
digitalWrite(sinDirPin1, LOW); //Change to LOW if using relays
digitalWrite(sinDirPin2, HIGH); //comment this line out if using relays
} else {
digitalWrite(sinDirPin1, HIGH); //Change to HIGH if using relays
digitalWrite(sinDirPin2, LOW); //comment this line out if using relays
}
if (cosCoilValue<=0) {
digitalWrite(cosDirPin1, LOW); //Change to LOW if using relays
digitalWrite(cosDirPin2, HIGH); //comment this line out if using relays
} else {
digitalWrite(cosDirPin1, HIGH); //Change to HIGH if using relays
digitalWrite(cosDirPin2, LOW); //comment this line out if using relays
}

// take the absolute value because analogWrite doesn't take negatives
sinCoilValue = abs(sinCoilValue);
cosCoilValue = abs(cosCoilValue);
//Serial.println(sinCoilValue);
//Serial.println(cosCoilValue);
analogWrite(sinPin, sinCoilValue);
analogWrite(cosPin, cosCoilValue);
}
``````