Arduino interface with servo motor using MIT app

Arduino interface with servo motor using MIT app

In this article we will learn how to interface arduino with servo motor using MIT app.
In the last post we will learn how to make full wave rectifier power supply circuit using 7805 regulator. You can visit our website,
I hope you appreciate my work, let’s discuss about today’s project.

Components which we use in this project are listed below:

  1. Arduino nano
  2. HC-05
  3. Servo motor
  4. Connecting wires

Actual image of this project is below:

Arduino interface with servo motor using MIT app
Arduino interface with servo motor using MIT app

Construction of arduino interface with servo motor using MIT app:

  • Connect the VCC point of servo motor to the VCC point of arduino
  • Connect the GND point of servo motor to the GND point of arduino
  • Connect the signal wire of servo motor to the D9 point of arduino
  • Connect the VCC point of HC-05 to the VCC point of arduino
  • Connect the GND point of HC-05 to the GND point of arduino
  • Connect the TX point of HC-05 to the RX point of arduino
  • Connect the RX point of HC-05 to the TX point of arduino

Working of Arduino interface with servo motor using MIT app:

Interfacing an arduino with a servo motor using the MIT App Inventor involves creating a simple mobile app that communicates with the arduino via Bluetooth or another communication method. The app allows you to control the servo motor’s position or angle remotely using buttons or sliders on the mobile interface.

Applications of Arduino interface with servo motor using MIT app:

  1. Home automation
  2. Remote Control Devices
  3. Educational tool
  4. Art Installations
  5. Modeling and Simulation

Advantages of Arduino interface with servo motor using MIT app:

  1. User-Friendly Interaction
  2. Remote Control
  3. Quick Prototyping
  4. Customizability

Program code of this project is below:

#include <SoftwareSerial.h> // TX RX software library for Bluetooth

#include <Servo.h> // servo library

 

Servo myservo; // servo name

int bluetoothTx = 1; // Bluetooth module’s TX to Arduino’s RX (pin 0)

int bluetoothRx = 0; // Bluetooth module’s RX to Arduino’s TX (pin 1)

SoftwareSerial bluetooth(bluetoothRx, bluetoothTx); // Swap RX and TX

 

// Motor states

const int FORWARD = 1;

const int REVERSE = 2;

const int STOP = 3;

int pos = 0;

int motorState = STOP;

 

void setup()

{

myservo.attach(9); // attach servo signal wire to pin 9

// Setup USB serial connection to computer

Serial.begin(9600);

 

// Setup Bluetooth serial connection to Android

bluetooth.begin(9600);

}

 

void loop()

{

if (bluetooth.available() > 0) // Receive number from Bluetooth

{

int servopos = bluetooth.read(); // Save the received number to servopos

Serial.println(servopos); // Serial print servopos current number received from Bluetooth

myservo.write(servopos);

char command = bluetooth.read(); // Read the received character

 

// Update motor state based on command

if (command == ‘A’) {

motorState = FORWARD;

} else if (command == ‘B’) {

motorState = REVERSE;

} else if (command == ‘C’) {

motorState = STOP;

}

 

 

// Rotate the servo the angle received from the Android app

 

 

 

// Perform action based on motor state

if (motorState == FORWARD) {

Serial.println(“Moving forward”);

for (pos = 0; pos <= 0; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

myservo.write(pos);              // tell servo to go to position in variable ‘pos’

delay(15);                       // waits 15 ms for the servo to reach the position

}

// Add your motor control code for moving forward here

} else if (motorState == REVERSE) {

Serial.println(“Moving reverse”);

for (pos = 180; pos >= 180; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos);              // tell servo to go to position in variable ‘pos’

delay(15);                       // waits 15 ms for the servo to reach the position

}

// Add your motor control code for moving in reverse here

}

}

 

}