Go Down

Topic: Compare two sensor values (Read 14503 times) previous topic - next topic

wildbill

Quote
But don't I have to use the "map function" again now in order to map those values to my LED ports?

Why? The code works off the absolute difference already, no need to massage it further.

The code now looks like it should work. If it doesn't, serial.print the values you have and the difference - it may be that you'll need to adjust the thresholds you set in the ifs.

snickers_90

okay well that little thing with the values was my mistake with the basic version of the code as well. I think I will fix it somehow  :) Oh dear  :~ THANK YOU SO MUCH!!!

ScottC

Hi Snickers,

Sometimes it is better to start from scratch rather than mould another code.
The reason you get varied responses, is because you are trying to do something very different from the original code you referenced.
And you seem to be changing your question or requirement.

I am going to lay out what I think you want to do in point form, and if you want something different, you can say so in subsequent comments.

1. You have 2 flex sensors.
One attached to Analog input 0 : lets call this one flexA0,
and the other attached to Analog input 1: lets call this one flexA1.

2. You have 3 LEDs
These LEDs are attached to pins 5, 6 and 7.

3. You want a single LED to light up when the flex sensor readings do not match
The LED that lights up depends on the difference between flex sensor readings.

4. If there is no difference between flex sensor readings : All LEDs are off

5. If there is a difference of 1-10: LED on pin 5 lights up, others are off.

6. If there is a difference of 11-20: LED on pin 6 lights up, others are off.

7. If there is a difference greater than 20: LED on pin 7 lights up, others are off.


Please note: 270 minus 225 is NOT 25, it is 45...
Once we have the question right, then we can work on the answer.


snickers_90

Quote
1. You have 2 flex sensors.
One attached to Analog input 0 : lets call this one flexA0,
and the other attached to Analog input 1: lets call this one flexA1.

2. You have 3 LEDs
These LEDs are attached to pins 5, 6 and 7.

3. You want a single LED to light up when the flex sensor readings do not match
The LED that lights up depends on the difference between flex sensor readings.

4. If there is no difference between flex sensor readings : All LEDs are off

5. If there is a difference of 1-10: LED on pin 5 lights up, others are off.

6. If there is a difference of 11-20: LED on pin 6 lights up, others are off.

7. If there is a difference greater than 20: LED on pin 7 lights up, others are off.


Hi Scott C,

thanks a lot again for your detailed post :) I'm sorry for confusing some of you here but as I already
mentioned it's really hard to explain such a problem in English.
Your interpretation is absolutely right.
The last code that was posted by PaulS was actually the one I was trying to write and it worked fine
with a little tuning the values of the sensors. The most confusing problem is that my sensors are both
of the same type but sensor one gives me values from 390 to 258 while the other one gives me
something in between 480 to 340. That's really strange cause they are opposite...
But I fixed it by playing with those values. Now everything works fine :-)

But thanks a lot again and again for your answer :) I will try to write posts that are easier to understand
in the future ;)

bilaldebs

hi, i am working on glove assessment for hand fingers using arduino uno with two flex sensor,
i start by using just one sensor and i map its reading values from 0-100 then i map (0-100) on led bar of 10 leds which blink one by one incrementally during flexing the sensor (it works properly).
know i want some help to add my second flex sensor to the circuit and i should put an external selector which select the sensor that should be assigned to the led bar, and the change in code if there is any if statement i should use.

thanks for help and support.

Go Up