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.
My code:
#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