2. Motorized Pinwheel

Introduction

This project aims to simply rotate a colorful pinwheel using a motor! However, moving things requires a lot of energy, more than what Arduino can provide, and motors also require higher voltage.

Transistor

Transistors allow controlling high loads of current and voltage through the low output current of Arduino's pin, acting as a digital switch. When power is supplied to one of the transistor's pins, called the gate, it closes the circuit between the other two pins, called the source and drain. This way, a high-voltage motor can be turned on and off with Arduino.

Motors

Motors are inductive devices. Induction is a process whereby a varying electric current flowing through a wire is capable of creating a varying magnetic field. When electricity is supplied to a motor, a coil of copper wire tightly wound inside the motor creates a magnetic field, causing the motor shaft to rotate.

Necessary components

Construction

  1. Connect the power and ground of the board to the breadboard.
  2. Add a button to the board by connecting one side to power and the other to digital pin 2 of Arduino. Add a 10 kilo ohm resistor to ground on the output pin of the switch.
  3. Connect the 9-volt battery connector to the breadboard. When using circuits with different voltages, the grounds must be connected to create a single ground, so connect the battery ground to Arduino ground with a jumper wire. Finally, attach one end of the motor to the central pin of the connector to the 9-volt power supply.
  4. Place the transistor on the breadboard. Connect digital pin 9 to the left pin of the transistor. This pin is called the gate, and a voltage on the gate creates a connection with the other two pins. Connect one end of the motor to the central pin of the transistor, which is called the drain.
  5. Connect the motor power supply to the motor and the breadboard, then add the diode. It is a polarized component and should be inserted into the circuit in a single direction. The diode has a positive pole (anode) and a negative pole (cathode). Connect the anode to ground and the cathode to the motor power supply. This component is crucial as it helps prevent any back electromotive force generated by the motor.

IMG_4758.jpg

Code explanation

const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;

void setup() {
  pinMode(motorPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop() {
  switchState = digitalRead(switchPin);

  if(switchState == HIGH){
    digitalWrite(motorPin, HIGH);
  }else{
        digitalWrite(motorPin, LOW);
  }
}

Key Components:

  1. Variables:
    • switchPin: Defines the pin number connected to the switch.
    • motorPin: Defines the pin number connected to the motor.
    • switchState: Stores the current state of the switch (HIGH or LOW).
  2. Setup Function:
    • pinMode(motorPin, OUTPUT): Configures the motor pin as an output pin.
    • pinMode(switchPin, INPUT): Configures the switch pin as an input pin.
  3. Loop Function:
    • Reads the digital state of the switch using digitalRead(switchPin) and stores it in switchState.
    • Uses an if statement to check the state of the switch:
      • If switchState is HIGH, turns on the motor by setting motorPin to HIGH.
      • If switchState is LOW, turns off the motor by setting motorPin to LOW.

Overall, the code demonstrates a simple switch control for a motor using Arduino.