Go Down

Topic: Multiple HC-SR04 in one UNO (Read 1 time) previous topic - next topic

samaras

Hello. I need help with special project. I know, there are some quite similar threads, yet but I think about my problem in other way, maybe.  :)

I trying to measure distance with more than 15 HC-SR04. I choosed additional DMX to use less pins from arduino, with possibility to connect maybe 128 sensors and more.

Circuit in attachment.

DMX works fine - SIG to one specific TRIG and sensor sends ECHO right. BUT I have more echos in one pin connected and this cause problem. (Output = 0cm). When I use diode after echo and current doesnt divide to all other sensor's echos, it works, but veeery unstable.

Then I used NewPing.h, no way to send echo through DMXs back.

THIS IS MY DMX

My code:
Code: [Select]
#include <Console.h>
#include <NewPing.h>

#define PING_PIN 6
NewPing sonar(PING_PIN, 12);

byte ps[4]={2,3,4,5};
byte ss[4]={7,8,9,10};

void setup() {
  Serial.begin(9600);
  for(int i = 0; i<4; i++){
    pinMode(ps[i],OUTPUT);
    pinMode(ss[i],OUTPUT);
  }
}

void loop() {
  setSensor(0);
  delay(500);
  unsigned int uS = sonar.ping();
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM);
  Serial.println("cm");
}

void nula(){
  for(int i = 0; i<4; i++){
    digitalWrite(ps[i], LOW);
  }
  for(int i = 0; i<4; i++){
    digitalWrite(ss[i], LOW);
  }
}

void setSensor(int num){
  nula();
  int ps_tmp = num/16;
  int ss_tmp = num%16;
 
  int pss[4]={0}; int sss[4]={0};
 
  int i = 0;
  while(ps_tmp > 0){
    pss[i++] = ps_tmp%2;
    ps_tmp = ps_tmp/2;
  }
  i = 0;
  while(ss_tmp > 0){
    sss[i++] = ss_tmp%2;
    ss_tmp = ss_tmp/2;
  } 
  for(int j = 0; j < 4; j++){
    if(pss[j] == 1){
      digitalWrite(ps[j], HIGH);
    }else {
      digitalWrite(ps[j], LOW);
    }
    if(sss[j] == 1){
      digitalWrite(ss[j], HIGH);
    }else {
      digitalWrite(ss[j], LOW);
    }
  }
}



Please, If you have any suggestions, I will be so thankful. I trying to solve this problem too long.


PS - sorry for my english :)

PaulS

Code: [Select]
  delay(500);
  unsigned int uS = sonar.ping();

Using a non-blocking library to read the ping sensor, and using blocking code to waste time makes no sense.

Code: [Select]
#define PING_PIN 6
NewPing sonar(PING_PIN, 12);

Using a name for the trigger pin and a number for the echo pin doesn't make sense.

Complaining about not being able to handle multiple sensors while posting code that deals with one sensor doesn't make sense.

Personally, I suspect that you have some unrealistic expectations about the sensors you are using. The sensor has a 15 degree field of view. At most 24 sensors would be need to have a 360 degree field of view. I can't imagine why you think you need 5 times that many, or more.


samaras

Im so sorry about that. My false - it was just a test. there was ...
Code: [Select]
NewPing sonar(PING_PIN, PING_PIN);
... when i tried to send signal back throught DMX - not real. But never mind about it. Before this code I didnt use NewPing.h and defined one pin(12) as input for ECHO. And that delay was for me. It was less measurements to check. And as you wrote about 24 sensors for view 360 degree - try to imagine something bigger, what needs more sensors.

And Im so sorry if I look now like a lame for the mistake, but I'm new there and new in Arduino, and I hoped in some experienced and understandig approach.

PaulS

Quote
try to imagine something bigger, what needs more sensors.
I'm trying to imagine a circle with more than 360 degrees. But, physics keeps getting in the way. Forget about me imagining anything. You explain what you need more than 24 sensors for.

samaras

Ok, try to imagine mechanism, which scans changable surface - higher or lower... long mechanism - no one point.
Better to looking help in this forum?

Go Up