Go Down

Topic: Weight Sensor switch (Read 1 time) previous topic - next topic

BAMac

Hello,

 I have been working with the Audrino Uno program on a project using weight sensors that triggers a relay.  I can get the relay to turn on and off just fine, but I have a problem with setting the relay to trigger at a specific weight.  I want to be able to adjust this specific weight if/when I choose to do so.
 
I have some Force Sensitive Resistors (Square) and these can handle 100g-10kg. I am new to the coding community, but I have been doing electrical work for 40+ years, so I know how to set up the board, but I think I'm having trouble with the code I wrote. 

The following is my code:

void setup() {
 
Serial.begin(9600); 
}

void loop() {

  pinMode(9,OUTPUT);
  int sensorValue=analogRead(A0);
  float voltage=sensorValue*(5.0/1023);
  Serial.println(voltage);
  digitalWrite(9,HIGH);
  delay(sensorValue);
 
  if (voltage>=10.00)
  //digitalWrite(9,HIGH)
    {   
      pinMode(9,HIGH);
    }

  else (voltage<10.00);
  digitalWrite(9,LOW);
  {
    pinMode(9,LOW);
  }

}



Is there a library I need, or something else to add to my code, to specify how I want my project to turn on only when the weight reaches 10.4 lbs. (5 kg) or above?


Wawa

Post a link to the sensor you're using. There are many.

Post a diagram an/or picture of how you have connected this sensor
And the value of the pull-up resistor.

Why convert to voltage. Are you making a voltmeter?
Leo..

Wawa

This might work (untested).
Leo..
Code: [Select]
int sensorValue;
int offset = 75; // enter here the zero weight A/D value
float weight; // final weight

void setup() {
  pinMode(9, OUTPUT);
  digitalWrite(9, LOW); // assuming LOW is off
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(A0);
  Serial.print("A/D value is ");
  Serial.print(sensorValue);
 
  weight = (sensorValue - offset) * 0.02345; // weight conversion
  Serial.print("  Weight is ");
  Serial.print(weight);
  Serial.print(" lbs");
 
  if (weight >= 10.4) {
    digitalWrite(9, HIGH);
    Serial.println("  Relay On");
    delay(1000);
  }
  else {
    digitalWrite(9, LOW);
    Serial.println("  Relay OFF");
    delay(1000);
  }
}

BAMac

WOW!!!!!  You bet it does!  Can't thank you more - or can I?  This is going to make this project work beautifully!  Where can I send a thank you gift?  I cannot believe I've worked on this so long, and you fixed it in seconds!  Thank you, thank you, thank you!

Wawa

I am just a hobby coder. If you spend some time with the examples that come with the IDE, you can do the same in a few weeks. Thanking people is usually done by adding a karma point.
Leo..

BAMac

Oh, believe me, I've done it twice already! Thanks again!

Rajpal-singh

Dear
I want to make same  project


"Weight Sensor switch"

 (detect / show the weight,  and OFF the relay when 'n' weight)

could any body please tell me about the components required for the same.
:rajpalsinghnewdelhi@gmail.com

Thanks

wvmarle

Please read this, and start your own thread instead of reviving a 3 year old one.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up