Feasability and general help

const int motorFR = A0; //defines motor FRONT RIGHT at analog pin 0
const int motorFL = A1; //defines motor FRONT LEFT at analog pin 1
const int motorBR = A2; //defines motor BACK RIGHT at analog pin 2
const int motorBL = A4; //defines motor BACK LEFT at analog pin 3
const int Button = A3; //defines our one and only button at analog pin 4
/*
HC-SR04 example sketch

by Isaac100
*/

float distance1, duration1;
float distance2, duration2;
float distance3, duration3;
float distance4, duration4;
float distance5, duration5;

const int trigPin1 = 3; //defines trig pin for ultrasonic 1 at pin 3
const int echoPin1 = 10; //defines echo pin for ultrasonic 1 at pin 10

const int trigPin2 = 6;
const int echoPin2 = 11;

const int trigPin3 = 8;
const int echoPin3 = 12;

const int trigPin5 = 2;
const int echoPin5 = 5;

const int trigPin4 = 7;
const int echoPin4 = 4;

void setup() {
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);

pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);

pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);

pinMode(trigPin4, OUTPUT);
pinMode(echoPin4, INPUT);

pinMode(trigPin5, OUTPUT);
pinMode(echoPin5, INPUT);
Serial.begin(9600);

pinMode(motorFR, OUTPUT);
pinMode(motorFL, OUTPUT);
pinMode(motorBR, OUTPUT);
pinMode(motorBL, OUTPUT);
pinMode(Button, INPUT);
}

void loop() {
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1 * .0343) / 2;
Serial.print("Distance1: ");
Serial.println(distance1);
delay(100);
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, LOW);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);

duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2 * .0343) / 2;
Serial.print("Distance2: ");
Serial.println(distance2);
delay(100);
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, LOW);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);

duration3 = pulseIn(echoPin3, HIGH);
distance3 = (duration3 * .0343) / 2;
Serial.print("Distance3: ");
Serial.println(distance3);
delay(100);
digitalWrite(trigPin3, LOW);
delayMicroseconds(2);
digitalWrite(trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3, LOW);

duration4 = pulseIn(echoPin4, HIGH);
distance4 = (duration4 * .0343) / 2;
Serial.print("Distance4: ");
Serial.println(distance4);
delay(100);
digitalWrite(trigPin4, LOW);
delayMicroseconds(2);
digitalWrite(trigPin4, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin4, LOW);

duration5 = pulseIn(echoPin5, HIGH);
distance5 = (duration5 * .0343) / 2;
Serial.print("Distance5: ");
Serial.println(distance5);
delay(100);
digitalWrite(trigPin5, LOW);
delayMicroseconds(2);
digitalWrite(trigPin5, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin5, LOW);

if (Button == HIGH) {
if (distance2 < 20) {
analogWrite(A0, HIGH);
analogWrite(A2, HIGH);
delay(1000);
analogWrite(A0, LOW);
analogWrite(A2, LOW);
}
if (distance1 < 20) {
analogWrite(A0, LOW);
analogWrite(A1, LOW);
analogWrite(A2, LOW);
analogWrite(A4, LOW);
}
if (distance4 < 20) {
analogWrite(A1, HIGH);
analogWrite(A4, HIGH);
delay(1000);
analogWrite(A1, LOW);
analogWrite(A4, LOW);
}
if (distance3 < 20) {
analogWrite(A1, HIGH);
analogWrite(A4, HIGH);
delay(1000);
analogWrite(A1, LOW);
analogWrite(A4, LOW);
}
if (distance5 < 20) {
analogWrite(A0, HIGH);
analogWrite(A2, HIGH);
delay(1000);
analogWrite(A0, LOW);
analogWrite(A2, LOW);
}
}
}

/This is my code, I do not think it is right. I am making a self-driving car using an Arduino nano 5 ultrasonic sensors and 4 motors. I am in the testing stage right now, and when I open the serial monitor to look at the data I am receiving, it shows a distance of 0 for all of them. Please help! And thank you in advance!/

  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);

Shouldn't the trigger pin go HIGH somewhere ?

Yes, thank you! But it did not work.

Please post your amended code.
In code tags this time.

I don’t understand why you’re waggling the pull-ups on the analogue pins on and off.

(Your code is too long, BTW)

const int Button = A3; 
...
if (Button == HIGH) {

Oops

Also just realised much of your code is in the wrong order.
You need to trigger the sensor, then read it, not the other way around.

And please - step away from the cut-and-paste controls.

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify each of your original posts (not re-post them) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

Hi,
Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Have you got code that just tests ONE ultrasonic unit and got that code working.

If you are developing code you should have gone through this phase, rather than write a mass of code for everything and expected it to work.

If you have not, then for the moment dump your existing code and go back to programming basics.
Write code for ONE and ONLY ONE ultrasonic unit and get it working before adding more, one at a time.

Tom... :slight_smile: