Lesson 6/31: Buzzer, Driver Wheel and mini Water Pump using Arduino SunFounder Kit | Robojax

Lesson 6/31: Buzzer, Driver Wheel and mini Water Pump using Arduino SunFounder Kit | Robojax

In this lesson, we will explore how to control an active buzzer, a motor for a wheel, and a mini water pump using an Arduino and the SunFounder Kit. This project will help you understand the basics of controlling various components with an Arduino, allowing you to create more complex systems in the future. We will focus on wiring and coding these components to achieve the desired outcomes.

We will start with the active buzzer, which requires careful attention to polarity, followed by controlling a motor using the L298N motor driver, and finally, we will integrate a mini water pump. This combination of projects showcases how to manage electrical components effectively and introduces the concept of using a motor driver to control motors safely. For more detailed explanations, refer to the video (in video at 00:00).

Hardware Explained

The main components involved in this project include an active buzzer, an L298N motor driver, a DC motor, and a mini water pump. The active buzzer generates sound when powered, and it requires a positive and negative connection, with the longer pin typically representing the positive connection. The L298N motor driver acts as an interface between the Arduino and the motor, allowing the Arduino to control the motor's direction and speed without exceeding its current limits.

The DC motor is used to drive the wheel for the smart car project, and it requires more current than the Arduino can provide directly. The L298N motor driver amplifies the control signal from the Arduino to power the motor effectively. The mini water pump operates similarly, using the motor driver to manage its operation while ensuring that it receives the appropriate voltage and current.

Wiring Instructions

motor-wiring

To wire the active buzzer, connect the positive pin to Arduino pin 8 and the negative pin to the ground. For the L298N motor driver, connect the IN1 pin to Arduino pin 9 and the IN2 pin to pin 10. The motor terminals should be connected to the output pins of the driver. Make sure to connect the motor power supply (typically 5 V) to the power input of the L298N, and connect the ground of the driver to the Arduino ground. For the mini water pump, connect it similarly to the L298N outputs, ensuring that the pump is also powered appropriately.

For the motor driver, it’s crucial to connect the ENA pin to enable the driver and control the motor speed through PWM if desired. When wiring the components, use color-coded wires to avoid confusion; for instance, use red for positive connections and black for ground. Ensure that all components are securely connected to prevent any disconnections during operation.

Code Examples & Walkthrough


const int buzzerPin = 8;

void setup() {
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  for (int i = 0; i < 50; i++) {
    digitalWrite(buzzerPin, HIGH);
    delay(3);
    digitalWrite(buzzerPin, LOW);
    delay(3);
  }
  delay(1000);
}

In this code snippet, we declare a constant integer buzzerPin assigned to pin 8. Inside the setup function, we set this pin as an output. The loop function alternates the buzzer's state, turning it on and off rapidly, which produces a beeping sound.


const int motorPinA = 9;
const int motorPinB = 10;

void setup() {
  pinMode(motorPinA, OUTPUT);
  pinMode(motorPinB, OUTPUT);
}

void loop() {
  digitalWrite(motorPinA, HIGH);
  digitalWrite(motorPinB, LOW);
  delay(2000);
  digitalWrite(motorPinA, LOW);
  digitalWrite(motorPinB, HIGH);
  delay(2000);
}

This excerpt shows how we control the motor using pins motorPinA and motorPinB. By setting one pin high and the other low, we can control the direction of the motor. The motor runs in one direction for two seconds and then reverses for another two seconds, demonstrating basic motor control.

Demonstration / What to Expect

When the code is uploaded to the Arduino, you should hear the buzzer beeping intermittently. For the motor, you will observe it rotating in one direction for two seconds before changing direction. If everything is set up correctly, the mini water pump will also activate, moving water as intended. Be cautious of wiring errors, as incorrect connections can lead to unexpected behavior or component damage (in video at 12:30).

Video Timestamps

  • 00:00 Introduction to the projects
  • 02:15 Wiring the buzzer
  • 05:30 Motor control with L298N
  • 09:00 Setting up the water pump
  • 11:45 Code walkthrough

Images

buzzer_schematic
buzzer_schematic
buzzer_wiring
buzzer_wiring
less06-pump-schematic
less06-pump-schematic
less06-pump-wiring
less06-pump-wiring
motor-schematic
motor-schematic
motor-wiring
motor-wiring
866-Lesson 6/30: SunFounder's 3-in-1 Smart Card Arduino kit code Digital write - beep
Language: C++
Copied!

Resources & references

No resources yet.

Files📁

No files available.