I2C Between Arduinos With Potentiometer and LED: by Crockettcaleb

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

instructables

I2C Between Arduinos With Potentiometer and LED

by crockettcaleb

By Caleb Crockett and Logan Dykes

This circuit is designed to let one board communicate to another. This one is designed to send a value from one to
dim or brighten the other LED.

I2C Between Arduinos With Potentiometer and LED: Page 1


Step 1: Materials

You will need these items:

1) Breadboard

2) 2 Arduino Uno

3) One LED

4) Potentiometer

5) 220 Ohm resistor

6) Wires

Step 2: Connecting the Breadboards

Connect the two Arduinos with wires going from A4 to A4 and A5 to A5. And also connect the grounds to the
grounds. These are analog pins.

I2C Between Arduinos With Potentiometer and LED: Page 2


Step 3: Connect to LED

Place an Led on the bread board. Make sure you connect the anode to the ground and the cathode to the pin 11.
pin 11 has pulse width modulation and can disburse electricity with different pulses. Also. place a resistor between
the cathode and the pin 11.

Step 4: Arduino to Potentiometer

First, connect the left pin on the meter to ground and the right pin on the five volt power supply. Next, connect the
middle to pin A0.

I2C Between Arduinos With Potentiometer and LED: Page 3


Step 5: Code for the "Slave Reciever"

// Include the required Wire library for I2C void receiveEvent(int bytes) {
#include
x = Wire.read(); // read one character from the I2C
int LED = 11;
}
int x = 0;
void loop() {
void setup() {
//potentiometer value from sensor
// Define the LED pin as Output
int ledPWM = map(x, 0, 255, 0, 1023);
pinMode (LED, OUTPUT);
analogWrite(LED, ledPWM);
// Start the I2C Bus as Slave on address 9
Serial.print("X is: ");
Wire.begin(9);
Serial.println(x);
// Attach a function to trigger when something is
received. Serial.print("PWM is: ");

Wire.onReceive(receiveEvent); Serial.println(ledPWM);

//bit rate for data transfer over Serial communication delay(1000);

Serial.begin(9600); }

I2C Between Arduinos With Potentiometer and LED: Page 4


Step 6: Code for the "Master Sender"

// Chapter 7 - Communications Serial.begin(9600);


// I2C Master // By Cornel Amariei for Packt
Publishing }

// Include the required Wire library for I2C void loop() {

#include <wire.h> sensorValue = analogRead(sensorPin);

int x = 0; Serial.println(sensorValue);

int sensorPin = A0; Wire.beginTransmission(9);

int sensorValue = 0; // transmit to device #9

void setup() { Wire.write(sensorValue);

// Start the I2C Bus as Master delay(1000);

Wire.begin(); Wire.endTransmission();

// stop transmitting

Step 7: End Result

Now both of the Arduinos should be connected and ech should be hooked up with the LED and the other to the
potentiometer. Make sure you have the right code uploaded to each. The slave is the LED and the Master is the
meter.

I2C Between Arduinos With Potentiometer and LED: Page 5


I2C Between Arduinos With Potentiometer and LED: Page 6

You might also like