Arduino Library Essentials: Servo, Bluetooth, SoftwareSerial

Classified in Technology

Written on in English with a size of 4.24 KB

Arduino Libraries: Extending Functionality

The Arduino environment, much like most programming platforms, can be significantly extended through the use of libraries. These libraries provide additional functionality, making it easier to implement complex features and interact with various hardware components in your sketches.

Arduino Servo Library Capabilities

The Servo library is essential for controlling servo motors. It supports up to 12 motors on most Arduino boards and an impressive 48 motors on the Arduino Mega. It's important to note that on boards other than the Mega, using the Servo library disables analogWrite() (PWM) functionality on pins 9 and 10, regardless of whether a servo is connected to those specific pins. On the Arduino Mega, up to 12 servos can be used without interfering with PWM functionality. However, if you use 12 to 23 motors, PWM will be disabled on pins 11 and 12.

Controlling Continuous Rotation Servos

What are Continuous Rotation Servos?

Unlike standard servos that move to a specific position, a continuous rotation servo rotates fully forward or backward. These servos are excellent for creating simple moving robots and can be controlled using any standard servo code, hardware, or library. They typically come with four different horns, as shown in common product images.

How to Control Continuous Rotation Servos with Arduino

To control a continuous rotation servo with an Arduino, we recommend connecting the control wire to pin 9 or 10 and utilizing the Servo library included with the Arduino IDE. The control values are interpreted as follows:

  • "90" (1.5ms pulse): Stops the servo.
  • "180" (2ms pulse): Full speed forward rotation.
  • "0" (1ms pulse): Full speed backward rotation.

These servos may require some simple calibration. To calibrate, simply tell the servo to 'stop' (send the "90" position command) and then gently adjust the potentiometer located in the recessed hole with a small screwdriver until the servo ceases movement.

Arduino Bluetooth Integration (HC-06)

Connecting HC-06 Bluetooth Module

To establish Bluetooth communication, follow these steps:

  • Pair your HC-06 module with your Android Bluetooth-capable device. Common default passkeys are 1234 or 0000.
  • Start your Android application and select the HC-06 module to connect.

Using Amarino Library for Bluetooth Data

If you are using the Amarino library for your project:

  • Select the specific data to be sent (e.g., which sensor data) within your Android application.
  • Include the Amarino library in your Arduino sketch and receive the data through the serial port as usual.

You can find several interesting examples and resources online for the Amarino library.

SoftwareSerial Library for Flexible Communication

Maintaining USB Serial Connection with SoftwareSerial

If you wish to maintain a serial connection through USB to your computer for debugging purposes, you can initiate a serial connection with a USB module using the SoftwareSerial library. This allows you to have debug information displayed on your computer's screen without interfering with the primary hardware serial port.

Understanding SoftwareSerial Functionality

The SoftwareSerial library was developed to enable serial communication on other digital pins of the Arduino, effectively replicating the functionality of a hardware serial port using software. This is particularly useful when the primary hardware serial port (pins 0 and 1) is occupied or when you need multiple serial communication channels. It is possible to have multiple software serial ports operating at speeds up to 115200 bps. Additionally, a parameter within the library allows for inverted signaling, which is necessary for certain devices that require that specific protocol.

Related entries: