Having trouble communicating between multiple arduinos

I am attempting to create a fencing pocket box using Arduino Nanos and wireless modules. The communication from the modules is fine, but I can't seem to communicate between the ports. The black port is CPost, the middle yellow post is BPost and the bottom yellow post is APost. WHat is supposed to happen is when B is touched to A one signal is outputted, and when B is touched to C a different sidnal is outputted. The code and physical builds are identical, but I need to be able to touch the B post of one to the C post of the other (and vice versa) but it does not work. Any guidance would be appreciated.

#include "nRF24L01.h" //NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"

#define APost 2
#define CPost 3
#define BPost 4

int SentMessage[1] = {000}; 
RF24 radio(9,10); // NRF24L01 used SPI pins + Pin 9 and 10 on the NANO

const uint64_t pipe = 0xE6E6E6E6E6E6; // Needs to be the same for communicating between 2 NRF24L01 

void setup()
{
  pinMode(APost, INPUT);
  pinMode(CPost, INPUT);
  pinMode(BPost, OUTPUT);
  digitalWrite(APost,HIGH);
  digitalWrite(CPost, HIGH);
  digitalWrite(BPost, LOW);
  
  radio.begin(); // Start the NRF24L01
  radio.openWritingPipe(pipe); // Get NRF24L01 ready to transmit
}

void loop()
{
  if (digitalRead(CPost) == LOW)    // If switch is pressed
  { 
      SentMessage[0] = 110;
      radio.write(SentMessage, 1);      // Send pressed data to NRF24L01
  }
  else if (digitalRead(APost) == LOW)
  {
    SentMessage[0] = 111;
    radio.write(SentMessage, 1);
  }
  else 
  {
      SentMessage[0] = 000;
      radio.write(SentMessage, 1);      // Send idle data to NRF24L01
  }
  delay(2);
}

You appear to have 3 posts defined in the picture and 3 posts on a breadboard each with one wire going to it. Where is the GND wire (since you appear, form the sketch, to be expecting the switches/posts? to be on the high side) ?
Maybe add a schematic.

Edit. OK. Post B is Output LOW so is, effectively ground. Use Serial.print statements to see what is happening in your sketch.

Edit 2

int SentMessage[1] = {000}; 
. . . 
radio.write(SentMessage, 1);      // Send idle data to NRF24L01 - Too small for an int

You can replace the following:

  pinMode(APost, INPUT);
  pinMode(CPost, INPUT);
  digitalWrite(APost,HIGH);
  digitalWrite(CPost, HIGH);

with:

  pinMode(APost, INPUT_PULLUP);
  pinMode(CPost, INPUT_PULLUP);

I think it is more readable and accomplishes the same. Also, instead of using an output just connect post B to GND.

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