Control an Arduino board from an Arduino!

Introduction

In this project, we’ll be looking at how to control an Arduino board with another Arduino board. To do this, we’re going to use a library called Software Serial, which will enable the two boards to communicate in a UART link. This library already exists in Arduino ide, so you don’t need to download anything download.

To control the first board, we’ll use the serial monitor. This will enable us to control the LED from the first Arduino board. This link will enable us to switch an LED on or off.

Difficulty:

Materials required

We will now list the hardware required for the project:

  • Arduino Uno board
  • Red LED
  • A 220 ohm resistor
  • 3 connecting wires

Schematic diagram

How does it work?

Two pins are used for UART communication between the two boards: TX and RX on the receiving Arduino board, and two digital pins on the sending board. We then use the two serial monitors on the two boards to manage communication between them.

Project program

With this program, to turn the LED on, simply add a 1 to the serial monitor, then 0 to turn it off:

Here’s the program:

#include "SoftwareSerial.h" // Library for communication between the two boards
SoftwareSerial serial1(2,3); //Initialization with the two pins of the emitter board

int input; // Variable the value entered in the serial monitor

void setup()
{
  Serial.begin(9600); // Initializing the serial monitor on the first Arduino board
  serial1.begin(9600); // Initializing the serial monitor on the second Arduino board
}

void loop() 
{
  while (Serial.available()>0){
    input = Serial.parseInt(); // Recovers what the user has written in the serial monitor
  if (input == 1){
    Serial.println('1');
    serial1.println('1');//We write 1 on the serial monitor and turn on the led
  }
  if (input == 0){
    Serial.println('0');
    serial1.println('0');//We write 0 on the serial monitor and turn off the LED.
  }
}

How to install the Software Serial library?

The Software Serial library is already included in Arduino Ide, so you won’t need to install it.

How to modify the program?

This program currently turns the LED on and off. However, you can adapt this program to your project by turning on a motor or other component.

To switch on a component, you can add whatever you like to the if field. You can also replace the 1 with something else, such as “On”:

  if (input == 1){
    Serial.println('1');
    serial1.println('1');//We write 1 on the serial monitor and turn on the led
  }

To switch off this component, you must do so in “input =0”. You can change the 0 to Off, for example:

 if (input == 0){
    Serial.println('0');
    serial1.println('0');//We write 0 on the serial monitor and turn off the LED.
  }

Project simulation

Here is the tinkercad simulation of the project: