About pins of HC-SR04 Ultrasonic Sensor PCM and Bluetooth HC-05 PCM sensors

Hello

I have a basic question regarding these sensors that are connected to a Arduino UNO board:

  • Pins Trig and Echo of HC-SR04 Ultrasonic Sensor PCM:
    image

  • Pins RXD and TXD of Bluetooth HC-05 PCM:
    image

I am starting with Arduino. My question is:

Are these four related? Are pins Trig and Echo a kind of TX and RX Arduino UNO pins?

For Ultrasonic sensor, why Trig and Echo pins can be connected to any digital/analogic pins but are not strictly connected to RX/TX pins?:

Sorry if this is a silly question. Any further information please let me know.

Thank you!

Read about your sensor here. https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
Serial connections (TX, RX) are not used by this sensor, as it doesn't 'communicate', it simply uses two digital pins, one to trigger it, and the second to respond with a pulse.

Thank you! It helps me a lot.

To complete the answer, what do serial connections (TX, RX) produce on the Arduino UNO board (in contrast to Echo and Trigger)?

A serial(i.e. one-at-a-time) series of ones and zeros that, when parsed correctly, define text characters/numerics/control characters per ASCII chart(search web for ASCII). Usually, that parsing is done within your processor by a device called a UART, although it can also be done in software using something such as software serial.
TX is outbound (send) from the Arduino, while RX is inbound (receive).
More info than you probably want:

Ok. Sorry, again, but my mind needs to create a gate between those four connections. Let me explain:

TX = Send information from Arduino to external device (such as ultrasonic sensor)
RX = Receive information from external device (such as ultrasonic sensor) to Arduino

In the same way, we could think Echo and Trig as:

Trig = Send an 'order' to the ultrasonic sensor to produce ultrasonic waves (i.e. TX)
Echo = Receive the information from ultrasonic waves and Arduino receives it to obtain the duration of the length / distance from object (i.e. RX)

Under this perspective, are the connections related? If so, why don't we connect Echo and Trig to TX and RX connections?

What I wrote is probably very wrong, but my brain interprets it that way. That's why I ask you to correct me

image

Yes it helped me. This scheme helps me identifying that one device send and the other receive, thank you!

Yes, the trick is that TX/RX transmit information in a very specific fashion. The pulses your sensor sends/receives are single events. To transmit the character A, your TX pin will have transitioned from 0-1 and back again several times in a very short period of time, and only 'readable' by a device at the receiving end that expects those transitions in a specific order.

Ohh perfect.

But I have been told that digital pins (0-13) only have two states: LOW and HIGH. I understand TX/RX sends/receives one bit at a time, but since Trig and Echo are also digital connections (since they are connected to digital pins, which have two states), why Trig and Echo do not share the same transmition way as TX/RX? i.e.:

TX = Digital pin -> Hence single events pulses
RX = Digital pin -> Hence single events pulses

but since Trig and Echo are connected to any of pins 0-13:

Echo = Digital pin -> Hence single events pulses
Trig = Digital pin -> Hence single events pulses

What am I getting confused about?

Those two pins, and many others, are multifunctional. I.e. they normally are used for TX and RX, but if you eschew using serial for anything, you're free to use them as digital inputs or outputs. Similarly, analog pins A0-A5 can also be used as D14-d19. Some pins can be used as PWM outputs, but also as 'normal' digital pins.
This diagram might help:

Ok, since RX (pin 0) and TX (pin 1) are on the digital pins side, why the manuals and all the information on Internet do not standard the Trig and Echo connection to these particular pins? I think it would be more realistic, since:

Of course you may not know the answer, I am just wondering why they do not usually connect Echo and Trig to TX and RX since they share a lot of the purpose of its connections.

because those pins are also used for Serial Monitor, which is an incredibly useful feature for debugging and communicating with your code. Although it's perfectly fine to use them for other purposes, such as your trigger and echo, what it does is it prevents you from using them for anything SerialMonitor related. Without Serial Monitor, you're flying blind, a state that most of our newbies find themselves in until they realize their code can talk to them, via Serial Monitor, and be instructed by them, also via Serial Monitor. Not trying to be insulting, but you're understanding is limited because you don't even know what you don't know yet, if you get my drift.

1 Like

Don't worry.

When some people taught us, the teachers, about electronics we started with pure Arduino code. And I remember we used Serial Monitor to print the distance from the ultrasonic sensor to an obstacle and it was nice to compare with the reality.

Then we were learning about code blocks, because is more easy for students to learn fundamentals of programming.

However, we should not teach serial monitor and how to print because we aim to focus on more things to learn with the kids.

That's why we don't actually use serial monitor in our classes, although in the process of learning Arduino we used it.

Thank you for your patience.

most good libraries/examples stay away from the pins most Arduinos have that are dedicated to the Serial Monitor function. That's why I was surprised at your focus on this - Arduino is a very 'limited' platform, in the sense that there aren't a whole lot of ways to interact with the running code - Serial Monitor is the primary one, other than doing blinky-blinky stuff with the onboard LED. So writing examples that used RX/TX for other things would be self-defeating - as soon as the user went to do something like display a number, they would then have to move whatever example had used 0/1 to other pins, in order to keep from messing up serial.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.