0% found this document useful (0 votes)
5 views6 pages

Arduino Uno Code

This Arduino UNO code controls a powder filling machine using an HX711 load cell, a servo motor, and an LCD display. It initializes the components, reads weight data, and allows for setting target weights of 50g and 100g based on button inputs. The system also supports tare operations via serial commands and displays the actual weight on the LCD.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Arduino Uno Code

This Arduino UNO code controls a powder filling machine using an HX711 load cell, a servo motor, and an LCD display. It initializes the components, reads weight data, and allows for setting target weights of 50g and 100g based on button inputs. The system also supports tare operations via serial commands and displays the actual weight on the LCD.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ARDUINO UNO CODE:

#include <HX711_ADC.h>

#include <LiquidCrystal_I2C.h>

#include <Servo.h>

#if defined(ESP8266)|| defined(ESP32) || defined(AVR)

#include <EEPROM.h>

#endif

LiquidCrystal_I2C lcd(0x27 ,20,4);

//pins:

const int HX711_dout = 6; //mcu > HX711 dout pin

const int HX711_sck = 7; //mcu > HX711 sck pin

//HX711 constructor:

HX711_ADC LoadCell(HX711_dout, HX711_sck);

Servo power;

const int calVal_eepromAdress = 0;

unsigned long t = 0;

int st=0,st1=0;

float tar1=50 ,tar2=99.5,tar=0;

void setup() {

[Link](9600); delay(10);

[Link]();
[Link]("Starting...");

pinMode(2,INPUT);

pinMode(4,INPUT);

pinMode(5,INPUT);

pinMode(12,OUTPUT);

digitalWrite(12,HIGH);

[Link](9);

[Link](0);

delay(1000);

//[Link](98);

[Link]();

[Link]();

[Link](); // Make sure backlight is on

// Print a message on both lines of the LCD.

[Link](2,0); //Set cursor to character 2 on line 0

[Link](" POWDER");

[Link](2,1); //Move cursor to character 2 on line 1

[Link](" Filling Machine");

delay(1000);

[Link]();

//[Link](); //uncomment to turn a negative output value to positive

float calibrationValue; // calibration value (see example file "[Link]")


calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the
sketch

#if defined(ESP8266)|| defined(ESP32)

//[Link](512); // uncomment this if you use ESP8266/ESP32 and want to fetch the
calibration value from eeprom

#endif

//[Link](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

[Link](stabilizingtime, _tare);

if ([Link]()) {

[Link]("Timeout, check MCU>HX711 wiring and pin designations");

while (1);

else {

[Link](calibrationValue); // set calibration value (float)

[Link]("Startup is complete");

void loop()

if(st1==0)

st=0;

do
{

if(digitalRead(4)==HIGH)

st=1;

if(digitalRead(5)==HIGH)

st=2;

}while(st==0);

st1=1;

if(st==1)

tar=tar1;

[Link]();

[Link](0,0); //Set cursor to character 2 on line 0

[Link]("TARGET WEIGHT: 50g");

if(st==2)

tar=tar2;

[Link]();

[Link](0,0); //Set cursor to character 2 on line 0

[Link]("TARGET WEIGHT: 100g");

}
delay(1000);

do

delay(1);

}while(digitalRead(2)==LOW);

[Link](0);

digitalWrite(12,LOW);

static boolean newDataReady = 0;

const int serialPrintInterval = 0; //increase value to slow down serial print activity

// check for new data/start next conversion:

if ([Link]()) newDataReady = true;

// get smoothed value from the dataset:

if (newDataReady)

if (millis() > t + serialPrintInterval) {

float i = [Link]();

[Link]("Load_cell output val: ");

[Link](i);

//[Link]();

[Link](0,1);

[Link]("ACTUAL WEIGHT: ");

[Link](i);

[Link](" g");
if(i>=tar)

[Link](98);

digitalWrite(12,HIGH);

st1=0;

newDataReady = 0;

t = millis();

// receive command from serial terminal, send 't' to initiate tare operation:

if ([Link]() > 0) {

char inByte = [Link]();

if (inByte == 't') [Link]();

// check if last tare operation is complete:

if ([Link]() == true) {

[Link]("Tare complete");

COMPONENTS PRICE

You might also like