Hi i made a car using the BTS7960 and it works just fine, but instead of changing the speed of the motors using a potentiometer i want to use hall effect sensor throttle
on pin A0 (with is throttle)
but a hall effect throttle is 0.86v to 4.23v instead of the 0v to 5v like a pot do
so there always some power given to the motor making the car moving without touching the throttle probably need a dead zone of some sort ?
Thanks for any help
#define potentiometer A0 // Variable Resistor
#define BU_C A1 // Clockwise Button
#define BU_S A2 // Stop Button
#define BU_An A4 // Anticlockwise Button
int RPWM1_Output = 5 ; // Arduino PWM output pin 5; connect to first IBT-2 pin 1 (RPWM)
int LPWM1_Output = 6; // Arduino PWM output pin 6; connect to first IBT-2 pin 2 (LPWM)
int RPWM2_Output = 9 ; // Arduino PWM output pin 9; connect to second IBT-2 pin 1 (RPWM)
int LPWM2_Output = 10; // Arduino PWM output pin 10; connect to second IBT-2 pin 2 (LPWM)
int R1_EN = 2; //enable of motor1 forward
int L1_EN = 3; //enable of motor1 reverse
int R2_EN = 4; //enable of motor2 forward
int L2_EN = 7; //enable of motor2 reverse
int read_ADC = 0;
int duty_cycle;
int set = 0;
void setup() { // put your setup code here, to run once:
pinMode(potentiometer, INPUT);
pinMode(BU_C, INPUT_PULLUP);
pinMode(BU_S, INPUT_PULLUP);
pinMode(BU_An, INPUT_PULLUP);
pinMode(RPWM1_Output, OUTPUT);
pinMode(LPWM1_Output, OUTPUT);
pinMode(RPWM2_Output, OUTPUT);
pinMode(LPWM2_Output, OUTPUT);
pinMode(R1_EN, OUTPUT);
pinMode(L1_EN, OUTPUT);
pinMode(R2_EN, OUTPUT);
pinMode(L2_EN, OUTPUT);
digitalWrite(R1_EN, HIGH);
digitalWrite(L1_EN, HIGH);
digitalWrite(R2_EN, HIGH);
digitalWrite(L2_EN, HIGH);
Serial.begin(9600);
}
void loop() { // put your main code here, to run repeatedly:
read_ADC = analogRead(potentiometer);
duty_cycle = map(read_ADC, 0, 1023, 0, 255);
if(digitalRead (BU_C) == 0){set = 2;}
if(digitalRead (BU_S) == 0){set = 0;}
if(digitalRead (BU_An) == 0){set = 1;}
if(set==0){
digitalWrite(RPWM1_Output, LOW);
digitalWrite(LPWM1_Output, LOW);
digitalWrite(RPWM2_Output, LOW);
digitalWrite(LPWM2_Output, LOW);
}
if(set==2){
analogWrite(RPWM1_Output, duty_cycle);
digitalWrite(LPWM1_Output, LOW);
analogWrite(RPWM2_Output, duty_cycle);
digitalWrite(LPWM2_Output, LOW);
}
if(set==1){
digitalWrite(RPWM1_Output, LOW);
analogWrite(LPWM1_Output, duty_cycle);
digitalWrite(RPWM2_Output, LOW);
analogWrite(LPWM2_Output, duty_cycle);
}
delay(50);
}