proprietor
Published

Automated powder dispenser

This project takes input with pot and gives that amount of powder.

BeginnerShowcase (no instructions)1,479
Automated powder dispenser

Things used in this project

Hardware components

ElectroPeak Loadcell Sensor
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
TM1637 4-bits digital LED-display
×1
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SparkFun Load Cell Amplifier - HX711
SparkFun Load Cell Amplifier - HX711
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Arduino Due
Arduino Due
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

final code.ino

Arduino
#include <Q2HX711.h>
#include <TM1637.h>
#include <Servo.h>

#define POTENTIOMETER_PIN A5 // potentiometer port
Servo servo;
int CLK = 11;
int DIO = 10;
float weight = 0.00;

TM1637 tm(CLK, DIO);
int firstdigit = 0;
int seconddigit = 0;
int thirddigit = 0;
int fourthdigit = 0;

const byte hx711_data_pin = 4;
const byte hx711_clock_pin = 5;
const int buttonPin = 2;     // the number of the pushbutton pin

float y1 = 145.28; // calibrated mass to be added
long x1 = 0L;
long x0 = 0L;
float avg_size = 10.0; // amount of averages for each mass measurement
int buttonState = 0;         // variable for reading the pushbutton status


Q2HX711 hx711(hx711_data_pin, hx711_clock_pin); // prep hx711

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  servo.attach(8);
  tm.init();

  //set brightness; 0-7
  tm.set(3);
  Serial.begin(9600); // prepare serial port
  delay(1000); // allow load cell and hx711 to settle
  x0 = 8363340; // rate for scale
  x1 = 8545139; // rate for scale
}

