搜索代码

Control One or More Servo Motors with an ESP32 Bluetooth Mobile Device: Move-Return EESP32-SERV-BT-3

Control One or More Servo Motors with an ESP32 Bluetooth Mobile Device: Move-Return EESP32-SERV-BT-3

This video shows how to control one or more servo ESP32 Microcontroller and Bluetooth to move it from 0° to 180° or from 180° to 0° and return or set your own valuesYou need to download the libary specifically work with ESP32 Arduino IDE. The link to use in the "preferences" of Arduino IDE for ESP32 board https://dl.espressif.com/dl/package_esp32_index.json Watch video for instructions.
286-Resources for this sketch
语言: C++
++
/*
 * Original Servo Library source: https://github.com/RoboticsBrno/ESP32-Arduino-Servo-Library
 * 
 * This is Arduino code to control a servo motor with ESP32 boards over Bluetooth.
 * EESP32-SERV-BT-3
 * Watch video instructions for this code: https://youtu.be/39e4V0-GCgo
   
 * Written/updated by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
 * Date: January 05, 2019, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purposes only.
 * This code has been downloaded from https://robojax.com
 
 * Get this code and other Arduino codes from Robojax.com.
 * Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
 * all in one place. 

****************************
Get early access to my videos via Patreon and have your name mentioned at the end of every 
video I publish on YouTube here: http://robojax.com/L/?id=63 (watch until the end of this video for a list of my Patrons)
****************************

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include <Servo_ESP32.h>

static const int servo1Pin = 19; //printed G19 on the board

Servo_ESP32 servo1;
const char turnON ='a';
const int type =2;//watch video for details. Link is at the top of this code (robojax)

int servo1Angle =90;
int servo1AngleStep =10;

int servo1AngleMin =0;
int servo1AngleMax = 180;

int buttonPushed =0;
char receivedChar;// received value will be stored as CHAR in this variable

#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_Robojax"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth\n with ESP32_Robojax");
  
    servo1.attach(servo1Pin);
    //Servo control using ESP32 from Robojax.com

}

void loop() {
  //Robojax.com ESP32 Servo BT code
    receivedChar =(char)SerialBT.read();

  if(receivedChar == turnON){
    buttonPushed = 1;
  }
  
   if( buttonPushed ){
       servo1Angle += servo1AngleStep;
       // reverse the direction of the moving at the ends of the angle:
        if (servo1Angle >= servo1AngleMax) {
          servo1AngleStep = -servo1AngleStep;
            if(type ==1)
            {
                buttonPushed =0;                   
            }
        }
        
        if (servo1Angle <= servo1AngleMin) {
          servo1AngleStep = -servo1AngleStep;
           if(type ==2)
            {
                buttonPushed =0;       
            }
        }
     SerialBT.print("Moving to:");// write on BT app
     SerialBT.println(servo1Angle);// write on BT app 
    Serial.print("Moving to:");//print on Serial Monitor
    Serial.println(servo1Angle); //print on Serial Monitor     
                  
   }//if pushed
   
   servo1.write(servo1Angle);
   delay(20);

}

资源与参考

尚无可用资源。

文件📁

没有可用的文件。