load cell and servo arduino nano

Thread Starter

hanzzz

Joined Apr 9, 2023
1
hello guys, im a student. i want to complete my project, but im not a programmers. so guys i need your help. so the study case is, i have 2 sensor (ultrasonic and loadcell), if the ultrasonic sensor detected distance what i want it can move the servo, but must have a certain weight setting. but I can't figure out how to set a weight (let's say 500 grams). then if the weight meets the servo can move. umm, I've made the code but it's still error, can you guys help me....

C-like:
#include <LiquidCrystal_I2C.h>

#include "HX711.h"

#include <Servo.h>

#define DOUT 2

#define CLK 4

#define calibration_factor 433.00

#define Trigpin 16

#define Echopin 15


HX711 scale;

LiquidCrystal_I2C lcd(0x27, 16, 2);

int GRAM;

long duration,distance;

Servo servomuter;


void setup () {

  lcd.begin(16,2);

  lcd.init();

  lcd.backlight();

  lcd.setCursor(4,0);

  lcd.print("ilham kocak");

  lcd.setCursor(5,1);

  lcd.print("kontol");

  delay(2000);

  lcd.clear();


  scale.begin(DOUT,CLK);

  scale.set_scale(calibration_factor);

  scale.tare();

 

  pinMode(Trigpin,OUTPUT);

  pinMode(Echopin,INPUT);

  servomuter.attach(11);

  Serial.begin(9600);

  servomuter.write(0);


}


void loop() {

  lcd.setCursor(0,0);

  lcd.print("Silahkan Timbang");

  lcd.setCursor(0,1);

  lcd.print(scale.get_units(2), 0);

  lcd.print(" gram");

  lcd.print("          ");

 

  digitalWrite(Trigpin,LOW);

  delayMicroseconds(2);

  digitalWrite(Trigpin,HIGH);

  delayMicroseconds(10);

  digitalWrite(Trigpin,LOW);

  duration=pulseIn(Echopin,HIGH);

  distance=duration/58.2;


  if(distance<10 && distance>0)

  {

    Serial.println(distance);

    servomuter.write(180);

    delay(1000);

  }

  else

  {

    servomuter.write(90);

    delay(1000);

  }

}
 
Last edited by a moderator:
Top