Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
Arduino [Potentiometer + 4 LEDs] [Basic]
  • Sh3llc0d3
    Posts: 1,910
    Well this s a rare one for me but I thought I'd share the source to this program I made to run of a Arduino chip. It's pretty simple and pretty easy once you know what your doing (where the pins are etc).

    What you'll need:
    - Potentiometer
    - 4 LEDs
    - 8 wires.
    - 4 1KΩ Resistors (I'm told you could probably get away with lower resistance ones though).
    - Oh yeah and an Arduino (i'm using the uno model).

    /*
    Description: Potentiometer with increasing LEDs (ok it's a short description)
    Coded by: Sh3llc0d3
    */
    int greenPinOne = 10; // initialises green led (#1) on pin 10
    int greenPinTwo = 11; // initialises green led (#2) on pin 11
    int redPinOne = 12; // initialises red led (#1) on pin 12
    int redPinTwo = 13; // initialises red led (#2) on pin 13

    void setup() {
    pinMode(greenPinOne, OUTPUT); // This just sets the pins up and declares
    pinMode(greenPinTwo, OUTPUT); // the above variables(pins/leds) as outputs.
    pinMode(redPinOne, OUTPUT);
    pinMode(redPinTwo, OUTPUT);
    }

    void loop() {
    int sensorValue = analogRead(A0); // I have a potentiometer hooked up to A0 (analogue pin 0) ...this declares the variable and reads input from A0.
    if (sensorValue == 0) // This next bit it pretty simple, just pretty much involves if statements... well it does... the if's
    { // read the value from the potentiometer and then respond giving the correct output via the led lights.
    digitalWrite(redPinOne, LOW);
    digitalWrite(redPinTwo, LOW);
    digitalWrite(greenPinOne, LOW);
    digitalWrite(greenPinTwo, LOW);
    }
    if (sensorValue > 0 && sensorValue <= 250)
    {
    digitalWrite(redPinOne, LOW);
    digitalWrite(redPinTwo, LOW);
    digitalWrite(greenPinOne, HIGH);
    digitalWrite(greenPinTwo, LOW);
    }
    if (sensorValue > 250 && sensorValue <= 500)
    {
    digitalWrite(redPinOne, LOW);
    digitalWrite(redPinTwo, LOW);
    digitalWrite(greenPinOne, HIGH);
    digitalWrite(greenPinTwo, HIGH);
    }
    if (sensorValue > 500 && sensorValue <= 750)
    {
    digitalWrite(redPinOne, HIGH);
    digitalWrite(redPinTwo, LOW);
    digitalWrite(greenPinOne, HIGH);
    digitalWrite(greenPinTwo, HIGH);
    }
    if (sensorValue > 750 && sensorValue < 1000)
    {
    digitalWrite(redPinOne, HIGH);
    digitalWrite(redPinTwo, HIGH);
    digitalWrite(greenPinOne, HIGH);
    digitalWrite(greenPinTwo, HIGH);
    }
    }


    Also for anyone wondering, the void loop() and void setup() and prereq's for the program to work. If you name them something else of spell it wrong then you won't be able to upload your program onto your arduino board/chip.

    The result is (apologies for using the shit camera on my phone):

    [align=center][video=youtube]


    The noise at 0.11 is my cat that decided to check out what I was doing :\
  • Xin
    Posts: 3,251
    Nice i wanted to get into arduino modding and such how much was the board?
    Xin
  • Sh3llc0d3
    Posts: 1,910
    By itself:
    http://www.oomlout.co.uk/arduino-usb-uno-p-252.html

    The ARDB pack:
    http://www.oomlout.co.uk/budget-pack-fo ... p-217.html

    I got the second one as I couldn't be bothered getting the components seperately. You could buy it seperately and then get components cheaper but hey.

    If your into soldering and not afraid to get your hands mucky:
    http://www.oomlout.co.uk/arduino-pro-mini-p-258.html

    This is what can be achieved from arduino:
    http://www.theregister.co.uk/2011/06/27 ... se_attack/
  • volvo14
    Posts: 18
    nice topic i like it even if i don't understand how to implement it !!!
    good continuation bro
  • Sh3llc0d3
    Posts: 1,910
    If you want more beginner type info on who to setup etc google is definitely your friend. There's some great tutorials about, oh and on youtube too.
  • m0rph
    Posts: 332
    Watching this made me want to come.
    while( !(succeed = try() ) );
  • Sh3llc0d3
    Posts: 1,910
    said:


    Watching this made me want to come.



    Getting a bit over-excited there m0rph lol