my LED output wont work

I have this code:

/*

*/
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int red8Pin = 2;
const int red7Pin = 3;
const int yellow6Pin = 4;
const int green5Pin = 5;
const int yellow4Pin = 6;
const int red3Pin = 7;
const int red2Pin = 8;
const int red1Pin = 11;

// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(red8Pin, OUTPUT);
pinMode(red7Pin, OUTPUT);
pinMode(yellow6Pin, OUTPUT);
pinMode(green5Pin, OUTPUT);
pinMode(yellow4Pin, OUTPUT);
pinMode(red3Pin, OUTPUT);
pinMode(red2Pin, OUTPUT);
pinMode(red1Pin, OUTPUT);

Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
if (distance <= 91.44) {
digitalWrite(red1Pin, HIGH);
}
if (distance <= 80.9625) {
digitalWrite(red2Pin, HIGH);
}
if (distance <= 70.485) {
digitalWrite(red3Pin, HIGH);
}
if (distance <= 60.0075) {
digitalWrite(yellow4Pin, HIGH);
}
if (distance <= 49.53) {
digitalWrite(green5Pin, HIGH);
}
if (distance <= 39.0525) {
digitalWrite(yellow6Pin, HIGH);
}
if (distance <= 28.575) {
digitalWrite(red7Pin, HIGH);
}
if (distance <= 18.0975) {
digitalWrite(red8Pin, HIGH);
}
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

and I can’t get any of my LEDs on my breadboard to light up, the LEDs work (and are connected), but i don’t know what’s wrong, please help me fix my code if that’s the problem

How are the LEDs wired? Are they between the pins and ground? Or between the pins and 5V? Will the LEDs light up with a simple blink program?

if (distance <= 91.44) {The variable distance is an integer.

please use the code tags (< / > button). it makes it easier to read the code.

I was too slow, I was just going to say just that :wink:

i honestly have know idea what im doing, this is my first project, and i dont know all the technical terms for things

OK, what do the serial prints tell you?

serial shows that the sensor senses, and i know a tiny little bit of javascript

If these are common LEDs, make sure your LEDs are wired as D1 or D2.

See:
http://www.gizmology.net/LEDs.htm

.

im sorry, im just trying to help my grandfather stop running into the curb with his car

duskwolf:
im sorry, im just trying to help my grandfather stop running into the curb with his car

Take his car keys off him

If this is for parking in the garage, I use a tennis ball hanging from the roof.

.

while trying to park

travis_farmer:
the fault is not yours. it is my fault for not having enough coffee before trying to help. :smiley:

bit of a safety question, does your grandfather hit the curb while driving, or while trying to park?

if it is while driving, he may need a bit more help than an Arduino can provide.

if it is while he is trying to park, then hopefully we can be of service.

~Travis

while parking outside

never mind guys, thanks for your help, but i figured it out!

I suspect we'll never know.

Hi,
Thanks for posting your code in the first post, most don't.

This may help display your code.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Tom... :slight_smile:

duskwolf:
never mind guys, thanks for your help, but i figured it out!

Which is exactly how this simplified technology is supposed to work!

Discussions aside, there are many of us who would be delighted to know what you did to solve your issue. My girlfriend inherited her father's car, which makes a beep if it's too close to a curb. It also has a more urgent sounding beep if it gets too close to something while backing up. Very useful for us older folk.

larryd:
If this is for parking in the garage, I use a tennis ball hanging from the roof.

Worked for us as well till the dog decided it was her new toy :wink: