Struggling with using weight ranges and load cell.

A project log for Hedgehog Feeder

Hedgehogs in the UK are classed as an endangered species. For this reason I have chosen my final year project to be a hedgehog feeder.

Abigail SmithAbigail Smith 03/21/2019 at 18:093 Comments

So the idea is that, the hedgehog will be weighed and if it falls within a weight limit it will receive some food, However, at the moment, I am using weights that are below the weight limit (so no food should be dispensed) but in fact, food is being dispensed. 

I also am struggling to create different weight limits which will determine how much food will be dispensed.  

if (scale.get_units()>sensorMin){
    Serial.print("Weight: ");
    Serial.print(scale.get_units(), 3);
    Serial.println(" kg");
    //set RPM at which stepper will rotate when called to step
    hedgehogData.println(scale.get_units(), 3);
    Sleepy::loseSomeTime(10000); //instead of delay (10000)

I have tried using code as shown below but it does not make a difference

else if ((scale.get_units()>sensorMid)&&(scale.get_units()<sensorMax)){...


Ken Yap wrote 03/21/2019 at 22:38 point

You have defined sensorMin and two other varialbles as int but initialised them with floating point numbers. That won't work, they will get rounded down, and in this case to zero, as they are all less than 1. You should use float variables.

  Are you sure? yes | no

Abigail Smith wrote 03/25/2019 at 12:19 point

Hi there, thank you for your advice - just wanted to check whether you meant just to change the variables sensorMin etc to 'float sensorMin =...' or isthere more that needs to be done?

  Are you sure? yes | no

Ken Yap wrote 03/25/2019 at 12:25 point

Yes, just that. int variables can only hold whole numbers, e.g. -10, 42, etc. Effectively you are assigning 0 to them so later the test always succeeds. Refer to a programming book if you need a refresher on types of variables and values they can hold.

  Are you sure? yes | no