Yes, but you can buy cables with just a voltage output to screw terminals if you look on line.
@Grumpy_Mike
great, but the main purpose of the device is to send data to the computer so it's already connected to the USB of the computer , the idea is to use the above technique so a single usb cable from the computer can supply power to the main board and the ultrasonic sensor by using a1 to 2 USB Hub like this one Amazon.com : 2 port usb hub
this way I can Avoid the use of additional power supply plug . and to use just one cable for every thing .
That you know of.
But many here know better. That's why we teach non-blocking code, aka Do_Multiple_Things_At_The_Same_Time.
You can blah-blah-blah definitions all you want but when I have inputs being read and responses started in a 50+KHz void loop(), that's multitasking at the 20 microsecond smoothness level on a single thread... a technique known since at least the late 70's though I learned it in the early 80's on 8080 and 6502 machines.
Yes, the OP's code can be converted. I would prefer to convert working Do_One_Thing_Right sketches to non-blocking (cut&dry work) and combine them.
If it is going through the USB port then it is limited to 5V. Also many USB devices in the hobby world do not go through external hubs.
Sorry but I still not "get" what you are trying to do. Can you draw a diagram please.
I still not understand, why do you need any home-made cables for it?
Standard Arduino Uno has a three 5v pins and a five GND.
Moreover, if you use a breadboard, (as you mentioned above) - then you only need one "5V" pin. You connect this pin to the power line on the breadboard and power all other devices from it.
No I'm using Arduino nano with just one 5v pin,
and as I mentioned earlier, I have many components to connect to the 5v pin which is enough to power the + rail on the breadboard,
the problem happens with the ultrasonic sensor which stop taking measurement when connected to the + rail on the breadboard, but works only when connected directly to the 5v pin on the Nano.
@Grumpy_Mike
here the supposed diagram, I apologize as it's handwritten and not in high quality.
as you can see, there is a USB splitter connected directly to the computer that supply 2 cables of USB
the first connected to the Nano USB port.
the second cable is used to supply the 5v and ground wires to the ultrasonic sensor.
So how do you see this.
@docdoc
Sure, I have a clear path in my mind, which I translated into the code in my last sketch.
I have Made a handwritten scheme of the states as you can find from here.
I apologize it's not in high quality.
as you can see, here there is there is 2 modes where in mode 1 the state is zero and mode 2 the state is shifted from state 1 to 6 smoothly with the code in my last modified sketch and I'm satisfyed with it.
the point I wanted to say that I have used the following code from state 0 to state 1.
void weight3() {
switch (GetKey("0CD")) {
case 'C':
State = S_Phone;
return;
case 'D':
State = S_Phone;
return;
case '0':
State = S_Phone;
return;
}
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
delay(400);
}
as you can see here takes weight measurement all the time except for when there is some input, and this the best which I can do with rather satisfactory performance for a personal project.
do you think it worth's to modify the above code or continue on with next phases of testing of the project?
Classic Nano has a two 5v pins - one that labeled as "5v", and the other unlabeled on ICSP header:

Could it be a "breadboard middle gap issue" ?
(the link)
I have a Nano Clone, But I'll try your abovementioned technique.
All clones has the same ICSP header
There looks to be two outputs to that splitter in your diagram where in fact you only have one. The current you can get out of one connection to your PC is limited by your PC. Looking at one splitter on the list from amazon. USB splitter
It says:-
【Support Power Charging】For a stable connection, please avoid connecting devices that exceed a total of 900 mA,Avoid using two devices with more than 5V 1.2A at the same time, as the power is too high and the connection is easily broken.
It looks like the same problem you have with using more than one 5V pin from that video. The current has to come from somewhere, it is not free.
What you need to know is:-
- How much current your computer delver to the single USB socket?
- How much current do you need to power all your Ultrasonic sensors?
- How many sensors are actively transmitting at any one time?
My RPi 4 runs on a 3A USB wall wart. PC is good for 500mA.
It's not very bright to run power through the board unless it is small power. Search words are: external power.
I tried this technique and It really worked.
@docdoc
I really appreciate your help, the sketch performance now is satisfying for me And I'll try the real thing soon but I have question about the simulation before doing any life testing.
When I set the loop to measure height always and only I noticed that the ultrasonic reading is not constant, but it changes from the sensor reading and zero as you can see here in the serial monitor window.
So what the cause of this.
To let me test your latest code (I mean the one with that behaviour) I need a link to that version of the Wokwi project, not just a picture (or at least the full source I can copy/paste in my Wokwi test, if the wirings are the same of the last one).
PS: and remember, if you want to thow us the serial output, as you can do with the code, please just use copy/paste (ad "code") of the text, don't use screenshots as it's just a waste of time (for you to capture and paste a screenshot), resources (for the forum), and lastly it's often not enough (it's not this case but with a screenshot we can see just a bunch of lines, not the entire output)...![]()
@docdoc
Here is the wokwei link
You can try it.
this is an experimental sketch not the final one.
the height measuring code is
void Height() { // height measurement module
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration_us = pulseIn(echoPin, HIGH);
distance_cm = 0.017 * duration_us;
//lcd_1.clear();
// lcd_1.setCursor(0, 1);
// lcd_1.print("Height: ");
// lcd_1.print(distance_cm);
Serial.print("Height: ");
Serial.println(distance_cm);
delay(1000);
State = S_Weight;
}
The loop has only the height measurement. As I use this sketch to test single modules only, and when I tested the height measurement I found such a problem.
If there isn't something I'm missing, I can't see anything wrong causing this problem, except it seems to me they perfectly implemented physical SR04 sensors, together with its damn "zero-distance" defect... In "real life" I use SRF05 instead of that SR04 exactly for this reason, the SRF05s that I have used since I had to abandon the SR04s with that defect, I have never had any problems.
So now I think you can just ignore any bad readings (distance == 0) with a little modification to ignore such zero value:
void Height() { // height measurement module
duration_us = 0;
while (duration_us == 0) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration_us = pulseIn(echoPin, HIGH);
distance_cm = 0.017 * duration_us;
if (duration_us == 0) {
Serial.print("ZERO! ");
delay(50);
}
}
//lcd_1.clear();
// lcd_1.setCursor(0, 1);
// lcd_1.print("Height: ");
// lcd_1.print(distance_cm);
Serial.print("Height: ");
Serial.println(distance_cm);
delay(1000);
State = S_Weight;
}
Then when you have to physically implement the project, I still recommend using the SRF05s.
@docdoc
I realy appreciate your help,
Could you please help me understand the role of those lines in the get key function .
buf[ptr++] = customKey;
buf[ptr] = 0x0; // Always end the string with 0x0
and the buffer reset function
ptr = 0;
buf[0] = 0x0;


