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
 ================================================================== 










Monday, October 26, 2015

Robot Controlled by Keyboard

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







Homodruino R2V1


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

// Press the arrows on your keyboard to activate the robot

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

void setup() {
  Serial.begin(9600);              
  pinMode(MLWF, OUTPUT);
  pinMode(MLBB, OUTPUT);
  pinMode(MRYF, OUTPUT);
  pinMode(MRRB, OUTPUT);
}

void loop() {
  if (Serial.available()>0) {        
    int data = Serial.read();          
    switch (data) {
case '1':                   // FWD
    analogWrite(MLBB, 0);    
    analogWrite(MLWF, 255);
    analogWrite(MRRB, 0);    
    analogWrite(MRYF, 255);
    break;
case '2' :              // BCK
    analogWrite(MLBB, 255);    
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 255);    
    analogWrite(MRYF, 0);
    break;
case '3' :                  // LFT
    analogWrite(MLBB, 0);    
    analogWrite(MLWF, 255);
    analogWrite(MRRB, 0);    
    analogWrite(MRYF, 0);
    break;
case '4' :                   // RHT
    analogWrite(MLBB, 0);    
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 0);    
    analogWrite(MRYF, 255);
    break;
case '5':                   // STP
    analogWrite(MLBB, 0);    
    analogWrite(MLWF, 0);
    analogWrite(MRRB, 0);    
    analogWrite(MRYF, 0);
    break;
default :
Serial.println("TYPE the correct NUMBER please");
break;
}
  }
}


PROCESSING SKETCH:

import processing.serial.*;
Serial port;
String Ta= "HOMOTRONICS R2.4";
String Tb= "www.iHackLab.blogspot.com";
String Tc= "Click Here FIRST To START";
String T1= "FWD";
String T2= "RHT";
String T3= "LFT";
String T4= "BCK";
String T5= "STP";
char LETTER = 'S';    //STOP
void setup()
{
  size(300,300);
  println("Please press any ARROW key");
  String portName = Serial.list()[10];
  port = new Serial(this,"COM4",9600);
}

void draw()
{
background(149,201,255);
textSize(20);
fill (0,0,255);
text(Ta, 50, 70);
textSize(10);
fill (0,0,255);
text(Tb, 75, 82);
textSize(10);
fill (0,0,255);
text(Tc, 85, 270);

fill (0,0,255);
rect(155, 180, 55, 55, 7);    //dwn
rect(85, 115, 55, 55,7);      //bck
rect(85, 180, 55, 55,7);      // lft
rect(155, 115, 55, 55,7);     //rht
rect(120, 150, 55, 55,7);     // stp

textSize (15);
fill (0,255,0);
text(T1, 97, 135);      //FWD
text(T2, 170, 135);     //RHT
text(T3, 98, 225);      //LFT
text(T4, 170, 225);     //BCK
text(T5, 137, 182);     //STP
}

