First acquaintance

  • Typically, when connecting external electronic devices (such as motors) to Raspberry Pi or Arduino, direct connections are not always feasible, and additional electronic components may be required. Even when you're simply lighting up an LED, you still need to connect it somehow to your Raspberry Pi or Arduino.

    To make these connections without soldering, breadboards come in handy. These boards enable electronics enthusiasts to create and prototype their circuit designs before implementing them in more permanent forms with reliably soldered connections.

    The image depicts a breadboard with components from the section "Experiment: Motor Control," which we'll explore shortly. As you can see, on a breadboard, you can place components and connect wires.

    The breadboard we'll be working with is often referred to as a mini or 400-point board (due to having 400 holes). There are breadboards of different sizes available, but this size is well-suited for most projects and experiments.

    On the sides of this type of breadboard, there are usually two rows of holes. Typically, one of them is marked with a red stripe, and the other with a blue stripe. All the holes within each row are electrically connected by traces on the underside of the board. While you can use these rows for various purposes, they are often used for supplying positive and negative power to the circuit.
    Solderless breadboard
    image.png (230.56 KiB)
    Solderless breadboard Viewed 3574 times
    The main area of the board is divided into two sets of rows, each containing five holes in width. In these rows, any five holes aligned horizontally are connected by traces on the underside of the board. To connect the output of one component to another, you can simply insert the wires from both components into the holes aligned in one row.

    Do Not Disassemble the Breadboard!

    Beneath the holes on the front panel of the breadboard are metal clips equipped with clamps capable of holding wires and component leads. I do not recommend disassembling the breadboard (as shown in the picture) because reassembling it to its original state is usually quite challenging.
    image.png
    image.png (206.09 KiB)
    Viewed 3574 times
    Connecting to the Arduino Breadboard

    The GPIO connectors on the Arduino board (sometimes mistakenly referred to as "pins") are actually connectors. To connect one of these connectors to a hole on the breadboard, you can use jumper wires with male pins on both ends—electronics enthusiasts colloquially call them "male-male" wires.

    It's useful to have a good supply of these connectors in various lengths to connect anything to anything. They are easy to acquire, as there are sets of jumper wires available in various sizes and colors. It's a good idea to get a set along with a breadboard, as it simplifies connections, especially when your board is entangled with multiple wires of different colors.
    Connecting an Arduino to a breadboard
    image.png (211.21 KiB)
    Connecting an Arduino to a breadboard Viewed 3574 times
  • In the Arduino community, there's a tradition of starting your experiments by making an LED blink.

    Getting started with this is a pleasant and straightforward project. You'll need to connect just two components to your breadboard: an LED and a resistor. The resistor is mentioned here because all LEDs require it to limit the current passing through them.

    Components

    For this experiment, you will need the following components:

    - Red LED
    - 470-ohm 0.25W resistor
    - 400-point breadboard
    - Male-Male jumper wires (for Arduino only)
    - Male-Female jumper wires (for Raspberry Pi only)

    Breadboard Layout

    The breadboard layout for our project is shown in the diagram. It is the same whether you are working with Arduino or Raspberry Pi, but the connection to the breadboard differs.

    The diagram illustrates that the current from the output of Arduino or Raspberry Pi should first pass through the resistor and then reach the LED.

    Regardless of how the resistor is connected, the positive lead of the LED (it's slightly longer than the negative lead) should be connected to the upper of the two rows of holes on the breadboard. You can also identify the negative lead of the LED by the flat edge on the LED's body.
    Layout of the breadboard for LED control
    image.png (63.18 KiB)
    Layout of the breadboard for LED control Viewed 3573 times
    Arduino Connection

    Connect the Arduino connectors GND and D9 as shown in the diagram. The connection between the Arduino board and the prototyping board is illustrated below.
    Layout of the breadboard for controlling the LED with Arduino
    image.png (154.08 KiB)
    Layout of the breadboard for controlling the LED with Arduino Viewed 3573 times
    Connecting a breadboard to control the LED with Arduino
    image.png (188.14 KiB)
    Connecting a breadboard to control the LED with Arduino Viewed 3573 times
    Arduino Code

    The program turns the LED on for 5 seconds, then off for 2 seconds, and repeats the process. Here is the complete code:

    Code: Select all

    const int controlPin = 9; // 1
    
    void setup() { // 2 
        pinMode(controlPin, OUTPUT); 
    } 
    void loop() { // 3 
        digitalWrite(controlPin, HIGH); 
        delay(5000); 
        digitalWrite(controlPin, LOW); 
        delay(2000); 
    }

    1. In the first line (marked with comment 1), we define the constant controlPin for pin 9. Although Arduino Uno has both digital pins from 0 to 13 and analog pins from 0 to 5, there is a convention that when Arduino code references just a number (in our case, 9), it refers to a digital pin. If you want to refer to one of the six analog pins, you need to prefix the pin number with the letter A.

    2. In the second line (comment 2), the setup() function sets this pin as a digital output using the pinMode function.

    3. In the block marked with comment 3, there is an infinite loop function. It first sets controlPin (pin 9) to HIGH (5V) to turn on the LED. Then it introduces a delay of 5000 ms (5 seconds) and sets сontrolPin to LOW (0V) to turn off the LED. In the next line, we introduce another delay of 2 seconds, and the loop starts over.

    Uploading and Running the Program

    Upload the program to the Arduino. Once the Arduino board restarts during the upload process, your code will start running, and the LED will blink. If the LED doesn't blink, double-check all the connections and ensure that the LED is placed correctly (the longer lead of the LED should go to the upper of the two rows on the breadboard).

    Feel free to change the numbers in the delay functions to vary the LED's on-time and off-time in each cycle. Keep in mind that after each program change, you'll need to upload it again.
  • So, now you know how to turn an LED indicator on and off. Armed with this knowledge, let's try to start and stop an electric motor. To do this, we will use the same programs as described earlier in the "Experiment: LED Control" section, but for controlling the motor, we will use a switch.

    We'll delve deeper into DC motors later. For now, it's sufficient to know that in this experiment, we are using small motors similar to those found in handheld fans or toy cars. These motors are the easiest to use: they start spinning when voltage is applied across their two terminals. Since most motors require a current stronger than what the digital outputs of a Raspberry Pi or Arduino can provide, we can't power the motors directly from them. Instead, we'll include a transistor in the circuit, allowing the weak current from Raspberry Pi or Arduino to control a much stronger current powering the electric motor.

    Whether you are working with Raspberry Pi or Arduino, the same electronic components are used in both cases and are mounted on identical breadboards.

    Keep in mind that there will be more components on the breadboards than in the first experiment, so ensure that all their pins are inserted into the correct holes, and make sure that the components themselves are functioning correctly and properly installed.

    Components

    For this experiment, you will need the following components:
    • Composite transistor (Darlington pair) MPSA14
    • Diode 14001
    • 470-ohm 0.25W resistor
    • Small direct current (DC) motor with a 6V power supply (Battery compartment: 4 AA batteries - 6V)
    • 400-point breadboard
    • Male-Male jumper wires
    • Male-Female jumper wires (for Raspberry Pi only)
    Remember that Male-Female jumper wires are only needed if you plan to perform this experiment with a Raspberry Pi.

    Breadboard Layout

    The breadboard layout for this project is shown in the diagram. After placing all the components on the breadboard, make sure that the transistor is oriented correctly, with its flat side facing to the right. Also, verify the orientation of the diode; it has a stripe on one side, and this side should be pointing towards the upper part of the board.
    Layout of the layout board for engine control
    image.png (132.22 KiB)
    Layout of the layout board for engine control Viewed 3573 times
    Experiments Without Arduino or Raspberry Pi

    Before connecting the breadboard to Arduino or Raspberry Pi, you can test and experiment with it without such connections. In this setup, the transistor acts as a switch. Consequently, two wires will be connected to the board (Arduino or Raspberry Pi): a control wire and a ground wire. Ground (GND) corresponds to zero volts, both for the breadboard and for the Arduino or Raspberry Pi boards. The control connection starts the motor when connected to any power source with a voltage greater than 2V. When the voltage drops below this level, the motor will turn off.

    Practice using a Male-Male jumper wire before moving on to using Arduino or Raspberry Pi. Insert one end of the wire into the same row as the left output of the resistor, and connect the other end to the upper contact of the diode, which is connected to the positive terminal of the battery. The motor will start running, but as soon as you remove the jumper wire from the diode's pin, the motor will stop.
    Checking the circuit before connecting an Arduino or Raspberry Pi to it
    image.png (228.54 KiB)
    Checking the circuit before connecting an Arduino or Raspberry Pi to it Viewed 3573 times
    Connecting to Arduino

    Now that you've verified that the control output from the breadboard indeed starts and stops the motor, you can connect it to one of the GPIO (General Purpose Input/Output) pins on the Arduino using a Male-Male jumper wire. Use pin 9 for this purpose. Note that we've worked with this control pin before (see the "Experiment: LED Control" section).

    Additionally, you'll need to connect another wire - the ground wire (GND) - to the GND pin on the Arduino board. This is also shown in the diagram.
    Layout of the breadboard for motor control using Arduino
    image.png (118.22 KiB)
    Layout of the breadboard for motor control using Arduino Viewed 3573 times
    Experimenting with Arduino

    If your Arduino board still has the program from the previously discussed "Experiment: LED Control" section loaded onto it, there's no need to upload anything new. If that program is no longer on the Arduino, refer back to that section to upload it again.

    Just like in the LED experiment, you can play with the numbers in the delay functions to change the motor's operation duration in each cycle.