Flex Sensor Controlled Rc Car Using Arduino Uno

by ganesh_20203 in Circuits > Arduino

316 Views, 0 Favorites, 0 Comments

Flex Sensor Controlled Rc Car Using Arduino Uno

Screenshot 2022-08-10 233503.jpg

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

  1. Arduino uno -1
  2. Gearmotors - 2
  3. Servo motor - L293D- 1
  4. Resister -163 ohm - 1
  5. Flex sensor - 1
  6. Jumper wires

Below I Have Attached the TinkerCAD Diagram

Screenshot 2022-08-10 231907.jpg

TinkerCAD diagram

Connections of Above Used L293D

Screenshot 2022-08-10 232056.jpg

Starting from top left :

  1. Power 1
  2. Input 4
  3. Output 4
  4. Ground
  5. Ground
  6. Output 3
  7. Input 3
  8. Enable 3&4
  9. Enable 1&2
  10. Input 1
  11. Output 1
  12. Ground
  13. Ground
  14. Output 2
  15. Input 2
  16. 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);

}

}