Coding for Use Arduino Uno as a switch

What I want is If I pugged 3 wires to the digital pins (6,7,8) in Uno board , Program should run in loop firstly shorting pin 6 and 7 then after secondly pin 6 and 8 must shorting after that again 6 & 7 like that. How can I do it. Please help me with some coding.

Arduino pins cannot do that directly.

What is connected to these wires?

1 Like

You can't. Digital pins do not work like that. You will have to use an external data select / multiplexer chip.

What is your application?

1 Like

Data Wires

More detail

"shorting pins" can be done with an optocoupler for example this would let you use the PIN to short the ACTION pin and the COMMON pin together

(taken from my French tutorial on triggering a camera's controls)

1 Like

Thank You, Transferring Two data lines one after another to a single wire data receiver.

More detail. To make a good suggestion we need to know voltage, current, data rate, data protocol...

You need a multiplexer chip called a 4053 this has three two channel data select switches in it. Assuming that the data lines carry no more than 5V signals and have a common ground.

Your answers are very minimal, and I assume you are using some sort of translator program. Please write more than a few words for you answers.

you need to take into account then what will flow through the component and ensure it's fit for purpose. An optocoupler might not cut it. Indeed the 4053 series could be a good option (look for "channel multiplexer" or "channel analog multiplexer with logic-level conversion")

https://www.autonicsonline.com/image/pdf/THD.pdf

I have two of this THD-W-T modal sensors. sensor wire out diagram also on the pdf. But I only have one data receiving unit. Multi sensor diagram on pdf doesn't working. so I want to send data lines to the receiver one after another using Arduino Uno board. cause currently I only have that UNO module only.

so you want to route the Modbus/RS485 communications to your arduino one after the other so that you could listen sequentially to one sensor information?

1 Like

I understood @osandawelianga only wants the Arduino to act as a switch, not to receive the data itself.

But RS485 uses pairs of wires carrying the data signal, which can be >5V and can be negative voltages, so these definitely cannot be connected directly to arduino pins. The Arduino would be damaged.

My best suggestion, given my limited knowledge of RS485, would be a DPDT relay. Arduino pins cannot drive a relay directly, so you would need to buy a DPDT relay board with a built-in driver circuit, or make your own driver circuit with a transistor.

RS485 communication can happen on a bus if there is some sort of agreement on the communication protocol

1 Like


I have buy those modules and connected as it is in diagram. How could I get readings from sensor 1 and read it from Arduino serial monitor.
Can please guide me.

What are those modules? Please supply a link to them.

Why have you connected one to pins 0 and 1, those pins are used for serial input / output and with that module in place you will not be able to download any code to your Arduino.

RS-485 is a 2-wire half-duplex serial interface allowing multiple devices to communicate over the same pair of wires.

however, because it is half-duplex, only one device can transmit at a time. a common approach for handling this is to have a master (e.g. arduino) that polls each other device on the bus given that device a chance to respond as well as sending information to the device (sending nothing is simply a poll)

typical rs-485 interfaces have a TX (and RX) enable pin which must be disabled when not transmitting to no interfere with the device that is allowed to transmit. (Serial.flush() can be used to know when transmission is complete)

see page 6-7 of the posted datasheet

i don't believe your diagram is accurate. only one board is needed and connections to the arduino are missing

you should only need one RS-485 interface for your arduino that connects to a pair of wires between it and the other devices. beside power and ground, there are TX and RX data and TX and RX enable

@osandawelianga Check the diagram on page A-219 of the THD document you linked; this device is intended to reside on an RS485 BUS, with up to 31 devices talking on the same bus. You need only 1 RS485 adapter for your Arduino!

With an Uno, you must either do your RS485 on a software serial port, reserving the hardware serial for PC communication (i.e. uploads, and using Serial Monitor for debugging your code), OR use the hardware serial for both RS485 comms, and uploads (Serial Monitor will not be available this way). To do so, you must remove the RS485 adapter's signals from the Arduino when you want to upload, AND disconnect the USB when testing your setup. This is cumbersome, awkward, and painful, but it can be done.

Topic LOCKED.
DO NOT DOUBLE POST !