void keyPressed()
{
  switch (keyCode) {
    case UP:
    port.write('1');
    fill(33,255,33);
    rect(85, 115, 55, 55,7);
    break;

    case DOWN:
    port.write('2');
    fill(33,255,33);
    rect(155, 180, 55, 55, 7);
    break;

    case RIGHT:
    port.write('3');
    fill(33,255,33);
    rect(155, 115, 55, 55,7);
    break;

    case LEFT:
    port.write('4');
    fill(33,255,33);
    rect(85, 180, 55, 55,7);
    break;

    case 'S':
    case 's':
    port.write ('5');
    fill(33,255,33);
    rect(120, 150, 55, 55,7);
    break;

    default:
    println("press the correct key please");
    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
 ================================================================== 



Saturday, October 24, 2015

HOMOTRONICS

HOMODRUINO®







The iHackRobot series represents a progression of intuitive machines (IM) that have developed over time. These IMs can be programmed to perform various tasks by integrating the knowledge you’ve gained from our previous projects. They can autonomously navigate within a confined space, or be controlled via your keyboard, a TV remote, ethernet, wifi, bluetooth, and other sensors such as light, sound, and line detectors.

Our past projects involving RGB LEDs, IR remote controls, the SR04 ultrasonic finder, the L239D motorshield, the HC-05 bluetooth module, and the Arduino R3 Uno board can all be amalgamated to construct this programmable entity, which I’ve named Homotronics®.

A more advanced task would be to develop a simple, modular sketch for its neurotronic brain that can control its movement range, a feature I’ve termed the SOUL (Spectrum Of Ultrarhythmic Locomotion). The sketch provided below serves as an excellent starting point for instilling SOUL into these robots.

/* ===============================================================
      Project Homotronics: Homodruinos
      Author: J. B. Wylzan with some help from the Arduino community
      Website: http://www.ihackrobot.blogspot.com
      Abstract: Introduction to a simple Homodruino ROM/SOUL Algorithm.
================================================================== */

#define LeftMotorForward 2
#define LeftMotorBackward 3
#define RightMotorForward 4
#define RightMotorBackward 5

//pwm 3,5,6,9,10,11

void setup() {
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorForward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);
}

void loop() { 
  go_forward(); 
    delay(1000); 
      go_stop(); 
  go_right(); 
    delay(3000); 
      go_stop(); 
  go_forward(); 
    delay(1000); 
      go_stop(); 
  go_left(); 
    delay(3000); 
      go_stop(); 
  go_forward(); 
    delay(1000); 
      go_stop(); 
  go_backward(); 
    delay(3000);
      go_stop(); 


void go_forward()                                    //the robot goes forward 
{
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(RightMotorForward, HIGH);
}

void go_backward()                                  //the robot moves backward
{
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(RightMotorBackward, HIGH);
  
}

void go_left()                                        //the robot turns left
{  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
}

void go_right()                                       //the robot turns right
{
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(RightMotorBackward, HIGH);
}

void stop()                                           //the robot stops 
{
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}


/* ================================================================== */
Evolution of Homotronics®:


Homodruino V.1

Homodruino V.2

Homodruino V.3

Homotronics V.4




BiNG - The First Homodruino Robot


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 Intuitive Machines® logos are registered trademarks.
Copyright Biotronics®  Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

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


...

Saturday, October 10, 2015

Arduino Ethernet Shield

How to setup an Ethernet Shield on an Arduino and a Webserver to control an LED:
by J.B. Wylzan


Project 29:  Ethernet Web Server

This project shows how to set up the Arduino Ethernet Shield, 
design a simple HTML code, and use the site to control an LED and a relay.

The Ethernet Shield
The Web Server
The Relay

Hardware:
ethernet shield
relays
leds
resistors
connecting wires
breadboard
Arduino R3 UNO board


Block Diagram:

Replace the servo with a relay instead.

NOTE: Before you try the sketch below , make sure to test your ethernet shield using the example provided  by Arduino.  Go to File > Examples > Ethernet > Webserver.

Code # 29:

/* ===============================================================
      Project #29: 2 Channels 5V Relay Shield
      Author: J. B. Wylzan with some help from the Arduino community
      Website: http://www.ihacklab.blogspot.com
      Abstract: Control relays via an ethernet web server.
================================================================== */

#include <SPI.h>
#include <Ethernet.h>

#define CH1 6
#define CH2 7
#define gLed 8
#define rLed 9

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //Your mac address
byte ip[] = { 192, 168, x, x };                      //Your ip address
byte gateway[] = { 192, 168, x, x };                   //Your gateaway address
byte subnet[] = { 255, 255, x, x };                  //Your subnet address
EthernetServer server(80);                             //Your server port
String readString;

void setup() {

  Serial.begin(9600);
  pinMode(CH1, OUTPUT);  
  pinMode(CH2, OUTPUT); 
  pinMode(gLed, OUTPUT); 
  pinMode(rLed, OUTPUT);
  
  //Provide power to both LEDs
   digitalWrite(gLed, HIGH);
   digitalWrite(rLed, HIGH);
   
   //Turn OFF any power to the Relay channels
   digitalWrite(CH1,LOW);
   digitalWrite(CH2,LOW);
   delay(2000); 
  
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("my server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();
     
        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString = readString + c;
         }
          //if HTTP request has ended
         if (c == '\n') {          
           Serial.println(readString); 
     
           client.println("HTTP/1.1 200 OK"); //start of your HTML
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<!DOCTYPE HTML>");
           client.println("<HTML>");
           client.println("<HEAD>");
          client.println("<TITLE>iHackLab</TITLE>");
           client.println("</HEAD>");
           client.println("<center>");
           client.println("<H1>IHackLab Homotronics Website</H1>");
           client.println("<hr />");
           client.println("<br />");  
           client.println("<H2>Automation using Arduino Ethernet Shield</H2>");
           client.println("<br />");  
           client.println("<a href=\"/stp\"\">Deactivate</a><br />"); 
           client.println("<br />");     
           client.println("<br />"); 
           client.println("<a href=\"/one\"\">Activate Relay 1</a><br />");
              client.println("<br />");   
               client.println("<br />");  
           client.println("<a href=\"/two\"\">Activate Relay 2</a><br />");   
           client.println("<br />"); 
            client.println("<br />");  
           client.println("<a href=\"/bth\"\">Activate Both Relays 1, 2</a><br />");
              client.println("<br />");   
               client.println("<br />");  
           client.println("<br />");   
           client.println("<br />"); 
           client.println("<hr />");
            client.println("www.thearduinosketch.blogspot.com/>"); 
           client.println("<hr />");
           client.println("<br />"); 
             client.println("</center>");
           client.println("</BODY>");
           client.println("</HTML>");   //end of your HTML
     
           delay(1);
           //stopping client
           client.stop();
           
           if (readString.indexOf("one") >0){
               Serial.println("Relay 1");
        digitalWrite(CH1, HIGH);
       delay(1000);
        digitalWrite(CH1, LOW); 
        delay(1000);
    
         
           }
           if (readString.indexOf("two") >0){
                Serial.println("Relay 2");
       digitalWrite(CH2, HIGH);
       delay(1000);
        digitalWrite(CH2, LOW); 
        delay(1000);
           }
           if (readString.indexOf("bth") >0){
                 Serial.println("Relays 1,2");
        digitalWrite(CH1, HIGH);
        delay(1000);
        digitalWrite(CH1, LOW); 
        delay(1000);
        digitalWrite(CH2, HIGH);
        delay(1000);
        digitalWrite(CH2, LOW); 
        delay(1000);
           }
           if (readString.indexOf("stp") >0){
               Serial.println("Deactivate");
         digitalWrite(CH1,HIGH);
         digitalWrite(CH2,HIGH);
         digitalWrite(gLed, LOW);
         digitalWrite(rLed, LOW);
         delay(1000);
           }
            
            readString="";  
           
         }
       }
    }
}
}

/* =============================================================== */

Challenge: 

Make a sketch that will turn On and Off any appliances in your house controlled by your webserver.



Actual Layout:






Procedure:
1. Build the prototype as shown above
2. Run the Arduino Interface
3. Select File > New
4. Copy Code #29 above
5. Paste Code #29
6. Click File > Save
7. Click Verify
8. Click Upload
9. Type your ip address on the url slot
10.  Click On or Off to activate the relay and the led


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
 ==================================================================