Go Down

Topic: The reset LED keeps flashing (Read 640 times) previous topic - next topic

danny63

I built a project that was designed by another person, yet when I run the code the reset LED keeps flashing. I asked the author his opinion on this and he wasn't sure why. It's for a distance parking sensor in my garage. It uses an HC-SR04 Ultrasonic Ping sensor, and the code appears to be quite simple, it is:

//"Arduino Garage Tennis Ball."  A distance sensor with LED Stoplights for people with multiple vehicles going into a limited space.

const int triggerPin = 8;
const int echoPin = 9;
int redPin=13;
int yellowPin=12;
int greenPin=11;
long duration;
long distance;

void setup(){
  pinMode (13, OUTPUT);
  pinMode (12, OUTPUT);
  pinMode (11, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int stopDistance=6;//object distance in inches from sensor that you want to trigger the Red LED.
  int warnDistance=60;//object distance in inches from sensor that you want to trigger the Yellow LED.
  pinMode(triggerPin, OUTPUT);
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  distance = duration / 72 / 2;//determines distance in inches of object from sensor by microseconds to inches formula.
  if (distance >= warnDistance){
    digitalWrite (redPin, LOW);
    digitalWrite (yellowPin, LOW);
    digitalWrite (greenPin, HIGH);
  }
  else if((distance>stopDistance) && (distance<warnDistance)){
    digitalWrite (redPin, LOW);
    digitalWrite (yellowPin, HIGH);
    digitalWrite (greenPin, LOW);
  }
  else{
    digitalWrite (redPin, HIGH);
    digitalWrite (yellowPin, LOW);
    digitalWrite (greenPin, LOW);
  }
  Serial.println (distance);
}

I hope somebody that's much more adept at the Arduino can help me with this code issue. Everything works as it's supposed to except the red LED always flashes until it's the only one that's supposed to be on, then it's steady. This was from Instructables.com and I couldn't get the issue resolved there. I've never posted a question here so I hope I'm not out of order by asking such a question. I appreciate any help.

mmcp42

#1
Feb 10, 2013, 01:37 pm Last Edit: Feb 10, 2013, 01:41 pm by mmcp42 Reason: 1

...


if you wrap your code in [ code] [ /code] tags (without the spaces)
it is sooo much easier to read :)

Code: [Select]

//"Arduino Garage Tennis Ball."  A distance sensor with LED Stoplights for people with multiple vehicles going into a limited space.

const int triggerPin = 8;
const int echoPin = 9;
int redPin=13;
int yellowPin=12;
int greenPin=11;
long duration;
long distance;

void setup(){
 pinMode (13, OUTPUT);
 pinMode (12, OUTPUT);
 pinMode (11, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 int stopDistance=6;//object distance in inches from sensor that you want to trigger the Red LED.
 int warnDistance=60;//object distance in inches from sensor that you want to trigger the Yellow LED.
 pinMode(triggerPin, OUTPUT);
 digitalWrite(triggerPin, LOW);
 delayMicroseconds(2);
 digitalWrite(triggerPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(triggerPin, LOW);
 pinMode(echoPin, INPUT);
 duration = pulseIn(echoPin, HIGH);
 distance = duration / 72 / 2;//determines distance in inches of object from sensor by microseconds to inches formula.
 if (distance >= warnDistance){
   digitalWrite (redPin, LOW);
   digitalWrite (yellowPin, LOW);
   digitalWrite (greenPin, HIGH);
 }
 else if((distance>stopDistance) && (distance<warnDistance)){
   digitalWrite (redPin, LOW);
   digitalWrite (yellowPin, HIGH);
   digitalWrite (greenPin, LOW);
 }
 else{
   digitalWrite (redPin, HIGH);
   digitalWrite (yellowPin, LOW);
   digitalWrite (greenPin, LOW);
 }
 Serial.println (distance);
}



I would move the setup code at the start of loop into setup
Code: [Select]

  pinMode(triggerPin, OUTPUT);
  pinMode(echoPin, INPUT);


you might also want to activate the pullup on echoPin, but that's just a guess
there are only 10 types of people
them that understands binary
and them that doesn't

holmes4


danny63


What "reset" LED?

Mark
I'm sorry I didn't mention that I was working with a Boarduino that has a red LED as a reset indicator. There's also a small LED on the actual Arduino that flashes in sink with the red LED on my project.

PeterH


I'm sorry I didn't mention that I was working with a Boarduino that has a red LED as a reset indicator. There's also a small LED on the actual Arduino that flashes in sink with the red LED on my project.


Would that be one of these two?
Quote
The specifications for the DC boarduino include ... 2 LEDs, green power and red "pin 13" LED just like the Arduino Diecimila
I only provide help via the forum - please do not contact me for private consultancy.

retrolefty

Yes, you most certainly have a pin 13 led, rather then a 'reset' led. The reason that it sometimes is associated or confused with a reset is that the standard arduino bootloader code blinks pin 13 when it first starts, which is right after a reset condition or initial power-up is activated.

Lefty

danny63



I'm sorry I didn't mention that I was working with a Boarduino that has a red LED as a reset indicator. There's also a small LED on the actual Arduino that flashes in sink with the red LED on my project.


Would that be one of these two?
Quote
The specifications for the DC boarduino include ... 2 LEDs, green power and red "pin 13" LED just like the Arduino Diecimila


That is correct. On my Boarduino from Adafruit it does have two LEDS. It appears to me the more I mess with this project is, the red LED might be flashing in sequence to the trigger or echo pin of the HC-SR04. It doesn't appear to be pin 13 on the Boarduino/Arduino, because I tried moving completely away from pin 13, leaving it open, and the flashing still occurs until the red LED on my project is supposed to stay lit. It's supposed to be the green LED on at first, then as you pull in further into the garage the yellow LED lights, and when I get to the sweet spot the red light comes on. So my problem is when the green or yellow are on, the red LED constantly flashes. It's got to be a code issue since I've now tried two different sensors, two Arduinos, and a Boarduino, all with the same results. I have several books on Arduino projects, such as Beginning Arduino by Michael McRoberts, and Getting started with Arduino by, Massimo Banzi, and I've been going over code just to get a better understanding of how the code works, so it's not an issue of me being lazy hoping other people will do the work for me. I'm really trying to learn. Every problem usually makes you smarter because you have to try many options, and I do think that's a great way to learn. I'm sorry for not being completely clear on my question, I'm not use to asking others for help, but I'll certainly appreciate any help I do get. Thanks for your patience. Danny

PeterH




I'm sorry I didn't mention that I was working with a Boarduino that has a red LED as a reset indicator. There's also a small LED on the actual Arduino that flashes in sink with the red LED on my project.


Would that be one of these two?
Quote
The specifications for the DC boarduino include ... 2 LEDs, green power and red "pin 13" LED just like the Arduino Diecimila


That is correct. On my Boarduino from Adafruit it does have two LEDS.


Neither of them seem to be anything to do with 'reset' as far as I can see.

Is your distance measurement returning sensible values?
I only provide help via the forum - please do not contact me for private consultancy.

Go Up