97Views7Replies

Author Options:

Hi, I was trying to control 10 Leds with the arduino Through the serial monitor, does anybody know how ? Answered

7 Replies

user
Genius 470 (author)2014-09-21

I was wondering if i could modify this code so i could control the led's with the serial monitor, but i don't know how, Could somebody help?

int pin2 = 2;

int pin3 = 3;

int pin4 = 4;

int pin5 = 5;

int pin6 = 6;

int pin7 = 7;

int pin8 = 8;

int pin9 = 9;

int pin10 = 10;

int pin11 = 11;

int timer = 60;

void setup(){

pinMode(pin2, OUTPUT);

pinMode(pin3, OUTPUT);

pinMode(pin4, OUTPUT);

pinMode(pin5, OUTPUT);

pinMode(pin6, OUTPUT);

pinMode(pin7, OUTPUT);

pinMode(pin8, OUTPUT);

pinMode(pin9, OUTPUT);

pinMode(pin10, OUTPUT);

pinMode(pin11, OUTPUT);

}

void loop() {

digitalWrite(pin2, HIGH);

delay(timer);

digitalWrite(pin2, LOW);

delay(timer);

digitalWrite(pin3, HIGH);

delay(timer);

digitalWrite(pin3, LOW);

delay(timer);

digitalWrite(pin4, HIGH);

delay(timer);

digitalWrite(pin4, LOW);

delay(timer);

digitalWrite(pin5, HIGH);

delay(timer);

digitalWrite(pin5, LOW);

delay(timer);

digitalWrite(pin6, HIGH);

delay(timer);

digitalWrite(pin6, LOW);

delay(timer);

digitalWrite(pin7, HIGH);

delay(timer);

digitalWrite(pin7, LOW);

delay(timer);

digitalWrite(pin8, HIGH);

delay(timer);

digitalWrite(pin8, LOW);

delay(timer);

digitalWrite(pin9, HIGH);

delay(timer);

digitalWrite(pin9, LOW);

delay(timer);

digitalWrite(pin10, HIGH);

delay(timer);

digitalWrite(pin10, LOW);

delay(timer);

digitalWrite(pin11, HIGH);

delay(timer);

digitalWrite(pin11, LOW);

delay(timer);

digitalWrite(pin10, HIGH);

delay(timer);

digitalWrite(pin10, LOW);

delay(timer);

digitalWrite(pin9, HIGH);

delay(timer);

digitalWrite(pin9, LOW);

delay(timer);

digitalWrite(pin8, HIGH);

delay(timer);

digitalWrite(pin8, LOW);

delay(timer);

digitalWrite(pin7, HIGH);

delay(timer);

digitalWrite(pin7, LOW);

delay(timer);

digitalWrite(pin6, HIGH);

delay(timer);

digitalWrite(pin6, LOW);

delay(timer);

digitalWrite(pin5, HIGH);

delay(timer);

digitalWrite(pin5, LOW);

delay(timer);

digitalWrite(pin4, HIGH);

delay(timer);

digitalWrite(pin4, LOW);

delay(timer);

digitalWrite(pin3, HIGH);

delay(timer);

digitalWrite(pin3, LOW);

delay(timer);

}

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)Genius 4702014-09-21

No, you need to start with what I posted, after you've learned how to listen to the serial port.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2014-09-20

Yes, Here's one method, it will allow you to put any combination of 10 LEDs on or off at once

Fasten all the LEDs to the Arduino pins.
Read a number from the serial port

if ( (number&1)==1) led1=1 else led1=0;

if ((number&2)==2) led2=1 else led2 =0;

if ((number&4)==4) led3=1 else led3 =0;

if ((number&8)==8) led4=1 else led4 =0;

if ((number&16)==16) led5=1 else led5 =0;

if ((number&32)==32) led6=1 else led6 =0;

if ((number&64)==64) led7=1 else led7 =0;

if ((number&128)==128) led8=1 else led8 =0;

if ((number&256)==256) led9=1 else led9 =0;

if ((number&512)==512) led10=1 else led10 =0;

There are other ways, but this is the easiest method for a beginner.

Select as Best AnswerUndo Best Answer

user
Genius 470 (author)steveastrouk2014-09-21

Thank you for you answer, But could you explain a little bit more, because i'm only 13 and i just started using arduino and the coding.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)Genius 4702014-09-21

Do this in stages then. Take a look at the serial programming samples in the Arduino code and try them out. Make them turn on and off one LED first. Then come back and look how, if you enter a number from 0..1024, my code works.

Select as Best AnswerUndo Best Answer

user
mpilchfamily (author)2014-09-20

Need lots more information here. What code are you using? What LEDs are you using? How do you have everything wired?

Select as Best AnswerUndo Best Answer

user
Genius 470 (author)mpilchfamily2014-09-20

I'm using a led bargraph wired through pins of 2 through 11 of a arduino uno.

Select as Best AnswerUndo Best Answer