First Arduino Trial

Publish: 02.11.2023
Updated: 25.12.2023 17:37
38
A+
A-

Hello everyone, Welcome to aior.com youtube. I wanted to produce content for our Youtube page for you. The first thing that came to my mind was to make an Arduino project. Actually, it’s just a toy, but it can be a little confusing to make. Still, I learned a lot and had a lot of fun while making this obstacle-breaking toy. I wanted to share the construction stages with you. This is actually a pick-up-assemble-and-play style toy like Lego, but it is quite educational in terms of electrical circuits and programming. I heard a lot of good comments about Arduino and wanted to try my first Arduino by buying a sample obstacle-climbing robot kit. I purchased the ready-made Robot Body online and purchased the necessary parts separately. Arduino Uno was used in the project, and the BlueTooth adapter was chosen as HC06. By the way, please note that the HC06 Bluetooth module can only pair with Android and Windows. If you want to control it from Mac or Linux operating systems, you should buy the HM10 Bluetooth module. Video quality will be increased with remaining videos 🙂

Here you can see YouTube video for installation and trial:

Here you can find Arduino codes which will be developed soon:

// Define motor control pins
const int motorPin1 = 9;
const int motorPin2 = 8;
const int motorPin3 = 7;
const int inputPin = 6;  // This pin is set as INPUT, make sure this is intended

void setup() {
  // Begin serial communication at a baud rate of 9600
  Serial.begin(9600);

  // Initialize motor control pins as OUTPUT
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);

  // Initialize inputPin as INPUT
  pinMode(inputPin, INPUT);  // Check if this should be INPUT
}

void loop() {
  // Check if there is any serial data available
  if (Serial.available() > 0) {
    // Read one byte from the serial buffer
    char data = Serial.read();

    // Stop all motors before setting new direction
    Stop();

    // Determine the command and execute the corresponding action
    switch (data) {
      case 'R':  // Turn Right
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        break;
      case 'L':  // Turn Left
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        break;
      case 'F':  // Forward
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, HIGH);
        break;
      case 'B':  // Backward
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        break;
      default:
        // If the command is unrecognized, ensure all motors are stopped
        Stop();
        break;
    }
    // You could add a delay here if needed, for example:
    // delay(10);
  }
}

// Function to stop all motor activity
void Stop() {
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  // Do not digitalWrite to inputPin. If it's meant to be an output, change its mode in setup().
}

This code is an Arduino script designed to control a set of four outputs, to drive motors. We have created a setup function to initialize serial communication and set the pin modes, and a loop function that reads serial input to control the pins. The Stop() function turns all the controlled outputs off.

The control scheme uses single-character commands sent over the serial port:

  • ‘R’ sets one pair of outputs to drive in one direction (forward or backward).
  • ‘L’ sets the other pair of outputs to drive in the opposite direction.
  • ‘F’ to set the device to move forward.
  • ‘B’ is for backward motion.

Android application must be adjusted to send these codes to Robot.

Leave a Comment

Comments - 0 Comment

No comments yet.