This circuit is designed to control a yarn tension adjustment system. It utilizes an Arduino UNO microcontroller to interface with various components including an OLED display, pushbuttons, a load cell with an HX711 interface, and a motor driver to control two 12V geared motors. The system reads the tension from the load cell, displays the set and actual tension values on the OLED display, and allows the user to adjust the set tension using pushbuttons.
Arduino UNO
0.96" OLED
Pushbutton
Pushbutton
HX711 - Bridge Sensor Interface
Load Cell - Red/white/black/green
12V Geared Motor
12V Geared Motor
L298N DC Motor Driver
#include <Arduino.h>
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "HX711.h"
#include "L298N_MotorDriver.h"
// OLED display
Adafruit_SSD1306 DIS = Adafruit_SSD1306(128, 64, &Wire);
// Motor driver
L298N_MotorDriver motor(3, 2, 4);
// Load cell
const int LOADCELL_DOUT_PIN = 8;
const int LOADCELL_SCK_PIN = 7;
HX711 scale;
// Button pins
int sw1 = 5;
int sw2 = 6;
int sw3 = 9;
int sw4 = 10;
// Variables
boolean run = 1;
int set = 50;
int actual = 502;
long sensee;
int scl;
// Button handling
const int increaseButtonPin = 5; // Pin for the increase button
const int decreaseButtonPin = 6; // Pin for the decrease button
int setValue = 400; // Variable to store the set value
int lastIncreaseState = HIGH; // Last state of the increase button
int lastDecreaseState = HIGH; // Last state of the decrease button
void setup() {
// Pin modes
pinMode(13, OUTPUT);
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);
// Serial communication
Serial.begin(57600);
// Initialize load cell
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Initialize OLED display
DIS.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Initialize motor driver
motor.setDirection(true); // Sets the direction (depending on the wiring)
motor.enable();
}
void diss() {
DIS.clearDisplay();
DIS.setTextColor(WHITE);
DIS.setTextSize(1);
DIS.setCursor(7, 0);
DIS.print("YARN TENSION ADJST");
DIS.setTextSize(2);
DIS.setCursor(10, 22);
DIS.print("SET");
DIS.setTextSize(2);
DIS.setCursor(10, 45);
DIS.print("ACT");
DIS.setCursor(70, 22);
DIS.print(set);
DIS.setCursor(70, 45);
DIS.print(scl);
DIS.display();
DIS.dim(false);
}
void load() {
if (scale.is_ready()) {
long reading = scale.read();
sensee = reading / 100.0;
scl = map(sensee, 2853, 3300, 0, 1000);
} else {
Serial.println("HX711 not found.");
}
}
void loop()