I have two circuits one having a ultra sound sensor and one other having a relay module. So i'm trying to establish communication between the two to send and recieve data. I just want to know which way is the best so that one arduino will send data only when the other is powered and able to recieve data. So that there is no problem when one circuit is powered on and the other is not and the data is not sent until the connection between the two is established .This is because the circuits are powered by different power sources and the current is not predictable and i dont want any miscommunication happening between them.

any way is okay like rf or wifi or some other methods? Using other devices is also an option like ESP32 which has builtin wifi and bluetooth, But wired is not possible because the distance is too big like about 15-17 meters and using the same power source is not viable for the same reason. Tell me also if the distance im worried about is not a problem?

  • data is not sent until the connection between the two is established makes no sense ... it is like being in a forest, trying to find somebody, but you do not call their name until you are certain that they can hear you
    – jsotola
    Apr 8 at 18:55
  • Its not like arduinos should not send any data it is only that it should not send data for processing such as value from ultrasound sensor until it is connected to the other arduino Apr 9 at 4:46
  • why not send the data? ... if it is acknowledged, then you are done, otherwise retransmit data until it is acknowledged
    – jsotola
    Apr 9 at 5:03
  • Over Wifi you can use a tcp based protocol. Before you can send data you have to establish a socket connection. If this worked, the peer must be up. If the the peer goes down you'll get notified, if it goes down while you are sending , the protocol does not confirm and after the timeout you know the data has not been sent. Then you can resent it as soon as the connection can be reestablished. Bluetooth handles the handshake also for you, you have to connect the peers before you can send data. There is also the possibility to use a Queue server. The most common for IOT is a MQTT Server. Apr 9 at 7:50
  • And yes, I would recommend to use ESP32 boards. I don't know if there are usefull TCP implementations for a simple Arduinos. Apr 9 at 7:53

Let the ultrasound-module broadcast measurements and not care about whether anyone are listening or not. If you are using wifi, you can send to the broadcast address of the network you are using. Then the ultrasound-module does not need to know anything about the receiver, like ip address or number of receivers. The only thing you need to make sure is that they are on the same subnet. If you want to, you can later put another module on the same subnet and it will also receive the data.

If you establish a handshake protocol it complicates things, because there are so many cases you need to consider. What should happen if communication link dies after handshake, but before data are transmittet? Should the receiver acknowledge the data? What should the sender do, if it does not receive the acknowledge? etc...

If the only thing the sender is using the handshake for is to know whether to send data or not, then just send it and forget about it. If it was to do something special, in case there are no receiver, like logging data and send the log when the receiver comes back online, then there is a use case for the handshaking.


One way is periodically send a "Hello?" request. If you don't get a "Hi, I'm here." reply, then don't send your data. These calls and responses could be as simple as couple of constant bytes that won't appear in your data. The master would send it out and wait briefly for the slave to repeat it. If the master times out, it assumes the slave isn't awake.


which way of communication is a viable option

Bluetooth 2 range is generally quoted as ~10 meters but that sounds conservative if the conditions (no obstacles, no or limited interference) and antennas are good. Here's an article that discusses that. But if that isn't suitable there are other RF technologies that are designed for longer range.

  • I know but how like bluetooth or wifi with one in AP or rf something like that Apr 9 at 4:46
  • This should work just as well over a radio based link. Or perhaps I don't understand your question.
    – JRobert
    Apr 9 at 11:45
  • I'm asking which way of communication is a viable option. Apr 9 at 15:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.