Using your breadboard.

The breadboard is a convenient way to build circuits without having to solder connections. It allows for quick prototyping and testing.

A breadboard and circuit

This project shows two main components:

  1. a potentiometer wired to the A0 pin to serve as an input device,
  2. a red LED wired to the the digital output pin D9 which is the output.

The project takes a reading from the potentiometer and converts that to a brightness level to control the brightness of the LED.

The key thing to note in this design is that we've used the power busses on the breadboard to carry our +5, GND, and D9 signals.

The diagram below shows the cable routing in detail. Notice how the two lines of pins marked + and - on either side of the breadboard are used to connect the two components to the various signals. This is useful, because in more complicated circuits, you might require several things to have a +5 connection. Now they can all grab that +5 from the same line of pins.

If you construct this above circuit, and use the code below, you should be able to see the brightness of the LED change as you adjust the potentiometer.

The code for the project above.



    // Potentiometer controlled LED
    const int analogPin = A0;
    const int ledPin = 9;
    int brightness=0;

    void setup() {
        pinMode(ledPin, OUTPUT);
        Serial.begin(9600);
    }

    void loop() {
        int analogValue = analogRead(analogPin);
        //map the analogValue to the acceptable range for the LED output.
        brightness = map(analogValue, 0, 1023, 0, 255);
        //send the brightness value to the D9 pin
        analogWrite(ledPin, brightness);

        Serial.println(analogValue);
        delay(1);
    }