Wednesday, November 11, 2015

Robot controlled by Bluetooth

How to build a Robot on an Arduino that can be controlled using a Bluetooth:
by J.B. Wylzan

the accelarometer is actually a bluetooth module




ARDUINO SKETCH:

/* ===============================================================
      Project Homotronics: Robot controlled by bluetooth
      Author: J. B. Wylzan with some help from the Arduino community
      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.


//* HC06 bluetooth sensor with the relay


int relay = 8; 
void setup()
{
   Serial.begin (9600); 
   pinMode(relay,OUTPUT); 
 }
void loop()
{
   char val,mVal; 
  val = Serial.read(); 
  mVal=val;
  if (mVal=='1' ) 
 {
   digitalWrite(relay,HIGH); 
  }
  if(mVal=='0')  
  {
    digitalWrite(relay,LOW); 
  }
 }


//* HC06 bluetooth sensor w/o the relay

void setup()
{
   Serial.begin (9600); 
 }
void loop()
{
   char mVal;
  mVal= Serial.read(); 
  
if ((mVal>='a'&& mVal<='z') || (mVal>='A'&& mVal<='Z'))
  {
    Serial.println(mVal); 
  }


 }  */

// Processing: watch2PFNL
// Click on the image to give it focus,
// and then press any key.

import processing.serial.*; 

Serial port;                       // Create object from Serial class

void setup() { 
  size(100, 100); 
  noStroke(); 
  frameRate(10); 
  // Open the port that the board is connected to and use the same speed (9600 bps)
  port = new Serial(this,"COM#",9600); 

int value = 0;

void draw() {
  fill(value);
  rect(25, 25, 50, 50);
}

void keyPressed() 
{
  
   switch (keyCode) {   
    case 'J':
    value = 255;
    port.write('1');
    break;
    
    case 'L':
    value = 0;
    port.write('2');
    break; 
    
   }
}



Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

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

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

L.A.W.S.I.N. Educational Production
 ================================================================== 






Wednesday, November 4, 2015

Robot controlled by Sonar

How to build a Robot on an Arduino that can be controlled by an ultrasonic sensor:
by J.B. Wylzan




ARDUINO SKETCH:

/* ===============================================================
      Project Homotronics: Robot controlled by Sonar
      Author: J. B. Wylzan with some help from the Arduino community
      Website: http://www.ihackrobot.blogspot.com
      Abstract: Control a robot via an ultrasonic sensor.
================================================================== */

#define trigPin 12
#define echoPin 11
#define IN1 10
#define IN2 9
const int redLed = 6;     
const int greenLed = 7;   
const int yellowLed = 8;  

// ENABLE PWM 3,5,6,9,10,11

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);    
  pinMode(echoPin, INPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
    pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 pinMode(yellowLed, OUTPUT);
}

void loop() {
  long time, range;
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(2);   //2
  digitalWrite(trigPin, LOW);

  time = pulseIn(echoPin, HIGH);
  range = (time/2)/29.1;    //58.2

  if (range < 20)
  {
    analogWrite(IN1, 0);        
    analogWrite(IN2, 255);
   
    Serial.println("Moving forward");
    Serial.println("Blinking Green");
     Serial.print(range);
    Serial.println(" cm");

 //   delay(1000);
  //  digitalWrite(redLed, HIGH);
//delay(1000);
//digitalWrite(redLed, LOW);
  }
  else        
    {
        analogWrite(IN1, 255);   
        analogWrite(IN2, 0);      
       
        Serial.println("stopping");
         Serial.println("Blinking Red");
          Serial.print(range);
    Serial.println(" cm");

     // digitalWrite(yellowLed, HIGH);
//delay(1000);
//digitalWrite(yellowLed, LOW);                                         
    } 
}





Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

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

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

L.A.W.S.I.N. Educational Production
 ================================================================== 




Wednesday, October 28, 2015

Robot Controlled by a TV Remote

How to build a Robot on an Arduino that can be controlled by a TV remote:
by J.B. Wylzan
Peanutz : My Robotic Dog







ARDUINO SKETCH:

/* ===============================================================
      Project Homotronics: Robot controlled by a TV remote
      Author: J. B. Wylzan with some help from the Arduino community
      Website: http://www.ihackrobot.blogspot.com
      Abstract: Control a robot via a TV remote control.
================================================================== */

#include <IRremote.h>

const int MLWF = 10;         
const int MLBB = 9;
const int MRYF = 6;         
const int MRRB = 5;

// The codes below were generated from our Project the Infra Red Sensor.
const long lft = 0x4EB338C7;    
const long fwd = 0x4EB322DD;    
const long rht = 0x4EB312ED;    
const long rvs = 0x4EB3B847;    
const long stp = 0x4EB33AC5;    

IRrecv irrecv(IR_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();        // turn on the receiver
  pinMode(MLWF, OUTPUT);
  pinMode(MLBB, OUTPUT);
  pinMode(MRYF, OUTPUT);
  pinMode(MRRB, OUTPUT);}

void loop() {
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    Serial.println(decCode);
    
    switch (results.value) {
      case lft:
        Serial.println("Left");
       analogWrite(MLBB, 0);     
    analogWrite(MLWF, 255);
    analogWrite(MRRB, 0);     
    analogWrite(MRYF, 0);   
        break;
        
      case fwd:
        Serial.println("Forward");
        analogWrite(MLBB, 0);     
    analogWrite(MLWF, 255);
    analogWrite(MRRB, 0);     
    analogWrite(MRYF, 255);          break;
        
      case rht:
        Serial.println("Right");
         analogWrite(MLBB, 0);     
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 0);     
    analogWrite(MRYF, 255);  
        break;
        
      case rvs:
        Serial.println("Reverse");
         analogWrite(MLBB, 255);     
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 255);     
    analogWrite(MRYF, 0);        break;  
        
      case stp:
        Serial.println("Stop");
        analogWrite(MLBB, 0);     
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 0);     
    analogWrite(MRYF, 0); 
        break;  
        
      default: 
        Serial.println("Press a key ...");
    }

    irrecv.resume();  
  }

}



PEANUTZ


Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

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

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

L.A.W.S.I.N. Educational Production
 ==================================================================