Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Tribometer with Load Cell Feedback and Motorized Rotary Encoder

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Tribometer with Load Cell Feedback and Motorized Rotary Encoder

Circuit Documentation

Summary

This circuit is designed to control a DC motor using an Arduino UNO microcontroller and an L298N DC motor driver. It also includes a rotary encoder for position feedback and a load cell with an HX711 amplifier for force measurement. The Arduino UNO reads the encoder and load cell data to monitor the position and force applied to the motor. The motor's speed and direction are controlled by the Arduino through the L298N driver.

Component List

Arduino UNO

L298N DC Motor Driver

DC Motor

Rotary Encoder

Load Cell - Red/white/black/green

SparkFun Load Cell Amplifier - HX711

Wiring Details

Arduino UNO

L298N DC Motor Driver

DC Motor

Rotary Encoder

Load Cell - Red/white/black/green

SparkFun Load Cell Amplifier - HX711

Documented Code

#include "HX711.h"

// Define motor control pins
#define motorIn1 8
#define motorIn2 9
#define motorEN 10

// Define encoder pins
#define encoderA 2
#define encoderB 3

// HX711 Pins
#define HX711_DOUT A0
#define HX711_SCK A1

HX711 scale;

long position = 0;
float force = 0;
int lastStateA = LOW;  // To track encoder state

void setup() {
  // Motor pins
  pinMode(motorIn1, OUTPUT);
  pinMode(motorIn2, OUTPUT);
  pinMode(motorEN, OUTPUT);

  // Encoder pins
  pinMode(encoderA, INPUT);
  pinMode(encoderB, INPUT);

  // Initialize serial communication for debugging
  Serial.begin(9600);

  // Initialize HX711 scale
  scale.begin(HX711_DOUT, HX711_SCK);
  scale.set_scale();  // Calibration needed here (You can add a known weight for calibration)
  scale.tare();  // Set scale to zero

  // Print initial message
  Serial.println("Pin-on-Disk Tribometer Initialized");

  // Get a baseline (zero) for the load cell
  long zero_factor = scale.read_average();  // You can store this value for tare later if needed
}

void loop() {
  // Motor Control: Move disk
  digitalWrite(motorIn1, HIGH);  // Set motor direction
  digitalWrite(motorIn2, LOW);
  analogWrite(motorEN, 200);     // Set motor speed (PWM value from 0-255)

  // Read Encoder Values
  int stateA = digitalRead(encoderA);  // Read the state of the encoder's channel A
  int stateB = digitalRead(encoderB);  // Read the state of the encoder's channel B

  // Detect direction of rotation using both channels
  if (stateA != lastStateA) {
    if (stateB != stateA) {
      position++;  // Forward rotation
    } else {
      position--;  // Reverse rotation
    }
  }
  lastStateA = stateA;  // Update the last known state of encoderA

  // Read Load Cell (Force Measurement)
  if (scale.is_ready()) {
    force = scale.get_units();  // Get the calibrated weight or force value
    Serial.print("Force (in units): ");
    Serial.println(force);  // Print force data to the Serial Monitor
  } else {
    Serial.println("HX711 not ready");  // Error message if HX711 is not responding
  }

  // Print Encoder Position (Rotation data)
  Serial.print("Encoder Position: ");
  Serial.println(position);

  delay(100);  // Small delay to allow easier reading of values
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the motor control pins, encoder pins, and the HX711 load cell amplifier. In the loop function, it controls the motor, reads the encoder position, measures the force using the load cell, and outputs the data to the serial monitor. Calibration of the HX711 is required for accurate force measurements.