LED "motor" demo.

Creator : Stein-Ove Bratthammer.
[smiley=beer.gif]

/*
Creator : Stein-Ove Bratthammer.
You will need:

6 LED diodes
6 Transistors Bipolar hFE (about 200)
6 x 100 ohm resistors (brown black brown)
6 x 2.2 k ohm resistors (red red red)
some jumper wires
Arduino (I use dumilanove)

here is the setup:
set 1:pin 2 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 2:pin 3 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 3:pin 4 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 3:pin 5 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 4:pin 6 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 5:pin 7 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
set 6:pin 8 to pin on 2.2k resistor to Base on Transistor, Transistor Collector to 100 Resistor, Resistor to 5v pin, Transistor Emitter to LED, LED notch to GND
(2) (3) (4) (5) (6) (7)

the software is using serial communication.
*/
int incomingByte = 0; // for incoming serial data
int lr = 0;// left/right flag
int run = 0;// motor on/off flag
int LEDpin = 5;// Start pin numb 5 (can be 2,3,4,5,6 or 7)

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(2,1);pinMode(3,1);pinMode(4,1);// open pin 2 to 7 for output.
pinMode(5,1);pinMode(6,1);pinMode(7,1);
Serial.println("-----------------------------");
Serial.println(“key 1 = motor on/off”);
Serial.println(“key 2 = go left/right”);
Serial.println("-----------------------------");
}

void loop() {
if (run == 1){
digitalWrite (LEDpin,1);// turns LED pin on
delay(100);
if (lr == 1){
digitalWrite (LEDpin,0);// turns LED pin off
if (LEDpin < 7){LEDpin = LEDpin + 1;}
digitalWrite (LEDpin,1);
}
else {
digitalWrite (LEDpin,0);
if (LEDpin > 2){LEDpin = LEDpin - 1;}
digitalWrite (LEDpin,1);
}
}
//“1” = 49
// “2” = 50

// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();

if (incomingByte == 49){if (run == 1){run = 0;Serial.println(“motor is off”);}else {run = 1;Serial.println(“motor is running”);}}
if (incomingByte == 50){if (lr == 1){lr = 0;Serial.print("Stepping left ");}else {lr = 1;Serial.println(“Stepping right”);}}
}
}

Good job! I’ll try. Thank you!