Load Cell to control Actuator movement

I am confused on why i get an are at pinmode asking for a constructor.
The code should read the load cell for mass, once mass has been removed, the actuator should extend.

#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif

//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin
const int A1B = 10;
const int A1A = 11;
pinMode(HX711_dout, INPUT);
pinMode( HX711_sck, INPUT);
pinMode(A1A, OUTPUT);
pinMode(A1B, OUTPUT);
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);

const int calVal_eepromAdress = 0;
unsigned long t = 0;
float i
void setup() {
Serial.begin(57600); delay(10);
Serial.println();
Serial.println("Starting...");

LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
//EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom

unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Startup is complete");
}
}

void scale()
{
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity

// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;

// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
}
}

// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}

// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}

}

void loop ()
{
if (i < 8.00)
{ analogWrite(A1B, 0);
analogWrite(A1A, 255);
}
else if (i >= 8.01)
{
scale();
analogWrite(A1B, 0);
analogWrite(A1A, 0);
}
}

use code tags </> when uploading code - it makes it easy read
upload the error complete messages?
upload a schematic of the circuit?


#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif

unsigned long t = 0;
float calibrationValue = 431;
float i = 0.0;
//pins:
const int HX711_dout = 2; //mcu > HX711 dout pin
const int HX711_sck = 3; //mcu > HX711 sck pin
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int A1B = 11;
const int A1A = 10;


void setup() {
  Serial.begin(57600); delay(10);
  pinMode(HX711_dout, INPUT);
  pinMode( HX711_sck, INPUT);
  pinMode(A1B, OUTPUT);
  pinMode(A1A, OUTPUT);

  Serial.println();
  Serial.println("Starting...");


  LoadCell.begin();
  //LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
  float calibrationValue; // calibration value (see example file "Calibration.ino")
  calibrationValue = -431.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
  //EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
  //EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom

  unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
  boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
  LoadCell.start(stabilizingtime, _tare);
  if (LoadCell.getTareTimeoutFlag()) {
    Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
    while (1);
  }
  else {
    LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
    Serial.println("Startup is complete");
  }
}

void scale()
{
  static boolean newDataReady = 0;
  const int serialPrintInterval = 0; //increase value to slow down serial print activity

  // check for new data/start next conversion:
  if (LoadCell.update()) newDataReady = true;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      i = LoadCell.getData();
      Serial.print("Load_cell output val: ");
      Serial.println(i);
      newDataReady = 0;
      t = millis();
    }
  }

  // receive command from serial terminal, send 't' to initiate tare operation:
  if (Serial.available() > 0) {
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

}
void loop ()
{
  if (i > 43.00)
  { scale();
    analogWrite(A1B, 0);
    analogWrite(A1A, 0);
  }
  else if (i <= 40.00)
  {
    scale();
    analogWrite(A1B, 50);
    analogWrite(A1A, 0);
  }
}


no longer getting the erro message. program runs, now i having an issue with it completing the task i need. continuously reading the scale and activating when weight is removed

can you upload the Serial Monitor output indicating where you think it is going wrong?
what happens if i > 40 or <= 43? scale() is not called

right now, the scale is reading in negatives for some reason and yes. i believe it is going wrong as it is reading for both motor functions.

put in Serial.println() statements during the program so you can trace program flow and results at each stage
then upload the serial monitor output
edit: there is this statement in setup()

  //LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive

what happens if you uncomment it?

//Library inclusions
#include <HX711_ADC.h>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif


unsigned long t = 0;
float calibrationValue = 431;// calibration offset
float i = 0.0;

const int HX711_dout = 2; //mcu > HX711 dout pin
const int HX711_sck = 3; //mcu > HX711 sck pin
HX711_ADC LoadCell(HX711_dout, HX711_sck);//Defined from HX711 library
const int switch_pin = 4;
int Act_Push = 10;
int Act_Pull = 11;
int switch_pin_n = 5;

void setup() {
  Serial.begin(57600); delay(10);
  pinMode(switch_pin, INPUT);
  pinMode(switch_pin_n, INPUT);
  pinMode(Act_Push, OUTPUT);
  pinMode(Act_Pull, OUTPUT);
  digitalWrite(Act_Push, LOW);
  digitalWrite(Act_Pull, LOW);

  Serial.println();
  Serial.println("Starting...");

  //Program begins and LoadCell begins reading output

  LoadCell.begin();
  //LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
  float calibrationValue; // calibration value (see example file "Calibration.ino")
  calibrationValue = 431.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
  //EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
  //EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom

  unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
  boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
  LoadCell.start(stabilizingtime, _tare);
  if (LoadCell.getTareTimeoutFlag()) {
    Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
    while (1);
  }
  else {
    LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
    Serial.println("Startup is complete");
  }
}
//Able to run scale function continuously inside the loop function
void scale()
{
  static boolean newDataReady = 0;
  const int serialPrintInterval = 0; //increase value to slow down serial print activity

  // check for new data/start next conversion:
  if (LoadCell.update()) newDataReady = true;

  // get smoothed value from the dataset:
  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      i = LoadCell.getData();
      Serial.print("Load_cell output val: ");
      Serial.println(i);
      newDataReady = 0;
      t = millis();
    }
  }

  // receive command from serial terminal, send 't' to initiate tare operation:
  if (Serial.available() > 0) {
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  // check if last tare operation is complete:
  if (LoadCell.getTareStatus() == true) {
    Serial.println("Tare complete");
  }

}
void loop() {
  scale();
  //Seat is occupied
  if ( i >= 40) {
    digitalWrite(Act_Push, LOW);
    digitalWrite(Act_Pull, LOW);
  }
  //Seat occupied with manual control (Extend)
  if (digitalRead(switch_pin) == LOW && i >= 40) {
    digitalWrite(Act_Push, LOW);
    digitalWrite(Act_Pull, HIGH);
  }
  //Seat is empty, Actuator Retracts
  if ( i < 40) {
    digitalWrite(Act_Push, LOW);
    digitalWrite(Act_Pull, HIGH);
  }
  //Seat occupied with manual control (Retract)
  if (digitalRead(switch_pin) == HIGH && i >= 40) {
    digitalWrite(Act_Push, HIGH);
    digitalWrite(Act_Pull, LOW);
  }
  // Seat occupied with manual cruise control
 if (digitalRead(switch_pin_n) == HIGH && i >= 40) {
   digitalWrite(Act_Push, LOW);
    digitalWrite(Act_Pull, LOW);
 }
}

this is a new code that does what i want except the middle pin of my 3 position toggle switch does not hold the actuator in place.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.