Flex Sensor Controlled Rc Car Using Arduino Uno
by ganesh_20203 in Circuits > Arduino
370 Views, 0 Favorites, 0 Comments
Flex Sensor Controlled Rc Car Using Arduino Uno
Using two Gearmotors illustrating two wheels of a car and a flex sensor. Control its direction using the flex value output by the flex sensor. The gearmotors run in the forward direction for the higher range of flex values. It functions in the opposite direction in the lower range. reference breakthrough value considered is 85.
Supplies
- Arduino uno -1
- Gearmotors - 2
- Servo motor - L293D- 1
- Resister -163 ohm - 1
- Flex sensor - 1
- Jumper wires
Below I Have Attached the TinkerCAD Diagram
TinkerCAD diagram
Connections of Above Used L293D
Starting from top left :
- Power 1
- Input 4
- Output 4
- Ground
- Ground
- Output 3
- Input 3
- Enable 3&4
- Enable 1&2
- Input 1
- Output 1
- Ground
- Ground
- Output 2
- Input 2
- Power 2
Below Is the Code :
#define IN1 12
#define IN2 11
#define IN3 10
#define IN4 9
#define ena 5
#define enb 6
const int flexPin=A0;
void setup()
{
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
analogWrite(ena,0);
analogWrite(enb,0);
delay(1000);
Serial.begin(9600);
}
void loop()
{
int flexValue;
int a;
flexValue=analogRead(flexPin);
a=map(flexValue,159,511,0,255);
Serial.print("sensor : ");
Serial.println(a);
if (a>=85)
{
analogWrite(ena,flexValue);
analogWrite(enb,flexValue);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}else
if (a<85)
{
analogWrite(ena,flexValue);
analogWrite(enb,flexValue);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
}