When I run my code and put more than 13 grams on the load cell, my dc motor is supposed to run. However, my motor will not run the slightest bit. I have also attached documentation of my project wiring. Though, if it is not clear, the breadboard power-supply runs off of a 9V battery.
Here is my code:
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
//Initialize the pins for the motor
#define ENABLE 9
#define DIRA 10
#define DIRB 11
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_I2C lcd(0x27,16,2); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(400); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
//---set pin direction for motors
pinMode(ENABLE, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
if (i > 13.00) { // weight is greater than 13g
digitalWrite(ENABLE, HIGH); // Any value between 0 and 255
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
} else {
digitalWrite(ENABLE, LOW); // Any value between 0 and 255
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
}
}
Delta_G:
Those square 9V batteries are great for super low current devices like a smoke detector.
Same for the breadboard supply.
Great to power things that require a few hundred milliamps, but not ok to power a motor.
Motor power should be connected directly to the L293D chip.
Leo..
I get the weight on the screen over 13 many times, for I weigh an object that is about 100 grams, so the screen says 100. I also fixed the power issue and routed the LCD and HX711 to a different power source.
Logic VCC (pin16 of the L293D) must be connected to Arduino 5volt.
L293 ground (pin4 or 5 or 12 or 13 of the L293D) must also be connected to Arduino ground.
So I have done this and modified my code, nut the motor still will not run based on the condition of having more than 13 grams on the load cell.
Here is my new code:
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
//Initialize the pins for the motor
#define ENABLE 5
#define DIRA 3
#define DIRB 4
HX711_ADC LoadCell(6, 7); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_I2C lcd(0x27,16,2); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
//---set pin direction for motors
pinMode(ENABLE, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
Serial.begin(9600); //Set the baud rate of the serial monitor
//Calibrate the Load Cell and LCD
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(400); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
//lcd.print("Hello"); // print out the retrieved value to the second row
lcd.print(i);
if (i > 13) { // weight is greater than 13g
digitalWrite(ENABLE, HIGH); // Any value between 0 and 255
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, HIGH);
delay(500);
} else {
digitalWrite(ENABLE, LOW); // Any value between 0 and 255
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
}
}
//Initialize the pins for the motor
#define ENABLE 5
#define DIRA 3
#define DIRB 4
HX711_ADC LoadCell(6, 7);
That does not match the Fritzing picture.
How big is this motor.
The L293D is old technology, and can only control a tiny toy motor.
It also drops about 2.5volt of the power supply, so only about 3.5volt is available to the motor from that 6volt? battery pack.
Leo..