arduino scale
below working code throws switch when arduino connected scale reaches reading (weight). need re-setting relay. if re-set program, tare reading changes , weight of samples different. propose like:
if relay switch has been thrown, check state of re-set switch , cease voltage relay.
can kindly through code below , show me insert type of statement? have tried many times , cant seem results after.
i should mention bit of noob...
thanks,
-jim
moderator edit: [code] [/code] tags added.
if relay switch has been thrown, check state of re-set switch , cease voltage relay.
can kindly through code below , show me insert type of statement? have tried many times , cant seem results after.
i should mention bit of noob...
thanks,
-jim
code: [select]
// arduino load cell amplifier
// christian liljedahl
// christian.liljedahl.dk
// load cells linear. once have established 2 data pairs, can interpolate rest.
// step 1: upload sketch arduino board
// need 2 loads of know weight. in example = 10 kg. b = 30 kg
// put on load
// read analog value showing (this analogvala)
// put on load b
// read analog value b
// enter own analog values here
float loada = 48.3; // kg
int analogvala = 548.23; // analog reading taken load on load cell
float loadb = 1051.9; // kg
int analogvalb = 305.75; // analog reading taken load b on load cell
// upload sketch again, , confirm, kilo-reading serial output correct, using known loads
float analogvalueaverage = 0;
// how readings?
long time = 0; //
int timebetweenreadings = 20; // want reading every 2000 ms;
int relay1 = 10;
void setup() {
serial.begin(9600);
pinmode(relay1, high);
}
void loop() {
int analogvalue = analogread(3);
// running average - smooth readings little bit
analogvalueaverage = 0.99*analogvalueaverage + 0.01*analogvalue;
// time print?
if(millis()- time >= timebetweenreadings){
float load = analogtoload(analogvalueaverage);
serial.print("analogvalue: ");serial.println(analogvalueaverage);
serial.print(" load: ");serial.println(load,5);
time = millis();
if(load > 1000)
{ digitalwrite(relay1, high);
}
}
}
float analogtoload(float analogval){
// using custom map-function, because standard arduino map function uses int
float load = mapfloat(analogval, analogvala, analogvalb, loada, loadb);
return load;
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
moderator edit: [code] [/code] tags added.
tools + auto format useful.
when want reset relay? after reading weight, , activating relay, make sense me read switch, , reset relay if switch pressed.
when want reset relay? after reading weight, , activating relay, make sense me read switch, , reset relay if switch pressed.
Arduino Forum > Using Arduino > Programming Questions > arduino scale
arduino
Comments
Post a Comment