Categories
TUTORIALS

Connecting Two Arduino Unos To Communicate With Each Other

In this tutorial, I will cover programming one Arduino board to act as a “controller” and send a signal to another board, triggering the second Arduino to respond by changing the color of the RGB light.

This project is a helpful overview of how inputs on one board can trigger outputs on other boards. Communication between two boards can be a helpful tool to create more complex systems of sensors.

For this tutorial, you will need:

  • 2 Arduino Uno boards
  • 1 Soderless Breadboard
  • 9 Wires, of both short and long lengths
  • 3 330 Ohm Resistors
  • 1 RGB LED Light
  • 2 9V Batteries with 2 Snap-on connectors for DC power plug

The wiring of the board setup should look as such:

The breadboard diagram for this setup is seen here:

I decided to use an RGB LED so that I could program the “controller” board to tell the “controlled” board to display different colors based on different inputs. This is a good first step for the larger project for which this system is ultimately intended.

Above, the board on the left is the “controller” board. Through Analog pins A4 and A5, the two boards are communicating by sending a character from one to the other. The board on the right – the “controlled” board – interprets the signal it receives and writes an output to a different combination of the RGB pins to create different color combinations. This can be easily adjusted so that based on the communication between the boards, the output can be changed based on the project needs. The “controller” board can also be enhanced so that based on a different input to that board such as a motion or light sensor, the output would be the communication to the “controlled” board. An expansion of this setup of the sort just described will be pursued in further experiments.

The sketches for these two boards – each board requires its own code uploaded to it – are relatively straight forward.

For the “controller” board, the code is below:

The code as such creates the system of sending signals to the “controlled” board. First we have to include a Wire library, which establishes the functions needed for inter-board communication. We then initiate the board to act as the controller, and have the “controller” board send signals to the “controlled” board that increment up one at a time to a maximum of 6, at which point it starts at 0 again, sending signals every half a second. As we move to the “controlled” board, these incremental changes in value will be the controlling values that dictate the color of the RGB light.

For the “controlled” board, the code is below:

This code establishes this board as the “controlled” board. The code uses the function receiveEvent to read the communication from the “controller” board. This communication is a character from 0 to 6. In the loop, the values are then translated to a different RGB color. This loop function can be altered to have different events based on the character transmitted. The light is programmed to turn on for two seconds and then off for two seconds currently, but could be altered in other uses.

This simple communication between boards can allow for more complicated systems to be created. You can see the system as outlined in this tutorial in a video here:

https://www.youtube.com/watch?v=z8wcKhiGUT0&feature=youtu.be

Leave a Reply

Your email address will not be published. Required fields are marked *