#include // Include the Wire library for I2C communication int potPin = D2; // Define the analog pin connected to the potentiometer int potVal; // Variable to store the potentiometer value void setup() { Serial.begin(9600); // Initialize serial communication at 9600 baud rate Wire.begin(9); // Initialize I2C communication as slave with address 9 Wire.onRequest(sendData); // Define the function to be called when data is requested } void loop() { potVal = analogRead(potPin); // Read the analog value from the potentiometer delay(500); // Adjust delay as needed } void sendData() { int servoVal = map(potVal, 0, 1023, 0, 180); // Map potentiometer value to servo range (0-180) Serial.println(servoVal); // Print servo value to serial monitor Wire.write(servoVal); // Send servo value to the master device over I2C }