Sending digital signal from one ardunio board to another to detect button push?

Hello everyone,

I am new to ardunio programming and this forum and am having an issue sending a signal from one ardunio board to another. I have spent several hours looking online for the answer to this issue and have been unable to find anything. I am asking here in hopes that someone can help me out and I apologize in advance if this is a stupid question, keep in mind I am new to this

The project I am working on calls for sending a signal from one ardunio board to another via wiring as they will be separated by roughly 10 feet when finally installed. The setup calls for the ardunio to have 4 different buttons hooked up. 3 of these buttons will operate momentary on switches while the final button will be a constant on until released.

The master ardunio will need to be able to detect which of these buttons has been activated and send a signal through the corresponding wire to the slave ardunio to have it operate relays connected to several devices. I am wanting to do this by assigning a digital pin on the master ardunio as an OUTPUT which will then connect to a digital pin on the second ardunio that is set to an INPUT. When the second ardunio detects the signal from the master board it would then execute the assigned routine.

I have all physical equipment hooked up in a test space and everything seems to be working as far as the coding side of things goes but the issue I am having is that it seems as though the slave arduino thinks that the master ardunio is always sending it a HIGH signal even when the button is not pushed.

I have tested the place holding code and board for the master ardunio with a simple LED attached to a breadboard and everything works fine there. The LED does not light unless the push button is pressed then turns off as soon as the button is released so I don't think there is a problem there. The second board also executes its routine correctly with the exception that it thinks the button is always being pushed. During start up it turns on all the relays defined in the code as it should. There will eventually be 4 different routines for it to run according to what button has been pushed, but for now I decided to start with one and once it is working correctly to expand from there.

I have attached the code for both of these boards below. If anyone could help me I would greatly appreciate it, this is driving me crazy!

This is the code I have on the master board. Very basic.

   /* This should turn the led on pin 11 on if the button connected to pin 12 is pushed.
      Should also function to send a HIGH signal to second board when jumper is moved. */
  
  const int pushbutton = 12;
  const int tosecondarduino = 11;
  int buttonstate = 0;

void setup() {

  pinMode (pushbutton, INPUT);
  pinMode (tosecondarduino, OUTPUT);

}

void loop() {

  buttonstate = digitalRead(pushbutton);
  if (buttonstate == LOW) {
    digitalWrite (tosecondarduino, HIGH);}

    
  else {digitalWrite (tosecondarduino, LOW);}

}

Here is the code I have on the slave arduino.

Switching default definition of "buttonread" from "LOW" to "0" now keeps all relays from activating on start up but the board doesn't seem to detect the button push signal now.

/* Board outputs defined. */
const int redlight = 12;      // Red light next to door
const int greenlight = 11;    // Green light next to door
const int buzzer = 10;        // Dryer Buzzer in wall
const int doorlock = 9;       // Electric door lock in wall

/* Board inputs defined. */
const int redbuttonin = 2;        // Jumper wire coming from room control box to pin
const int greenbuttonin = 3;      // Jumper wire coming from room control box to pin
const int lightsbuttonin = 4;     // Jumper wire coming from room control box to pin
const int emergencybuttonin = 5;  // Jumper wire coming from room control box to pin

/* Digital variables defined. (Not physical parts) */

int buttonread = 0;

void setup() {

  pinMode (redlight, OUTPUT);
  pinMode (greenlight, OUTPUT);
  pinMode (buzzer, OUTPUT);
  pinMode (doorlock, OUTPUT);

  pinMode (redbuttonin, INPUT);
  pinMode (greenbuttonin, INPUT);
  pinMode (lightsbuttonin, INPUT);
  pinMode (emergencybuttonin, INPUT);

}

void loop() {

  // Checks to see if RED BUTTON on room control panel has been pushed.
  buttonread = digitalRead (greenbuttonin);
  if (buttonread == HIGH) {
    digitalWrite (redlight, HIGH);      // Red light stays off.
    digitalWrite (greenlight, LOW);     // Green light comes on.
    digitalWrite (doorlock, LOW);       // Door lock retracts. (Door unlocked).
    digitalWrite (buzzer, LOW);         // Buzzer starts sounding.
    delay (2000);                       // Buzzer sounds for 2 seconds.
    digitalWrite (buzzer, HIGH);        // Buzzer stops sounding.
  }

}

Hi,
Does the master arduino do anything else apart from monitor the switches?

If that is all its doing, use one arduino and 10feet of shielded multi-core cable and connect it the switches.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Do you have the gnd of both arduino connected together?

Tom.... :slight_smile:

Hi,

Thank you for responding! I do have a jumper wire going between the boards to a ground on each of them. I’m not sure if it is correct, but I think so.

I don’t have access to a CAD program but I did the best I could with Photoshop. I hope it is clear enough and legible. Let me know if you need anything else, and thank you for your help!

T.J.

Oh, and the master arduino will be responsible for a lot of other things from its location or I would just run wiring. Thank you for the suggestion though!

Hi,
Thanks for diagram BUT how have you got your button wired?
I assume you are only showing one button as an example to get the principle working.

Does the output of the master go HIGH and LOW with the button press?

A hand drawn picture of your project would have been fine.

Tom.... :slight_smile:

Hi,
In your master code, pressing the button pulls the input LOW, do you have a 10k resistor from the input pin to +5V.
This will pull the input HIGH when the button is off.
Or activate PULL-UP on that pin.
https://www.arduino.cc/en/Reference/pinMode

Do you have a DMM?

Tom... :slight_smile:

Yes, the other buttons are not hooked up yet until I get this one working.

I have a 330 ohm resistor hooked up.

Also, I have power adapters hooked up to both of the boards. Would that make a difference?

I’ve attached another picture of the switch wiring. Just trying to make things as easy as I can for you since you are taking time out of your day to help me!

Hi,
You only need 1K to 10K.
Can you measure the output of the master going HIGH and LOW when you press the button?

Two power adapters will not be a problem.

Tom… :slight_smile:

Just checked it with a dmm by placing the ground lead in the last open ground pin on the board and pulling the #12 pin that went to the "pushbutton" input. It is reading dead on 5v when button is pushed but still reading around 4.6v when the button is not pushed. Did I measure that at the proper points?

Would I need to connect a power lead from the master board to the slave board somehow too or is just the ground important since I have it plugged into a wall adapter for power?

Hi,
Yes, between gnd and pin12 on the master.

No your 330R is too low in value, you need to fit 10k resistor.

What is your button?
Can you post a link?
Is it like this?

Can you measure the resistance across the button with button pressed and not pressed, this is with nothing else connected the the button.

Thank you so much! You hit the nail right on the head, my resistor was the problem the entire time! Replaced it and the boards are now reading the button pushes and working perfectly and each is running its programs as they should!

Now I just have to figure out how to code so that the program will stop and stay at an "if statement" once it runs it until another button is pushed, but that's all software!

I REALLY appreciate your help with this! Is there a way for me to give you credit or something on here for everything you have done?

Hi,
Good to hear.

You will need to look for change of state of the button, not when it is LOW.

You will need to look for the input going from HIGH to LOW, then change the output from LOW to HIGH or HIGH to LOW.

Tom.. :slight_smile:

Thanks for the tip and all your other help! Is there anything I can do to repay you for your time on here? I don't want to keep tying up the rest of your night!

Hi,
No worries mate, its lunchtime. afternoon on a Sunday.. Pet sitting.

Tom... :slight_smile: