Go Down

Topic: Ping))) SENSOR colour slider (Read 5986 times) previous topic - next topic

Muneeb

hi,
this is my first project (and youtube video)
and i would like to share it to every one.
i also put a tutorial in this video so that maybe you can make one.
dont forget to comment  :D

GrooveFlotilla

I would comment if I could see something
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.


JO3RI

Not bad at all. Tell us how you did this, so we can comment on your work.  ;)
http://www.JO3RI.be

Nederlandstalige sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Muneeb

Easy,

1.connect the 5v, ground, signal pin(7) to the PING)))
2.connect an led to the ground and between the pin 4 to 13 (exepte 7)
3.copy and past the code written in this quote:
Quote

const int pingPin = 7;


void setup() {
  pinMode (13,OUTPUT);
    pinMode (12,OUTPUT);
      pinMode (11,OUTPUT);
        pinMode (10,OUTPUT);
          pinMode (9,OUTPUT);
            pinMode (8,OUTPUT);
              pinMode (6,OUTPUT);
                pinMode (5,OUTPUT);
                  pinMode (4,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  long duration, inches, cm;

  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
 
  return microseconds / 29 / 2;
}


long microsecondsToCentimeters(long microseconds)
{
  if ( pingPin ==  microseconds /50 /2 )
  {
    digitalWrite(13,HIGH);
   
  }
  else
  {
    digitalWrite(13,LOW);
  }
  {
if ( pingPin == microseconds /60/2 )
  {
  digitalWrite(12,HIGH);
  }
  else
  {
    digitalWrite(12,LOW);
  }
  {
  if ( pingPin ==  microseconds /70 /2 )
  {
    digitalWrite(11,HIGH);
   
  }
  else
  {
    digitalWrite(11,LOW);
  }
  {
if ( pingPin == microseconds /80/2 )
  {
  digitalWrite(10,HIGH);
  }
  else
  {
    digitalWrite(10,LOW);
  }
  {
  if ( pingPin ==  microseconds /90 /2 )
  {
    digitalWrite(9,HIGH);
   
  }
  else
  {
    digitalWrite(9,LOW);
  }
  {
if ( pingPin == microseconds /100/2 )
  {
  digitalWrite(8,HIGH);
  }
  else
  {
    digitalWrite(8,LOW);
  }
  {
  if ( pingPin ==  microseconds /110 /2 )
  {
    digitalWrite(6,HIGH);
   
  }
  else
  {
    digitalWrite(6,LOW);
  }
  {
if ( pingPin == microseconds /120/2 )
  {
  digitalWrite(5,HIGH);
  }
  else
  {
    digitalWrite(5,LOW);
  }
  {
  if ( pingPin ==  microseconds /130 /2 )
  {
    digitalWrite(4,HIGH);
   
  }
  else
  {
    digitalWrite(4,LOW);
  }
  {
if ( pingPin == microseconds /140/2 )
  {
  digitalWrite(3,HIGH);
  }
  else
  {
    digitalWrite(3,LOW);
  }
  }
  }

  return microseconds / 29 / 2;
  }
}
  }
}
  }
}
  }
}

if something isn't working, tell me  :)

AWOL

Quote
if something isn't working, tell me  

Well, given
Code: [Select]
const int pingPin = 7;, then
Code: [Select]
if ( pingPin ==  microseconds /50 /2 )
or
Code: [Select]
if ( pingPin == microseconds /60/2 )

don't seem very likely.

Muneeb

well ,
the pingPin is name given to the Sensor connected to pin 7

Quote

if ( pingPin ==  microseconds /50 /2 )


this is the speed for the sending ultrasonic burst divised by 2 for the echo.

i dont get what the problem

AWOL

Quote
the pingPin is name given to the Sensor connected to pin 7

No, "pingPin" is the name given to the pin to which your sensor is connected.

It has the value 7 decimal, which never changes.
Do you see the problem now?

Muneeb

still not

you can just change the number of the pin where is connected the Sensor

AWOL

Code: [Select]
const int pingPin = 7;

It has the value seven, 7, 0x7, 07, 0b111.
You have made it a constant.

This
Code: [Select]
if ( pingPin ==  microseconds /50 /2 )
is satisfied by just one value of "microseconds" (for most intents)

Seeing it now?

Muneeb

sorry,
i still cant understand.
i dont know about constant int
but i know about int

AWOL

Quote
i still cant understand.


You've got a whole string of comparisons like
Code: [Select]
if ( pingPin ==  microseconds /50 /2 )
if ( pingPin == microseconds /60/2 )
if ( pingPin ==  microseconds /70 /2 )
if ( pingPin == microseconds /80/2 )
if ( pingPin ==  microseconds /90 /2 )


where "pingPin" only ever has, only ever can have, the value 7.
Doesn't that seem wrong to you?

You've posted this code in the Exhibition as an example of working code - why?

Muneeb

thats all good, each 5 cm is gonna turn an led on

AWOL

#13
Sep 04, 2011, 06:55 pm Last Edit: Sep 04, 2011, 07:08 pm by AWOL Reason: 1
{{ sob }}

Why on Earth should a range calculation be related to the pin the sensor is connected to?
What if the next guy to download your code decides to attach the sensor to pin 12 instead?

Muneeb

so ,that stupid guy should change the code pin 7 to 12

Go Up