Can someone help me correct this code.

Hi, I received a lot of help from CrossRoads (Thank you Sir!) but I am still having trouble. Could someone please correct this code for me or point me in the right direction. I am trying to learn how to communicate with the Ping Sensor and using a LED for feedback. I thought that this would make a good starting point. Thank you.

int LED = 13;
const int pingPin = 7;
int alarm = 0;
void setup()
{
 Serial.begin(9600);
 pinMode(LED, OUTPUT);
}

void loop()
{

if (pingPin < 10){
  digitalWrite(LED, HIGH);}
  else{
    digitalWrite(LED, LOW);
  }
  
  
float ping();

long duration, inches; 
pinMode(pingPin, OUTPUT); 
digitalWrite(pingPin, LOW); 
delayMicroseconds(2); 
digitalWrite(pingPin, HIGH); 
delayMicroseconds(5); 
digitalWrite(pingPin, LOW); 
pinMode(pingPin, INPUT); 
duration = pulseIn(pingPin, HIGH); 
inches = (duration); 
}

What is this supposed to be?

float ping();

pulseIn() returns unsigned long so why are duration and inches longs?

long duration, inches;

Honestly no idea I just got it from an online example I found in a code for a robot. I will remove it.

if (pingPin < 10){

You've declared pingPin to be 7; it is ALWAYS going to be less than 10.

(uncompiled, untested)

const int LED = 13;
const int pingPin0 = 7;

void setup()
{
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop()
{
  if (ping (pingPin0) < 10){
    digitalWrite(LED, HIGH);
  }   else{
    digitalWrite(LED, LOW);
  }
}    

unsigned long  ping(int pingPin)
{
  pinMode(pingPin, OUTPUT); 
  digitalWrite(pingPin, LOW); 
  delayMicroseconds(2); 
  digitalWrite(pingPin, HIGH); 
  delayMicroseconds(5); 
  digitalWrite(pingPin, LOW); 
  pinMode(pingPin, INPUT); 
  return pulseIn(pingPin, HIGH); 
}

(probably needs to have the microseconds to inches conversion reinstated)

Ok, so I removed that portion however "7" declares the pin location for my Ping Sensor so I don't really understand why I can't use const since I will keep the sensor plugged into pin 7.

You can give pingPin whatever value you want, but don't confuse the pin number with the range returned by the sensor attached to that pin.

Ok, i think i'm tracking on that. Could you tell me what's wrong with the below code i've been at it for so long I forgot to goto bed.

int LED = 13;
int pingPin = 7;
int val = 0;



void setup()
{
 Serial.begin(9600);
 pinMode(LED, OUTPUT);
 pinMode(pingPin, INPUT);
}

void loop()
{

val = digitalRead(pingPin);
if (val < 50){ digitalWrite(LED, LOW);}
if (val > 60){ digitalWrite(LED, HIGH);}

 


long duration, inches; 
pinMode(pingPin, OUTPUT); 
digitalWrite(pingPin, LOW); 
delayMicroseconds(2); 
digitalWrite(pingPin, HIGH); 
delayMicroseconds(5); 
digitalWrite(pingPin, LOW); 
pinMode(pingPin, INPUT); 
duration = pulseIn(pingPin, HIGH); 
inches = (duration);

Could you tell me what's wrong with the below code

The compiler should be able to tell you. I'm posting from a tablet, so no compiler.
However, you were told way back that you can't expect a digitalRead to return anything other than zero or one.

I posted nearly complete code; why didn't you use it?

OMG ! I am so sorry please forgive me I did not even notice it. Thank you once again I am sorry.