Connect Two Arduinos Using I2C Communication
by RonFrtek in Circuits > Arduino
577 Views, 1 Favorites, 0 Comments
Connect Two Arduinos Using I2C Communication
In this tutorial we will learn how to connect Two Arduino boards using I2C Communication by connecting a DHT11 Temperature sensor to the Slave Arduino and send it over the I2C to the Master Arduino and Display the Temperature value on the OLED Display.
This project serves as an example what can be done, you are free to send any data that you want.
What You Will Need
- 2X Arduino UNO (or any other Arduino)
- DHT11 Temperature & Humidity sensor
- OLED I2C Display
- Breadboard
- Jumper wires
- Visuino program: Download Visuino
The Circuit
- Connect OLED Display pin [SDA] to Arduino1-Master pin [SDA]
- Connect OLED Display pin [VCC] to Arduino1-Master pin [5v]
- Connect OLED Display pin [GND] to Arduino1-Master pin [GND]
- Connect DHT11 Sensor pin [VCC] to Arduino2-Slave pin [5v]
- Connect DHT11 Sensor pin [GND] to Arduino2-Slave pin [GND]
- Connect DHT11 Sensor pin [S] to Arduino2-Slave Digital pin [2]
- Connect Arduino1-Master pin [SDA] to Arduino2-Slave pin [SDA]
- Connect OLED Display pin [SCL] to Arduino1-Master pin [SCL]
- Connect Arduino1-Master pin [SCL] to Arduino2-Slave pin [SCL]
Start Visuino, and Select the Arduino UNO Board Type
The Visuino: https://www.visuino.eu also needs to be installed. Download Free version or register for a Free Trial.
Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2
For Master Arduino - in Visuino Add, Set & Connect Components
First Click on the Arduino Board and in the properties select "I2C Channels > I2C " and set "Address" to 20 (See Picture1)
- Add "OLED" component (See Picture2)
- Add "Split Structure" component (See Picture3)
- Add "I2C Device" component (See Picture4)
- Add "Clock Generator" component (See Picture5)
- Double Click on the "SplitStructure1" and in the "Elements" Window drag "Analog" to the left side (See Picture6)
- Close the "Elements" window
- Select "I2CDevice1" and in the properties window set "Address" to 20 (See Picture7)
- Double click on the "I2CDevice1" and in the "Operations" window drag "Request" to the left side (See Picture8)
In the Properties window set Size to 4 (See Picture9) - Close the "Operations" window
- Double Click on the "DisplayOLED1" and in the "Elements" Window
- drag "Draw Text" to the left side (See Picture10)
- In the Properties window set size to 2 and Text to TEMP (See Picture11)
- drag "Text Field" to the left side (See Picture10)
- In the Properties window set size to 3 and Y to 30 (See Picture12)
- Close the "Elements" window
- Connect "ClockGenerator1" pin [Out] to "I2CDevice1 Request1" Pin [Clock]
- Connect "I2CDevice1 Request1" Pin [Out] to "SplitStructure1" pin [In]
- Connect "I2CDevice1" I2C Pin [Out] to "Arduino board" I2C pin [In]
- Connect "SplitStructure1" Analog1 pin [Out] to "DisplayOLED1" Text Feld1 pin [In]
- Connect "DisplayOLED1" I2C Pin [Out] to "Arduino board" I2C pin [In]
Upload the Project to the Arduino Board (see the Generate, Compile, and Upload the Arduino Code step)
For Slave Arduino - in Visuino Add, Set & Connect Components
First Click on the Arduino Board and in the properties select "I2C Channels > I2C " and set "Address" to 20 and set "Is Slave" to True (See Picture1)
- Add "DHT11" component (See Picture2)
- Add "Make Structure" component (See Picture3)
- Double Click on the "MakeStructure1" and in the "Elements" Window drag "Analog" to the left side (See Picture4)
- Close the "Elements" window
- Connect "HumidityThermometer1" pin [Temperature] to "MakeStructure1 Analog1" Pin [In]
- Connect "HumidityThermometer1" pin [Sensor] to Arduino board Digital pin [2]
- Connect Arduino board I2C pin [Request] to "MakeStructure1" pin [Clock]
- Connect "MakeStructure1" pin [Out] to Arduino board I2C pin [In]
Upload the Project to the Arduino Board (see the Generate, Compile, and Upload the Arduino Code step)
Generate, Compile, and Upload the Arduino Code
In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.
Play
If you power the Arduino modules, the OLED Display connected to the Master Arduino will start to show the Temperature values from the DHT11 sensor that is connected on the Slave Arduino.
Congratulations! You have completed your project with Visuino. Also attached are the Visuino project files for Master and Slave, that I created for this Tutorial, you can download it and open it in Visuino: https://www.visuino.eu