Go Down

Topic: Senior Project - PIR senors with LED's sequence (Read 2954 times) previous topic - next topic

PaulS

Remove the doNextHole(...); line. It is not a function, it is a function prototype. The Arduino IDE will create one (correctly) when you create the function, which looks like
Code: [Select]
void doNextHole(int this, int that, int theOtherThing)
{
  // Do something
}

marklar

Quote

3) Do I need a resistor for each LED if the LED's are 3.5v and the output on my Arduino is 3.5?

I have asked this before and the answer I got was yes. Current and voltage are not the same.

In this case you are running a single LED at a time.  If you do a project that needs to run quite a few LEDs, then I normally use a 5v power supply like a standard USB power supply for an iPhone.  Be sure to connect the ground on the power supply with the arduino ground.   I personally do not power anything over a couple of LEDs via the arduino (anymore).  

Regardless of running your 5v from the arduino or the power supply, you will need a resistor for each LED.  I use a 100 ohms resistor for LEDs that require 3.2v, such as RGB Green and Blue legs and most bright white LEDs and a 180ohm for the Red (2v) LEDs.  Of course check your LED requirements and test with some resistors before doing your build.

Programming Advice
You should never have a program written and not know if it works but instead work one step at a time. Start with the smallest working code you can get and work up slow from there.  

I would write down the logic in plain language and then work on each part of the problem as an individual problem.  Once you have each of your units working and you understand fully what is happening, you can put it all together.   For a project like yours I would be working something like the following path....

1) Get the process to light up led 1 and when I put my hand in the box 1, it turns off.
2) Next get it to turn on the next led when it turns off the primary one and maybe get the full lighting loop working at this time.
3) Get the process to light up led1 and then put hand in any other LED and see that the buzzer goes off.
4) Now that basic code is working, time to code the process to assure the correct box is chosen based on "current box" and if so, cycle to the next box.  if not, kick off the buzzer and do not cycle to next box.

Note: You may need code like this (untested) to turn off the last LED when you turn on the first LED or when it loops back to the first LED your last one will still be on.

Code: [Select]
     if(i > 0){
         pLedPin = LEDs[i-1]; // Set previous pin (to turn off)
       } else {
         pLedPin = LEDs[9]; // Set previous pin (to turn off) - in this case - set the last off if moving to next
       }



Programming can be tons of fun once you get the hang of it, so hang in there and I hope this helps.

PaulS

Quote
Soooo.... What do I do? what do I need to write? What needs to be added or taken away?

That's hard to say, since we have no idea what doNextHole is supposed to do. All I can tell you is that you need to a return type and a body to the function.

Go Up