problem with using 5 hc-sr04 and mega2560

hi guys I'm working on an obstacle avoidance robot and it has 5 ultrasonic sensors i fixed the sensors on the robot and connect all of the gnd pins and vcc pins together(parallel) and now i have one wire for vcc and one wire for gnd and connect them to the arduino vcc and gnd and connect trig pin ands echo pins to the other pins of arduino

my first concern is about arduino current draw.with connecting like that can arduino make the enough current? or i have to use an external power supply? how can i connect them ?

second problem : when the robot starts some of sensors dosent work and the motors dosent work like i want

thanks for your help

According to this http://www.micropik.com/PDF/HCSR04.pdf

the working current of this device is 15 mA. So, five of those should be within the capability of the mega. That is probably the current when they are broadcasting sound, you should only be pinging one at a time otherwise they will get confused.

How are you powering your arduino ?

What does the motor do, that you don't want. Your motor is probably underpowered. Almost everybody who builds such a robot, does not provide enough power for the motor.

thanks for your answer my motor model is Faulhaber Hubble and its no load current is 0.075A and i dirve it with L298 i use a 12v/400ma supply when i connect all the sensors and see they result in the serial monitor , sometimes one of them and sometimes two of them dont work and they show 0 but when i test them one by one they work good i used digital pins for sensors not pwm.is this true or not? when there is no obstacle in the robot way it must go straight ahead but it turns and confused(use five sensors) but when i use 2 sensors it works true :relaxed:

this is the code that i use

[quote][quote]
#include <Ultrasonic.h>
////////////////////////////////////////////////////////////////////////////////
#define TRIGGER_PIN1  45
#define ECHO_PIN1     43  
////////////////////////////////////////////////////////////////////////////////
#define TRIGGER_PIN2  39
#define ECHO_PIN2     37
////////////////////////////////////////////////////////////////////////////////
#define TRIGGER_PIN3  51
#define ECHO_PIN3     49
////////////////////////////////////////////////////////////////////////////////
#define TRIGGER_PIN4  31
#define ECHO_PIN4     33
////////////////////////////////////////////////////////////////////////////////
#define TRIGGER_PIN5  30
#define ECHO_PIN5     28
////////////////////////////////////////////////////////////////////////////////
Ultrasonic ultrasonic1(TRIGGER_PIN1, ECHO_PIN1);
Ultrasonic ultrasonic2(TRIGGER_PIN2, ECHO_PIN2);
Ultrasonic ultrasonic3(TRIGGER_PIN3, ECHO_PIN3);
Ultrasonic ultrasonic4(TRIGGER_PIN4, ECHO_PIN4);
Ultrasonic ultrasonic5(TRIGGER_PIN5, ECHO_PIN5);
///////////////////////////////////////////////////////////////////////////////
int limit=20;
int pwm=100;
  float cmMsec1,cmMsec2,cmMsec3,cmMsec4,cmMsec5 ;
void setup()
  {
  Serial.begin(9600);
  pinMode(53,OUTPUT);
  digitalWrite(53,HIGH);
  pinMode(9,OUTPUT);
  
  pinMode(8,OUTPUT);
 
  pinMode(11,OUTPUT);
  
  pinMode(10,OUTPUT);

  }

void loop()
  {

  ////////////////////////////////////////////////////////////////////////////////////
  long microsec1 = ultrasonic1.timing();
  cmMsec1 = ultrasonic1.convert(microsec1, Ultrasonic::CM);
  Serial.print(" CM1: ");
  Serial.print(cmMsec1);
  ////////////////////////////////////////////////////////////////////////////////////
 long microsec2 = ultrasonic2.timing();
  cmMsec2 = ultrasonic2.convert(microsec2, Ultrasonic::CM);
  Serial.print("      CM2: ");
  Serial.print(cmMsec2);
  ////////////////////////////////////////////////////////////////////////////////////
  long microsec3 = ultrasonic3.timing();
  cmMsec3 = ultrasonic3.convert(microsec3, Ultrasonic::CM);
  Serial.print("           CM3: ");
  Serial.print(cmMsec3);
  /////////////////////////////////////////////////////////////////////////////////////
  long microsec4 = ultrasonic4.timing();
  cmMsec4 = ultrasonic4.convert(microsec4, Ultrasonic::CM);
  Serial.print("                CM4: ");
  Serial.println(cmMsec4);
  /////////////////////////////////////////////////////////////////////////////////////
 long microsec5 = ultrasonic5.timing();
  cmMsec5 = ultrasonic5.convert(microsec5, Ultrasonic::CM);
  Serial.print("                      CM5: ");
  Serial.println(cmMsec5);[/quote][/quote]

when you test them separately, do you use the same pins ?

Should you be defining all of those trigger pins and echo pins which you use, as inputs and outputs in setup( ) ?

can you run the robot with the 5 sensors, but the motor completely disconnected, so that it can't affect the arduino voltage at all ?

when i connect all the sensors and see they result in the serial monitor , sometimes one of them and sometimes two of them dont work and they show 0

In my experience, the performance of those sensors is always a bit flakey, particularly if there is actually nothing right in front of them. Your calculations and logic for using the result of the sensor needs to be robust to be able to cope with this.

You can't interpret 0 as zero, it actually means it can't see anything, I think.

when i use them separately they work nice but i use all of them they confused when all of them work one of them shows the 0cm for a moment and it causes robot to turn for a moment in the beginning after that it goes straight a head and then one of the motors turn however there is no obstacle in front of it! and about the trig and echo pins because i use the sensors library i dont define them as input or output