ping to AC - scaling values

hello

I am combinging a parallax Ping ultrasonic sensor with a DC controlled dimmer
http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/ProductID/92/List/1/Default.aspx?SortField=ProductName,ProductName.
Details – Own brands – Velleman – Wholesaler and developer of electronics.

my question is, i will control the dimmer with an analogue PWM value right? so how do i scale the values the PING sensor gives me down to a 0-255 range, or a 0-5v range. must i use a function, or can this be automated?

thank you

fubbi

i will control the dimmer with an analogue PWM value right?

Well no not directly. The PWM output needs to be boosted to 12V using a transistor. Then it needs to be smoothed using a series resistor, and a capacitor and then it can be applied to your controller.

i scale the values the PING sensor gives me down to a 0-255 range

Just scale it using a y = mX +C type of formula. Think about it.

thank you for your speedy gonzales reply!

Quote:
i will control the dimmer with an analogue PWM value right?

Well no not directly. The PWM output needs to be boosted to 12V using a transistor. Then it needs to be smoothed using a series resistor, and a capacitor and then it can be applied to your controller.

The dimmer manual says "Use an adjustment voltage of 0 to 5 (or to 12V max). And it has two pots for adjusting min/max.

Just scale it using a y = mX +C type of formula. Think about it.

I wish that scaling would be a default when passing a value to a limited range port. Like in Isadora.

Can you please explain your formula, if it's simple.
i am trying to get the range 200-13000 squeezed into 0-255.

(looking at this right now :-? Equation of a Straight Line)

Thank you humbly

fubbi

i think there is a function for scaling values, look up map function.

The ping just sends and receives a pulse it does no calculations so you will need to do that part anyway and you can just add that into the scaling mix. Once the code is written it will become automatic to the end user.

there is a function for scaling values, look up map function.

Yes in deed I keep forgetting the wimps functionality.

let S = sensor reading of a sensor range 200 to 13000
so S-200 will give you a range of 0 to 12800
if you have a maximum value of 12800 you want to map this to a value of 255 so divide it by 12800/255 = 501.96 lets call it 502.
A maximum value of 12800 / 502 = 255
Therefore to convert simply:-
converted = (S - 200)/ 502

or you can just do this:
val = map(200,13000, 0,255)

p.s. Mike probably writes his code in hex because its less wimpy than C or C++ :wink:

or you can just do this:
val = map(200,13000, 0,255)

that sounds very useful, but will that really scale everything inbetween too, or just those hard values?

thank you

fubbi

that sounds very useful, but will that really scale everything inbetween too, or just those hard values?

all values are scaled - the map function uses similar math to mikes post.

You can read more about map in the arduino reference: http://www.arduino.cc/en/Reference/Map

brilliant! just what i was looking for

thank you everybody

Mike probably writes his code in hex because its less wimpy than C or C++

How did you know? ;D

Mike probably writes his code in hex because its less wimpy than C or C++

How did you know?

Because I guessed you started to first write code at around the same time I did, back in the good old days when wimps wrote in assembler and real programmers wrote in hex (or octal) ;D