Code for parallel LEDs

Hi there

I currently have a working prototype of an arduino duemilanove programmed to turn 1 LED on when FSR (force sensing resistor) is pressed.

I need to have 14 LEDs, so I will be wiring them in parallel.

I just need some guidance on how to wire it through the breadboard, and the associated coding to switch all 14 LEDs on when the FSR is touched.

Here is the current working code for 1 LED

/* FSR testing sketch.

Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground

For more information see FSR Sensor tutorial */

int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 13;// connect Red LED to pin 11 (PWM pin)

int fsrReading; // the analog reading from the FSR resistor divider
int LEDbrightness;

void setup(void) {
Serial.begin(9600); // We’ll send debugging information via the Serial monitor
pinMode(LEDpin, OUTPUT);

}

void loop(void) {

fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);

if(fsrReading) {
digitalWrite(LEDpin, HIGH);
delay(5000);
}

}

Attached are images of current setup and LED array diagram.

The breadboard has columns A-J and rows 1-30

My parallel LED array : 2 x 7 array, with 150ohm resistors

Thanks in advance for any help!

Screen shot 2011-10-08 at 4.14.26 PM.png

The circuit needs 140mA at 9 volts. An Arduino pin is going to give you 40mA at 5 volts.

You can use a transistor to make the pin control more current, or you can spread the LEDs across multiple pins, for example use 7 pins to drive 2 LEDs each.

Good luck!

Chris

int LEDpin = 13;// connect Red LED to pin 11 (PWM pin)

It's nice when the useless comments match the code.

  if(fsrReading) {

The analogRead function returns a value between 0 and 1023, depending on how much force is applied to the sensor. A change in value from one reading to the next of less than 2 is considered noise.

If fsrReading what? As written now, ANY pressure on the sensor will cause a non-zero reading, as will any variation in voltage applied to the sensor, as will any (electrical) noise in the environment. It seems unlikely that ANY of these things should cause the LEDs to turn on for 5 seconds.

if(fsrReading > threshold) seems more useful. Experiment to determine what value threshold should have to prevent false alarms.

You can use a transistor to make the pin control more current, or you can spread the LEDs across multiple pins, for example use 7 pins to drive 2 LEDs each.

You can't drive load connected to 9 Volt directly by arduino, except you wanna to fry it. Transistor or relay is must be present.

Thanks for the replies!

I'll get a transistor then.

I'm very new to this, so excuse the ignorance! But can anyone explain how the breadboard maps to the arduino in terms of the code, and how that changes from how it is now?

Thanks

You want them all to turn on at the same time?
A simple 2n2222a will sink the 140mA you have shown.

Mapping - you intend a standalone circuit?

s4189332:
But can anyone explain how the breadboard maps to the arduino in terms of the code, and how that changes from how it is now?

Can you explain what you mean by that?

Thanks

Quick explanation of my goals here :

It's for an interactive stairway lighting system. So basically I have a model of a staircase, which will have one LED per step. When pressure is applied to the bottom step (via the FSR), I need all 14 LEDs to switch on for about 20 sec and then switch off.

My focus is on the system design and interaction, so I'm struggling a bit with no background in electronics. I understand what I have so far for a couple of LEDs, but having 14 is complicating things!!

Thanks for all your help :)

No problem. Just need to add a 2n2222 transistor & 220 ohm resistor to your design.

Thanks soooo much, it's working :)

Cool. Were you able to get the wiring tucked away nice & neat alongside the stairs?