Hello everyone, I would like to ask what is wrong with my code, I am trying to use Load cell as a switch which would turn on the cooling fan/ motor and turn off if there are no weight detected. The materials that I used are load cell 5kg, HX711 module and 12V cooling fan directly connected to Arduino. I don't know what's wrong with my code, pls help me. I am a beginner at coding I only learned blink codes. This is for my research project.
I suggest you use a number greater then zero as there will be noise at that point. Something a little bigger then that say 5 somewhat below your minimum weight. This will help to keep it from oscillation.
The Arduino will not make the fan work. You need to connect an Arduino output pin to control a relay compatible with Arduino. The relay will pass the 12vdc needed from a 12vdc power supply to the fan.
#include <HX711.h> // Library abstraction layer to convert high level code to low level commands
const int LOADCELL_DOUT_PIN = 4; // DATA OUT pin from HX711 amplifier to Arduino
const int LOADCELL_SCK_PIN = 5; // CLOCK pin from HX711 amplifier to Arduino
const int FAN_PIN = 8; // this pin will enable and disable a relay to power the fan
HX711 loadcell; // create an INSTANCE of HX711
void setup () // initialize
{
loadcell.begin (LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
pinMode (FAN_PIN, OUTPUT);
} // you needed a close-brace here... it was missing
void loop () // this is your main code that will repeat
{
long weight = loadcell.read(); // declare weight a long datatype, to store loadcell.read() data
if ( weight > 1 ) { // if the data/weight is greater than 5 (for noise protection - see @gilshultz)
digitalWrite (FAN_PIN, HIGH); // set the RELAY pin HIGH to turn the fan ON
} else { // otherwise... if the weight is <= 5...
digitalWrite (FAN_PIN, LOW); // set the RELAY pin LOW to turn the fan OFF
}
} // fin
You will need to CALIBRATE with a known weight (a bag of rice, a slug, et c.) for the EMPTY WEIGHT (tare).
I tried it yesterday with the help of my friends brother who is an IT, the fan turned on even though it is directly connected to the Arduino however the rotation of the fan is very slow or average.
You are killing your Arduino - disconnect it from the fan. Arduino is a microcontroller on a 5vdc board, and not a power supply. Look at my drawing... the fan is powered by the power supply when the relay is energized when the load cell weighs more than "5" (you may change the weight to your choice). 12vdc is present on your computer's power supply (as are GND, +/-5VDC, +/-12VDC terminals).
It doesn't indicate how much amp the material has, it just said 12V PTC heater and by the way sir we're going to change the cooling fan to a DC motor how many volts do you think we should use? And do we still need the relay module if we're gonna use DC motor? Or can we directly connect it to the Arduino if it's a 5V or 3V DC motor?
A fan using more volts means a bigger power supply. Cooling fans have a "cubic feet per minute" (CFM) rating that you will need to experiment with for your application (to keep it cool). Never power anything with an Arduino. Use the relay to pass the power from the power supply to the fan. Ensure the fan power requirement does not exceed the power supply output, and you really should not use 100% of the power supply output.
Noted sir. I was told by my teacher to use one Ac to Dc power supply for our Arduino and 12Ptc heater, are there material you can suggest to about this? He said about to make it parallel circuit to connect the power supply of both Arduino and heater since they are a different components of our product. And I would like to clarify if is it ok to power the Arduino with the 12V ac to DC through the power in Arduino or we need the back converter?