Bagaimana saya membuat Snowblower 3.0 dengan kontrol Bluetooth dari smartphone Android

Ini adalah sejarah waktu paling singkat mengubah mesin pemotong rumput robot menjadi peniup salju DIY dengan kontrol Bluetooth dari ponsel Android.




. . , . «» Geektimes, .

. . - . 0.9 .. — - . . . . .



Bluetooth Android . Arduino nano+Monster Motor Shield+Bluetooth HC-06

Bluetooth HC-06 3.3, .. . , .

Monster Motor Shield , - , . , 30.


Arduino


Bluetooth HC-06 Software Serial Serial port. , , Arduino. Bluetooth .
Arduino
#include <SoftwareSerial.h>
#define BRAKEVCC 0
#define CW   1
#define CCW  2
#define BRAKEGND 3
#define CS_THRESHOLD 100

int inApin[2] = {7, 4};  // INA: Clockwise input
int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {5, 6}; // PWM input

int statpin = 10;

SoftwareSerial mySerial(2, 3); // RX, TX
char a,b;

void setup()  
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


 pinMode(statpin, OUTPUT);

  // Initialize digital pins as outputs
  for (int i=0; i<2; i++)
  {
    pinMode(inApin[i], OUTPUT);
    pinMode(inBpin[i], OUTPUT);
    pinMode(pwmpin[i], OUTPUT);
  }
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
    digitalWrite(statpin, HIGH);
    
  if (mySerial.available()){
        a=mySerial.read();

    if(a=='F'){
  motorGo(0, CW, 1023);
  motorGo(1, CW, 1023);
    }
    if(a=='B'){
  motorGo(0, CCW, 1023);
  motorGo(1, CCW, 1023);
    }
    if(a=='L'){
  motorGo(0, CW, 1023);
  motorGo(1, CCW, 1023);
    }
    if(a=='R'){
  motorGo(0, CCW, 1023);
  motorGo(1, CW, 1023);
    }
     if(a=='I'){
  motorGo(0, CW, 500);
  motorGo(1, CW, 1023);
    }
    if(a=='G'){
  motorGo(0, CW, 1023);
  motorGo(1, CW, 500);
    }
    if(a=='H'){
  motorGo(0, CCW, 1023);
  motorGo(1, CCW, 500);
    }
    if(a=='J'){
  motorGo(0, CCW, 500);
  motorGo(1, CCW, 1023);
    }
       if(a=='S'){
  motorOff(1);
  motorOff(2);
    }

    Serial.write(a);
    }else{
      
    }
  
}


void motorOff(int motor)
{
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  analogWrite(pwmpin[motor], 0);
}

void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
  if (motor <= 1)
  {
    if (direct <=4)
    {
      // Set inA[motor]
      if (direct <=1)
        digitalWrite(inApin[motor], HIGH);
      else
        digitalWrite(inApin[motor], LOW);

      // Set inB[motor]
      if ((direct==0)||(direct==2))
        digitalWrite(inBpin[motor], HIGH);
      else
        digitalWrite(inBpin[motor], LOW);

      analogWrite(pwmpin[motor], pwm);
    }
  }
}



Andoid


Google Play . .





bluetooth.
  • «S» —
  • «F» —
  • «B» —
  • «L» —
  • «R» —
  • «I» —
  • «G» —
  • «H» —
  • «J» —

, . , .




1.0 2.0
, . -. , , , ..



P.S.: . X-Prize. :).. 2000$.

The registration deadline is 30 June, 2016 (11:59 PM UTC/4:59 PM PST). The registration fee is $2,000.00 USD.

Source: https://habr.com/ru/post/id388581/


All Articles