Double Servo Control Using Bluetooth With Potentiometers

by samuelkennedy1972 in Circuits > Arduino

20 Views, 0 Favorites, 0 Comments

Double Servo Control Using Bluetooth With Potentiometers

IMG_0047.jpg

In this Instructables we will show you how to build a system that will use potentiometers to control multiple servo using bluetooth, the servos will be able to react in real time and move according to what the potentiometers say. This project will use a combination of analog control and wireless communication.

Supplies

  1. 2x Arduino uno
  2. 2x 10k potentiometer
  3. 2x Breadboard
  4. many Wires
  5. 2x Servos
  6. 2x rf24 Bluetooth modules

Wire the System (Transmitter and Receiver)

IMG_0044.jpg
IMG_0045.jpg

Both the transmitter and the receiver RF24 module are wired the same which makes it nice and easy. An important part of the wiring process is to make sure the bluetooth modules are connected to the 3.3 volt power source instead of the 5 volt. The wiring pins that we used for the modules were:

  1. CE pin to pin 9
  2. CSN pin to pin 8
  3. GND to GND and VCC to 3.3V
  4. MOSI pin to pin 11
  5. MISO pin to pin 12
  6. SCK pin to pin 13



Transmitter Arduino (with Potentiometers):

IMG_0046.jpg
IMG_0048.jpg


Transmitter Arduino (with Potentiometers):

  1. Connect the first potentiometer to A0 and the second potentiometer to A1 on your Arduino.
  2. Connect the nRF24L01+ module to the Arduino:
  3. CE pin to pin 9
  4. CSN pin to pin 8
  5. GND to GND and VCC to 3.3V
  6. MOSI pin to pin 11
  7. MISO pin to pin 12
  8. SCK pin to pin 13


Receiver Arduino (with Servos):

  1. Connect the first servo to pin 7 on your Arduino.
  2. Connect the second servo to pin 6 on your Arduino.
  3. Connect the nRF24L01+ module to the Arduino (same wiring as the transmitter):
  4. CE pin to pin 9
  5. CSN pin to pin 8
  6. GND to GND and VCC to 3.3V.


Code for Transmitter

The Code begins by reading the values that are produced from the two potentiometers, then changes them to a range from 0 to 179, and makes them into an array so they can be transmitted as one through the RF24 radio. It does this in a loop() function that has a delay that separates the transmis

sions. There are three libraries required for this code.

Libraries:

  1. SPI.h:

  2. nRF24L01.h

  3. RF24.h


Code:

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>

#include <Servo.h>



const int SERVO_PIN1 = A5;

Servo servo1;

const int SERVO_PIN2 = A4;

Servo servo2;

const int SERVO_PIN3 = A3;

Servo servo3;

const int THRUSTER_PIN = 4;



RF24 radio(9, 10);

const byte address[6] = "07332";

bool turbineIsOn = true;

void setup() {

radio.begin();

radio.openReadingPipe(0, address);

radio.setPALevel(RF24_PA_MIN);

radio.startListening();

Serial.begin(9600);

pinMode(THRUSTER_PIN, OUTPUT);

servo1.attach(SERVO_PIN1);

servo2.attach(SERVO_PIN2);

}

void loop() {

if (radio.available()) {

byte Array[4];

radio.read(&Array, sizeof(Array));

Serial.print(Array[0]);

Serial.print(" ");

Serial.print(Array[1]);

Serial.println();

if (Array[0] == 0) {

moveServo1(Array[1]);

}

if (Array[0] == 1) {

moveServo2(Array[1]);

}

if (Array[0] == 2) {

moveServo3(Array[1]);

// turnMotor(Array[1])

}

}

}

void moveServo1(int rotation) {

servo1.write(rotation);

}

void moveServo2(int rotation) {

servo2.write(rotation);

}

void moveServo3(int rotation) {

servo3.write(rotation);

}

void turnMotor(int number) {

if (number > 90) {

digitalWrite(THRUSTER_PIN, HIGH);

} else {

digitalWrite(THRUSTER_PIN, LOW);

Serial.println("LOW");

}

}



Code for Receiver

This receiver code will allow an Arduino to wirelessly control two servo motors using the data being sent from a second Arduino with potentiometers. It receives two angle values 0–180 using NRF24L01 modules, and then moves each servo accordingly. This allows for the remote, real-time movement of servos for robotics or other RC projects.

Libraries:

  1. SPI.h:

  2. nRF24L01.h

  3. RF24.h

Code:

#include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>

const int POT_PIN1 = A0;

int potentiometerReading1;

const int POT_PIN2 = A1;

int potentiometerReading2;

const int POT_PIN3 = A2;

int potentiometerReading3;

RF24 radio(9, 10);

const byte address[6] = "07332";

byte Array[4];

void setup() {

radio.begin();

radio.openWritingPipe(address);

radio.setPALevel(RF24_PA_MIN);

radio.stopListening();

Serial.begin(9600);

pinMode(POT_PIN1, INPUT);

pinMode(POT_PIN2, INPUT);

pinMode(POT_PIN3, INPUT);

}

void loop() {

potentiometerReading1 = map(analogRead(POT_PIN1), 0, 1023, 0, 180);

potentiometerReading2 = map(analogRead(POT_PIN2), 0, 1023, 0, 180);

potentiometerReading3 = map(analogRead(POT_PIN3), 0, 1023, 0, 180);

// Serial.println(potentiometerReading1);

// Serial.println(potentiometerReading2);

Serial.println(potentiometerReading3);

Array[0] = 0;

Array[1] = potentiometerReading1;

Array[2] = 4;

Array[3] = 6;

radio.write(&Array, sizeof(Array));

delay(20);

Array[0] = 1;

Array[1] = potentiometerReading2;

Array[2] = 4;

Array[3] = 6;

radio.write(&Array, sizeof(Array));

delay(20);

Array[0] = 2;

Array[1] = potentiometerReading3;

Array[2] = 4;

Array[3] = 6;

radio.write(&Array, sizeof(Array));

delay(20);

}

```