Chandran N
Published © GPL3+

Transferring Data From One Arduino to Another

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

BeginnerProtip30 minutes52,951
Transferring Data From One Arduino to Another

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
LED (generic)
LED (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connections

Code

Code uploaded on master and slave boards

Arduino
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);
  }
}

Credits

Chandran N

Chandran N

5 projects • 22 followers
I am a student at NITK Surathkal pursuing Mechanical Engineering.I am interested in Robotics,Arduino,IoT,Automobiles and Astronomy.

Comments