Transferring Data From One Arduino to Another

Transferring Data From One Arduino to Another © GPL3+

A simple project, involving transferring value of a sensor, which is connected from one Arduino to another, and getting a required result.

  • 5,479 views
  • 10 comments
  • 38 respects

Components and supplies

Apps and online services

About this project

The objective of this project is simple: to understand how to transfer data from one Arduino board to another. In this case, the value to be transferred is coming from a potentiometer connected to the first Arduino board. If the value crosses a certain threshold, I will make the LED connected to the second Arduino board light up.

How to transfer values from one Arduino board to another?

There are many different protocols which can be implemented to achieve the above mentioned objective.Here I am going to use the I2C protocol with master writer/slave receiver configuration.

What is I2C protocol?

Simply put, in I2C communication protocol, you have two devices, a master and a slave, which are interconnected by two lines, a data line and a clock line.In Arduino Uno, the data line is Analog pin 4(A4) and clock line is Analog pin 5(A5). This however is different for different for different boards.

When the clock pin goes from low to high, one bit of data is transferred via the data pin.The slave board may then either send back data via the same data pin or perform a task(as in our case). The first eight bits, however, are reserved for the address of the slave Arduino board to which the master sends values.

How does the project work and what does it do?

I use analog read in the master Arduino board, to get the value of a potentiometer connected to it. Then this value is transferred to the slave Arduino Board and if it is above a threshold, the LED connected to the slave Arduino lights up.

Connections

Refer to the uploaded Fritzing file for connections.

The two boards must have a common ground so connect the grounds from both the boards together.

Result

Conclusion

There are many applications for I2C communication especially in the field of IoT (Internet of Things). Apart from that, this can also be used if one is running out of pins for a particular project and has multiple boards.

Code

Code uploaded on master and slave boardsArduino
There are 2 programs below-one for the Master board and second for the Slave board
//Code for the Master board
#include<Wire.h>//This library is used for I2C communication
int x;
void setup() {
  Wire.begin(); 
  Serial.begin(9600);
}
void loop() {
  x = analogRead(A0);//Reading value from Potentiometer
  x/=4;
  Wire.beginTransmission(9);//9 here is the address of the slave board 
  Wire.write(x);//Transfers the value of potentiometer to the slave board            
  Wire.endTransmission(); 
  Serial.print(x);
  delay(1000);
}

//Code for the slave board
#include<Wire.h
int x;
void setup() {
  pinMode (13, OUTPUT);//Connect LED to pin 13
  Wire.begin(9);//9 here is the address(Mentioned even in the master board code) 
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}
void receiveEvent(int bytes) {
  x = Wire.read();//Receive value from master board
  Serial.print(x);
}
void loop() {
  if (x > 88) {//I took the threshold as 88,you can change it to whatever you want
    digitalWrite(13, HIGH);
    delay(200);
  }
  else{
    digitalWrite(13, LOW);
    delay(400);
  }
}

Schematics

Connections
i2c_hIhBrkJQDO.fzz

Comments

Similar projects you might like

Temperature and Humidity Data Logger

Project tutorial by Wimpie van den Berg

  • 27,750 views
  • 2 comments
  • 25 respects

Export Data from Arduino to Excel Sheet

Project showcase by ahmed ismail

  • 19,428 views
  • 1 comment
  • 11 respects

Wireless Magnetic Data Transfer

Project tutorial by Tomi Chen

  • 5,599 views
  • 4 comments
  • 23 respects

Arduino & Python3 Temperature Data Visualizer

Project tutorial by reyadeetopee

  • 4,174 views
  • 2 comments
  • 26 respects

20bps Digital Data Wireless Transceiver (Laser)

Project tutorial by Achindra Bhatnagar

  • 2,025 views
  • 1 comment
  • 9 respects
Add projectSign up / Login