Sorry about the way I posted the code. I didn't know how to do that.
The volts is taking readings ok. I can make the code work, if I don't use a subroutine.
The following code is ok:
#define LED 13
int IRpin = 1; // analog pin for reading the IR sensor
float distance;
void setup()
{
pinMode(LED, OUTPUT); //sets the digital pin as output
Serial.begin(9600); // start the serial port
}
void loop()
{
float volts = analogRead(IRpin)*0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
Serial.println(volts);
float distance = 65*pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
if (distance < 30.00) {
digitalWrite(LED, HIGH);}
else
{
digitalWrite(LED, LOW);}
delay(5000);
digitalWrite(LED, LOW);
delay(5000);
}/code]
But when I try and use 'void measure', as in my original post, it stops working.