Tuesday, November 24, 2015

Bluetooth Control Experiment


the accelarometer is actually a bluetooth module




ARDUINO SKETCH:

/* ===============================================================
      Project Homotronics: Robot controlled by bluetooth
      Author: J. B. Wylzan with libraries from the Arduino website
      Website: http://www.iHackRobot.blogspot.com
      Abstract: Control a robot via bluetooth.
================================================================== */

int IN1 = 6; 
int IN2 = 5;  
int ENA = 4;  
int mode;
int key=0;        

void setup() {
   
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    //pinMode(ENA, OUTPUT);
    // digitalWrite(ENA, HIGH);
  
    Serial.begin(9600);
}

void loop() {
     
    if(Serial.available() > 0){     
      mode = Serial.read();   
      key=0;
    }   
    
    if (mode == '0') {
          analogWrite(IN1, 0);        
          analogWrite(IN2, 0);
        if(key== 0){
            Serial.println("Pressed 0");
            Serial.println("Stopping");
            Serial.println("Blinking Red");
          key=1;
        }
    }
    
    else if (mode == '1') {
       analogWrite(IN1, 0);        
       analogWrite(IN2, 255);
        if(key== 0){
           Serial.println("Pressed 1");
           Serial.println("Moving forward");
           Serial.println("Blinking Green");
          key=1;
        }
    }
    
    else if (mode == '2') {
        analogWrite(IN1, 255);        
        analogWrite(IN2, 0);
        if(key== 0){
            Serial.println("Pressed 2");
            Serial.println("Moving reverse");
            Serial.println("Blinking Yellow");
          key=1;
        }
    }

}

/* ================================================================== */
*** Warning ***
1. Remove the RX and TX cables when uploading the sketch.
2. Connect TX to RX and RX to TX.


 ==================================================================
"Everything has only two options: this or that." 
~ Joey Lawsin
==================================================================

NOTICE: Articles on this site are composed on random thoughts. The transcript may not be in its final form. It maybe edited, updated or even revised in the future based on the outcomes of  the author's experiments.

Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled Biotronics: The Silver Species. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: The Biotronics Project, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®
 ==================================================================





No comments:

Post a Comment