Re: Weight sorting system using arduino

Its not clear on the values you have in your pictures.

If so, this will give a val of 20 on your analog read. This is because 5 volts will read as 1024, so 100mv will be one fiftieth of that :
5v = 5000mv = 1024
Each unit of val is: 5000 divided by 1024 = 5mv
So 100 mv divided by 5mv = 20, and that is what analogRead should return with an input of 100mv

Therefore val will be less than 100 for all weights up to 500 grams and led 2 will be high.

Try dividing your test values by 5.

p.s. you can simplify your code by removing the check for greater than in all your ‘else if’ statements:

for example:
else if(val < 200) is all you need because it must be greater than 100 or it would have been detected by the previous if statement.

I hope that helps

It would help me to help you if you would clarify the following, just post the text values:

How many volts do you read with 100grams? And what is the value from analogRead with 100 grams? ( you can send this value using the serial port)

Try using a potentiometer on the analog input on the master instead of the sensor. Change the voltage using the pot and see if the leds respond as expected.

hey

you should try to take some clearer pictures, then it would be easier for us to help you! The pics you have there are all fuzzy and it's impossible to see what the meter is set to.

D

ok, I will take clear pictures. Thank you.

why do you think that is strange?
Pin 2 will be high for all voltages less than 100 mv because your if statement is :
If (val < 20) // this is checking if the voltage is less than 100mv
Each unit of val equals approx 5mv ( 5v = 5000mv divided by 1024 equals around 5mv)
so anything less than 100mv (including 0mv ) will light the led
If this is not what you want then post what voltage thresholds you require for lighting the LEDs.

the first if statment should check to see if at least some threshold voltage exists, for example:
if( (val > 1) && (val < 20) )

the only unexpected value in your results is the transition from 5 to 6. I don’t know why you are not seeing 0.3 volts on your voltmeter

The expressions are equivalent, either will work.

I prefer the use of the inner brackets because I think it makes it easier to see what the expression is doing. But the compiler doesn’t care so use whichever you prefer.

I see. Thanks a lot ~!