Two Nano's communicating With One Wire?

If I have two Nano's. (Nano1 and Nano2) Every digital and analog pin is being used except D13 and A0 on Nano1 and everything except D2 on Nano2. Is there a way to send data to Nano2 using only one of the remaining pins on Nan01?Then recieve that data on Nano2 to work relays, stepper motors, dc motors etc. Would something like this example work? The question marks aren't part of the code, I just don't know what to do there or if it's even possible.

Nano1

int sendPin = 13;
const int switch1 = 2;
const int  switch2 = 3;
const int switch3 = 4;

int sw1val;
int sw2val;
int sw3val;

void setup(){

pinMode (sendPin, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);

void loop(){
sw1val = digitalRead(switch1);
sw2val = digitalRead(switch2);
sw3val = digitalRead(switch3);

If(swval1 == HIGH){
? Write(sendPin,  ?);
}
If(swval2 == HIGH){
? Write(sendPin,  ?);
}
If(swval3 == HIGH){
? Write(sendPin,  ?);
}
________________________________________________________________

Nano2

int recPin = 2;
int relay1 = 3;
int relay2 = 4;
int relay3 = 5;
int recPinval;

void setup(){
pinMode(recPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT;
pinMode(relay3, OUTPUT;

}

void loop(){

recPinVal = ? Read(recPin);

If(recPinval == ?){
digitalWrite(relay1, HIGH);
}

If(recPinval == ?){
digitalWrite(relay2, HIGH);
}

If(recPinval == ?){
digitalWrite(relay3, HIGH);
}
}

What happens when you try it?

This is a bad idea, especially for a beginner. Using two Arduino together is more than twice as difficult as using two Arduino separately.

Better options include:

  1. An Arduino with more pins like a Mega.
  2. Use one Nano but give it extra pins using I/O expansion chips.

To get more detailed advice, give more details of the circuit you want to make. How many and what types of relays, motors etc. do you want to use?

Also please edit and correct your post above because it is breaking forum rules by not using code tags.

I agree that using one microprocessor would be the best solution. If you have yet to buy anything, think it through.

If the communication is one way and you can't help wanting to use two boards, maybe SoftwareSerial would be fun to try.

Which Nano of them all do you intend to use?

a7

Why should you need more than one pin?
Of course you need common GND as well.

I haven't tried it yet.

They would be separate (200 feet apart) and running 2 seperate codes. Why would it be a bad idea? Is it possible though? Has it ever been done before? I could use a Mega but I would have to run another 200 feet of cat5. So my question was can a single digital pin on Nano1 write different values (other than HIGH and LOW) to a single digital pin that can read those values on Nano2? Is there a more simple solution? Do beginners usually send wiring diagrams like this?


That would be a valid reason.

  • Will it be one-way communication?
  • Distance might have its own challenges; consider RS232/RS422/RS485.

Because it makes life (read: coding) more complex.

If you are 200’ apart you need some form of signal driver at one end and opto coupled input at the receiver .

When you say all the pins does that include the Tx /Rx pins ? These are shared with USB .
You could use a multiplexer to give more I/O , but an easier option is a different processor such as a Mega .
What does the project do ?

maybe simpler to use wireless communication such as LoRa
e.g. TTGO LoRa32 SX1276 OLED Board or Heltec WiFi LoRa 32(V3), ESP32S3 + SX1262 LoRa Node

Of course not

By definition a digital pin is either HIGH or LOW.

However, the digital pin could be used to send a pattern of pulses to be decoded by the receiver. We would need a name for this process. We could perhaps call it a serial link because a series of pulses is being sent

Please note that this may not be an original idea on my part :grinning:

2 Likes

It's not a bad idea.

What is a bad idea is not mentioning such an important factor in your original question. It completely changes the context and the answer.

You only need one pin to transmit on N1 and one to receive on N2 plus common ground.
The problem is more the wire length than anything else.
You could try software serial at baud rate 300. If it doesn't work you need to use something even slower.
If you only need to send a command to switch one of your relays, it could be something super simple like 100ms pulse for relay 1, 200ms pulse for relay 2 etc...

And with 200 ft of wire. Actually 400 ft of wire, total. You no longer have a common ground! That is why a bipolar communications scheme is always used. No common ground.

I agree.

Everything seems to be working fine with the cat5 at that distance. Hardly any voltage drop.

I may try this. Thanks.

Every what thing? What did you end up doing hardware and software to accomplish the task you asked about?

a7

Decided to use a Mega 2650 and run another piece of cat5 200' long.