Hello, for an aquarium project I needed a long electrical wire that could:
- supply power to device
- allow communication
- Current and voltages are low
- Wire is +/- 3m long
- Slow data transfers
- Bidirectional communication, half duplex
- Limited space in device
- Galvanic isolation
The communication is between 2 devices. The device can be an Arduino, Raspberry PI or other device using the digital pins.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Some sensors, like the DS18B20, use 3 wires to supply power and communicate with another device. In this project the wires have the following functions:
- Data (0 / +5V)
After some searching on the net I couldn’t find something simple that could easily be implemented. Most setups are based on certain chips and protocols with a lot of options that I didn’t need. Although I found some nice examples that could be adapted to my needs like:
- NXP, AN2342, https://www.nxp.com/docs/en/application-note/AN23.... figure 5
- EmSa,http://www.esacademy.com, Can I do galvanic decoupling of my I2C bus?
- Embedded,https://www.embedded.com/print/4025023, figure 1
To be flexible I decided to build a circuit, use standard / common parts, program a simple protocol. Note: Because this project is used in another project I will explain the building of the circuit and the programming of the test program. Feel free to use this for your own project, you need to create a suitable protocol for your needs.
Step 2: Partslist
- Power supply +5V
- Flexible household electric wire with 3 conductors
- Perfoboard 5x7cm
- 2x Resistor 470Ω
- 1x Resistor 680Ω
- 2x Resistor 1kΩ
- 2x Diode (e.g. 1N4148)
- 2x Optocoupler EL817
- Pin header female 2 pin
- Pin header female 3 pin
- Pin header female 4 pin
- Round header female 6 pin
- Round header female 4 pin
Also some tools are needed: tweezers, cutters, vise, soldering iron, wick, stand.
How to solder: https://learn.adafruit.com/adafruit-guide-excelle...
Be aware of the safety risks and use personal protective equipment.
Step 3: Schematic
Explanation of the schematic:
Because of the limited space, the right side of the schematic is housed in the machine with device 2. The left side of the schematic is the bulk and is operated by device 1. Between the left and right side the data conductor.
- The digital “OUT” on the right side is protected by a diode.
- The optocoupler “OUT” is protected by a diode.
- To limit the current a resistor is in front of pin 1 of optocouplers “IN” and “OUT”
- Pin 2 of optocouplers is connected to ground
- Pin 3 emitter is grounded with a resistor
- Pin 4 collector is supplied with power
To visualize data transfer a led is connected to the data line. The resistor value depends on the led and the desired brightness. Warning: If the resistor value is too low, too much current will burn out pin out of device 2 or the optocoupler “IN” will not be driven correctly.
- If “OUT1” or “OUT2” is “HIGH” the Data line will be +5V.
- If “OUT1” or “OUT2” is “LOW” the Data line will be 0V.
- At pin “IN1” or IN2” the value of the Data line can be read.
In Fritzing the layout of the parts on the perfoboard are determined. The diodes and resistors are positioned vertically, see the yellow, orange and red lines. The blue lines are the conductors under the perfoboard.
Step 4: Programming
To test if the circuit is working, you can use the attached programs.
Device 1 is the master and should be powered last. It will send a certain sequence of bits. At first 8 startbits, 1 stopbit and then a sequence “on” and “off”.
Device 2 is the slave and should be powered first. The program will start to read the dataline. When 8 startbits are read. The program will start to record the bits. When 8 bits are recorded the program will return the bits.
During the dataswap the “on” and “off” bits can be monitored by the blinking led and the leds (pin13) on the devices.
When your soldering is ok and the programs are loaded, then you'll see the blinking of the leds similar to the led in the video.
(To avoid shorting the circuit, the bare metal conductors can to be coated with epoxy)