void loop() {
  servo.write(0);
  while(digitalRead(buttonPin) == HIGH){
    delay(20);
  }
  long reading = 0;
  for (int jj = 0; jj < int(avg_size); jj++) {
    reading += hx711.read();
  }
  reading /= long(avg_size);
  // calculating mass based on calibration and linear fit
  float ratio_1 = (float) (reading - x0);
  float ratio_2 = (float) (x1 - x0);
  float ratio = ratio_1 / ratio_2;
  float tare2 = y1 * ratio;
  tm.display(3, 0);
  tm.display(2, 0);
  tm.display(1, 0);
  tm.display(0, 0);


  delay(100); // little bit time for board to rest
  while (digitalRead(buttonPin) == HIGH) {
    int data = analogRead(POTENTIOMETER_PIN); // read pot
    firstdigit = map (data, 0, 1023, 0, 9); // convert to 1 digit
    tm.display(3, firstdigit); // print digit in lcd
  }
  delay(200); // little bit time for board to rest

  while (digitalRead(buttonPin) == HIGH) {
    int data = analogRead(POTENTIOMETER_PIN);  // read pot
    seconddigit = map(data, 0, 1023, 0, 9); // convert to 1 digit
    tm.display(2, seconddigit); // print digit in lcd
  }
  delay(500); // little bit time for board to rest
  while ( digitalRead(buttonPin) == HIGH) {
    int data = analogRead(POTENTIOMETER_PIN);  // read pot
    thirddigit = map(data, 0, 1023, 0, 9); // convert to 1 digit
    tm.display(1, thirddigit); // print digit in lcd
  }
  delay(500);
  while (digitalRead(buttonPin) == HIGH) {
    int data = analogRead(POTENTIOMETER_PIN); // read pot
    fourthdigit = map(data, 0, 1023, 0, 9); // convert to 1 digitgit);
    tm.display(0, fourthdigit); // print digit in lcd
    delay(100); // little bit time for board to rest
  }
  float weight  = firstdigit * 0.1 + seconddigit + thirddigit * 10 + fourthdigit * 100 ; // the data is in the while loop so program cant read it out of the loop
  // averaging reading
  
  for (int jj = 0; jj < int(avg_size); jj++) {
    reading += hx711.read();
  }
  reading /= long(avg_size);
  // calculating mass based on calibration and linear fit
  ratio_1 = (float) (reading - x0);
  ratio_2 = (float) (x1 - x0);
  ratio = ratio_1 / ratio_2;
  float mass = y1 * ratio;
  float taredmass = mass - tare2;

  float r = round(taredmass * 10);

  int d1 = (int) r % 10;
  int d2 = (int) r / 10 % 10;
  int d3 = (int) r / 100 % 10;
  int d4 = (int) r / 1000 % 10;
  while (digitalRead(buttonPin) == HIGH) {
    while (mass < weight - 1) {

      long reading = 0;
      for (int jj = 0; jj < int(avg_size); jj++) {
        reading += hx711.read();
      }
      reading /= long(avg_size);
      // calculating mass based on calibration and linear fit
      float ratio_1 = (float) (reading - x0);
      float ratio_2 = (float) (x1 - x0);
      float ratio = ratio_1 / ratio_2;
      mass = y1 * ratio;
      taredmass = mass - tare2;


      float r = round(taredmass * 10);
      Serial.println(mass);
      Serial.println(weight);

      int d1 = (int) r % 10;
      int d2 = (int) r / 10 % 10;
      int d3 = (int) r / 100 % 10;
      int d4 = (int) r / 1000 % 10;
      tm.display(3, d1);
      tm.display(2, d2);
      tm.display(1, d3);
      tm.display(0, d4);

      servo.write(120);
      delay(200);
      servo.write(180);



    }
    while (taredmass < weight - 0.5) {

      long reading = 0;
      for (int jj = 0; jj < int(avg_size); jj++) {
        reading += hx711.read();
      }
      reading /= long(avg_size);
      // calculating mass based on calibration and linear fit
      float ratio_1 = (float) (reading - x0);
      float ratio_2 = (float) (x1 - x0);
      float ratio = ratio_1 / ratio_2;
      mass = y1 * ratio;
      taredmass = mass - tare2;


      float r = round(taredmass * 10);
      Serial.println(mass);
      Serial.println(weight);

      int d1 = (int) r % 10;
      int d2 = (int) r / 10 % 10;
      int d3 = (int) r / 100 % 10;
      int d4 = (int) r / 1000 % 10;
      tm.display(3, d1);
      tm.display(2, d2);
      tm.display(1, d3);
      tm.display(0, d4);

      servo.write(110);
      delay(500);
      servo.write(170);



    }
    while (taredmass < weight - 0.2) {

      long reading = 0;
      for (int jj = 0; jj < int(avg_size); jj++) {
        reading += hx711.read();
      }
      reading /= long(avg_size);
      // calculating mass based on calibration and linear fit
      float ratio_1 = (float) (reading - x0);
      float ratio_2 = (float) (x1 - x0);
      float ratio = ratio_1 / ratio_2;
      mass = y1 * ratio;
      taredmass = mass - tare2;


      float r = round(taredmass * 10);
      Serial.println(mass);
      Serial.println(weight);

      int d1 = (int) r % 10;
      int d2 = (int) r / 10 % 10;
      int d3 = (int) r / 100 % 10;
      int d4 = (int) r / 1000 % 10;
      tm.display(3, d1);
      tm.display(2, d2);
      tm.display(1, d3);
      tm.display(0, d4);

      servo.write(100);
      delay(500);
      servo.write(150);



    }
    servo.write(90);
    long reading = 0;
    for (int jj = 0; jj < int(avg_size); jj++) {
      reading += hx711.read();
    }
    reading /= long(avg_size);
    // calculating mass based on calibration and linear fit
    float ratio_1 = (float) (reading - x0);
    float ratio_2 = (float) (x1 - x0);
    float ratio = ratio_1 / ratio_2;
    mass = y1 * ratio;
    taredmass = mass- tare2;
    float r = round(taredmass * 10);
    int d1 = (int) r % 10;
    int d2 = (int) r / 10 % 10;
    int d3 = (int) r / 100 % 10;
    int d4 = (int) r / 1000 % 10;
    tm.display(3, d1);
    tm.display(2, d2);
    tm.display(1, d3);
    tm.display(0, d4);
    
  }

  delay(1000);
}

Credits

Quinten Speleers, Mazlum Akif Altun

Posted by proprietor

Comments