Crash Avoidance System For My RC Car, Need Help

Dear Friends,

I have a project for crash avoidance system for my rc car. Everything is running perfect but I have a small doubt. Here is the code as follows;

With this code, when ulstrasonic sensor detects an object, motor brakes immediatelly even if I push the throttle fully. After 2,5 seconds motor runs revers for 1,5 seconds slowly and go out of the u/s sensor range and I can use the transmitter as usual. That is what I wanted basically. However, despite there is no trigger action on transmitter if there is any object in the range of sensor motor runs revers. I know it acts what I wrote in the code but I want the ulstrasonic sensor runs when I use the transmitter ( forward action). So how should I upgrade/change my code in order to meet my a/m requirement. Any help, support will be appreciated.

Thanks.

#include <Servo.h>
int trigPin = 12;
int echoPin = 11;

int receiverPin = 3;

Servo esc;



void setup() {
  esc.attach(2);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int receiverValue = pulseIn(receiverPin, HIGH);
  int escValue = map(receiverValue, 950, 2000, 0, 180);
  esc.write(escValue);

  int sure, uzaklik;

  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  sure = pulseIn(echoPin, HIGH);

  uzaklik = (sure / 58);

  if (uzaklik < 20) {
    esc.write(0);
    delay(2000);
    esc.write(100);
    delay(1500);
  }
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Thank you very much. I already red the instructions and update my post especially for codes. I think it is much more better now.

Thanks for adding the code tags

Not only does it look better, it is easier to copy for examination or scroll through in the forum

There is nothing in code that can change the physical operation of your sensor. Look at the specifications for the sensor and you will find there is a "cone" of area that is scanned for reflections. As I recall it is 15 degrees wide. So anything within that area will cause a reflection and that is what you have proven.
In order to actually do what you want you will have to change sensors to an actual RADAR device that only has a tiny cone of response.

Add to the condition that controls the reverse response.

Test uzaklik, also test to see if the mapped value from the receiver is meaning throttle is active.

That would be escValue, can't be sure what value means go, but just don't go reverse if you aren't saying go forward over the remote. As well as seeing something ultrasonic in the way.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.