Descriere proiect:
Controlul de pe telefon prin bluetooth a motorului pas cu pas NEMA17. Se poate controla direcția și viteza de rotire. Asta o sa ma ajute să opresc sau sa reduc viteza de scanare.
Documentatie proiect:
–Arduino-and-hc-06
Componente:
– Motor NEMA17
– Driver A4988
– Arduino Pro micro
– Cabluri de conectare
– Breadborad
– Suport motor și suport soclu printate 3D
– Bluetooth HC-06 (postari mai vechi legate de bluetooth)
Schema electronica/sistem:
Cod de test:
#include "SoftwareSerial.h"
//Global Variables
// defines pins numbers
const int stepPin = 4;
const int dirPin = 5;
char _btRxData; //Most recent received byte from BT Shield
String _btRxBuff=""; //Local buffer for received data
int speedmot=0;
void setup() {
Serial.begin(57600);
BluetoothInit();
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
//If new byte of data to receive from BT Shield
if(Serial1.available())
{
_btRxData = Serial1.read(); //Read it
_btRxBuff += _btRxData; //Add it to buffer
Serial.print(_btRxData); //Debug: Send to PC Console
if(_btRxData == '1') // Checks whether value of data is equal to 1
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
else if(_btRxData == '0') // Checks whether value of data is equal to 0
digitalWrite(dirPin, LOW); //If value is 0 then LED turns OFF
if(_btRxData == '2') // Checks whether value of data is equal to 2
speedmot +=100; // If value is 2 then increase the motor speed
else if(_btRxData == '3')// Checks whether value of data is equal to 3
speedmot -=100; //If value is 3 then reduce the motor speed
if(_btRxData == 'x') // Checks whether value of data is equal to x
speedmot = 0; // stop the motor
if(_btRxData == 'b')// Checks whether value of data is equal to b
speedmot = 6000; // set the motor speed
if(_btRxData == 'c') // Checks whether value of data is equal to c
speedmot = 60000; // set the motor speed
if(_btRxData == 'p') // Checks whether value of data is equal to p
speedmot = 600; // set the motor speed
if(_btRxData == 't')// Checks whether value of data is equal to t
speedmot = 500; //set the motor speed
}
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(speedmot);
digitalWrite(stepPin,LOW);
delayMicroseconds(speedmot);
}
}
void BluetoothInit()
{
Serial1.begin(57900);
Serial1.print("rn+STWMOD=0rn"); //set the bluetooth work in slave mode
Serial1.print("rn+STNA=SeeedBTSlavern"); //set the bluetooth name as "SeeedBTSlave"
Serial1.print("rn+STOAUT=1rn"); // Permit Paired device to connect me
Serial1.print("rn+STAUTO=0rn"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Serial1.print("rn+LOSSRECONN=0rn");
delay(2000);
Serial1.print("rn+INQ=1rn"); //make the slave bluetooth inquirable
delay(2000); // This delay is required.
Serial1.flush();
}
In următorul pas o sa lipesc toate componentele pe o placa separata cât mai compactă. Apoi în următorul , probabil și ultimul pas, o sa încep sa scanez câteva obiecte, dar o sa am nevoie și de o placa rotunda foarte dreapta pe care obiectele sa se rotească fără a se înclina.
O seara faină tuturor!