Saturday 20 December 2014

Surveillance Robot using Arduino MEGA 2560


Features:


1- Ultrasonic Range Module

2- Motion Detector

3- GPS Tracker

4- Signal Jammer

 5- Camera < To view location through internet > 

6- Grip Tires 

7- Speed Controller Chips <integrated inside >

8- Head LED's < contains BLUE for night view >

9- USB Charging 

10- MEGA Chargeable Batteries


Tuesday 14 October 2014

ANDROID DEVELOPMENT Using Android Studio

Android Studio

The following steps are to be focused while creating a new project.
1. Launch Android Studio and select New Project.
2. Select the form factors your app will run on.
3. Configure you new project.
4. Add an activity to Mobile.
5. Choose options for your new file.

How to create AVD ?
Open AVD Manager. Tools > Andriod 
After opening the AVD Manager , create a new AVD and Set the following
1- AVD Name *whatever doesn't matter
2- Device * Depends on your pc resolution 
3- Target *The API level of your target device
4- CPU * The processing i.e Intel Atom (x86)
5- Keyboard *Check it if you want to use your pc's Keyboard.
6- Skin * Whatever as your taste
7- Memory Options 
  • RAM  *   Depends on your system (PC's RAM) divide it with your pc and avd
  • VM Heap : * Configure it as required .
8- Check Use Host CPU  
Click OK,



Wednesday 9 July 2014

Ultrasonic range module HC-SR04

Hardware Required:

Arduino 
HC-SR04 Ultrasonic Sensor
Blue LED
White LED
560 ohm (Green, Blue, Brown, Gold) Resistors
Breadboard


Connect as Shown Above.
Code:
#define trigPin 13
#define echoPin 12
#define led 11
#define led2 10

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 4) {  // This is where the LED On/Off happens
    digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
  digitalWrite(led2,LOW);
}
  else {
    digitalWrite(led,LOW);
    digitalWrite(led2,HIGH);
  }
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}

Monday 7 July 2014

Stop Watch in JAVA


The following code displays the seconds. Starts from 60 to 1 second.
You can modify the following code as your requirement. The variable delay 1000 means of 1 second..

Code:

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Timer;
import java.util.TimerTask;

public class StopWatch {
static int interval;
static Timer timer;

 public static void main(String[] args) throws UnknownHostException, IOException   {

    System.out.print("Counter : ");
    String secs = "60";

    int delay = 1000;
    int period = 1000;
    timer = new Timer();
    interval = Integer.parseInt(secs);
    System.out.print(" "+secs);
    timer.scheduleAtFixedRate(new TimerTask() {public void run() {System.out.print(" "+setInterval());} }, delay, period);
}

private static final int setInterval() {
   
    if (interval == 2)
        timer.cancel();
    return --interval;
}
}

Ping In JAVA

What is ping ?
If you are having connectivity problems, you can use the ping command to check the destination IP address you want to reach and record the results. The ping command displays whether the destination responded and how long it took to receive a reply. If there is an error in the delivery to the destination, the ping command displays an error message.
You can use the ping command to:
  • Ping your computer (by address, not host name) to determine that TCP/IP is functioning. (Pinging your computer does not verify that your network adapter is functioning.)
  • Ping the local router to determine whether the router is running.
  • Ping beyond your local router.
JAVA Code


import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Ping {
    public static void main(String[] args) throws UnknownHostException, IOException   {
    Scanner in = new Scanner(System.in);
    String ipAddress ;
    System.out.print("Enter Ip to Ping: ");
    ipAddress=in.nextLine();
    InetAddress inet = InetAddress.getByName(ipAddress);
    for(int i=1;i<201;i++){
    System.out.print(i +"- "+ "Sending Ping Request to " + ipAddress);
    System.out.println(inet.isReachable(5000) ? "  Host is reachable" : "  Host is NOT reachable");}}

}

Note: This code will ping the ip address entered by user upto 200 times.

Sunday 6 July 2014

Arduino Run DC Motor

Hardware Required:
1-Small 6V DC Motor 
2-PN2222 Transistor 
3-1N4001 diode 
4-270 Ω Resistor (red, purple, brown stripes) 
5-Breadboard 
6-Arduino Uno R3 
7-Jumper wire pack

Breadboard Layout
When you put together the breadboard, there are two things to look out for.
Firstly, make sure that the transistor is the right way around. The flat side of the transistor
should be on the right-hand side of the breadboard.
Secondly the striped end of the diode should be towards the +5V power line 
The motor can be connected either way around.

Run The Following Code on Arduino IDE:

int motorPin = 3;
void setup()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255)
{
analogWrite(motorPin, speed);
}
}
}

Arduino Multiple lights Blink

Connect Led's To pin 13,12 and 11 + GND each
Run the following code on Arduino
int led = 13;
int led2 = 12;
int led3 = 11;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT); 
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100); 
  {digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);}
{digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(100);}// wait for a second
}

Augmented Reality with Processing

Steps to follow:

1-Processing 1.5.1 Click Here
2-NyArtoolkit for Processing 1.1.6 Click here
3-GSVideo 1.0.0 Click here
4-Patterns Click here

Install processing in Operating System. Download NyArtoolkit for processing and copy it in documents > processing > libraries... as a contributed libraries. Same procedure with GSVideo. Download patterns and unpack them.
Restart Processing.....
Run the following code:

import java.io.*; // for the loadPatternFilenames() function
import processing.opengl.*; // for OPENGL rendering
import jp.nyatla.nyar4psg.*; // the NyARToolkit Processing library
// a central location is used for the camera_para.dat and pattern files, so you don't have to copy them to each individual sketch
// Make sure to change both the camPara and the patternPath String to where the files are on YOUR computer
// the full path to the camera_para.dat file
String camPara = "C:/Users/mainframe/Documents/Processing/libraries/nyar4psg/data/camera_para.dat";
// the full path to the .patt pattern files
String patternPath = "C:/Users/mainframe/Documents/Processing/libraries/nyar4psg/patternMaker/examples/ARToolKit_Patterns";
// the dimensions at which the AR will take place. with the current library 1280x720 is about the highest possible resolution.
// it will work just as well at a lower resolution such 640x360, in some case a lower resolution even seems to work better.
int arWidth = 1280;
int arHeight = 720;
// the number of pattern markers (from the complete list of .patt files) that will be detected, here the first 10 from the list.
int numMarkers = 10;
MultiMarker nya;
float displayScale;
color[] colors = new color[numMarkers];
float[] scaler = new float[numMarkers];
PImage input, inputSmall;
void setup() {
size(1280, 720, OPENGL); // the sketch will resize correctly, so for example setting it to 1920 x 1080 will work as well
// create a text font for the coordinates and numbers on the boxes at a decent (80) resolution
textFont(createFont("Arial", 80));
// load the input image and create a copy at the resolution of the AR detection (otherwise nya.detect will throw an assertion error!)
input = loadImage("input.jpg");
inputSmall = input.get();
inputSmall.resize(arWidth, arHeight);
// to correct for the scale difference between the AR detection coordinates and the size at which the result is displayed
displayScale = (float) width / arWidth;
// create a new MultiMarker at a specific resolution (arWidth x arHeight), with the default camera calibration and coordinate system
nya = new MultiMarker(this, arWidth, arHeight, camPara, NyAR4PsgConfig.CONFIG_DEFAULT);
// set the delay after which a lost marker is no longer displayed. by default set to something higher, but here manually set to immediate.
nya.setLostDelay(1);
String[] patterns = loadPatternFilenames(patternPath);
// for the selected number of markers, add the marker for detection
// create an individual color and scale for that marker (= box)
for (int i=0; i nya.addARMarker(patternPath + "/" + patterns[i], 80);
colors[i] = color(random(255), random(255), random(255), 160); // random color, always at a transparency of 160
scaler[i] = random(0.5, 1.9); // scaled at half to double size
}
}
void draw() {
background(0); // a background call is needed for correct display of the marker results
image(input, 0, 0, width, height); // display the image at the width and height of the sketch window
nya.detect(inputSmall); // detect markers in the input image at the correct resolution (incorrect resolution will give assertion error)
drawMarkers(); // draw the coordinates of the detected markers (2D)
drawBoxes(); // draw boxes on the detected markers (3D)
}
// this function draws the marker coordinates, note that this is completely 2D and based on the AR dimensions (not the final display size)
void drawMarkers() {
// set the text alignment (to the left) and size (small)
textAlign(LEFT, TOP);
textSize(10);
noStroke();
// scale from AR detection size to sketch display size (changes the display of the coordinates, not the values)
scale(displayScale);
// for all the markers...
for (int i=0; i // if the marker does NOT exist (the ! exlamation mark negates it) continue to the next marker, aka do nothing
if ((!nya.isExistMarker(i))) { continue; }
// the following code is only reached and run if the marker DOES EXIST
// get the four marker coordinates into an array of 2D PVectors
PVector[] pos2d = nya.getMarkerVertex2D(i);
// draw each vector both textually and with a red dot
for (int j=0; j String s = "(" + int(pos2d[j].x) + "," + int(pos2d[j].y) + ")";
fill(255);
rect(pos2d[j].x, pos2d[j].y, textWidth(s) + 3, textAscent() + textDescent() + 3);
fill(0);
text(s, pos2d[j].x + 2, pos2d[j].y + 2);
fill(255, 0, 0);
ellipse(pos2d[j].x, pos2d[j].y, 5, 5);
}
}
}
// this function draws correctly placed 3D boxes on top of detected markers
void drawBoxes() {
// set the AR perspective uniformly, this general point-of-view is the same for all markers
nya.setARPerspective();
// set the text alignment (full centered) and size (big)
textAlign(CENTER, CENTER);
textSize(20);
// for all the markers...
for (int i=0; i // if the marker does NOT exist (the ! exlamation mark negates it) continue to the next marker, aka do nothing
if ((!nya.isExistMarker(i))) { continue; }
// the following code is only reached and run if the marker DOES EXIST
// get the Matrix for this marker and use it (through setMatrix)
setMatrix(nya.getMarkerMatrix(i));
scale(1, -1); // turn things upside down to work intuitively for Processing users
scale(scaler[i]); // scale the box by it's individual scaler
translate(0, 0, 20); // translate the box by half (20) of it's size (40)
lights(); // turn on some lights
stroke(0); // give the box a black stroke
fill(colors[i]); // fill the box by it's individual color
box(40); // the BOX! ;-)
noLights(); // turn off the lights
translate(0, 0, 20.1); // translate to just slightly above the box (to prevent OPENGL uglyness)
noStroke();
fill(255, 50);
rect(-20, -20, 40, 40); // display a transparent white rectangle right above the box
translate(0, 0, 0.1); // translate to just slightly above the rectangle (to prevent OPENGL uglyness)
fill(0);
text("" + i, -20, -20, 40, 40); // display the ID of the box in black text centered in the rectangle
}
// reset to the default perspective
perspective();
}

// this function loads .patt filenames into a list of Strings based on a full path to a directory (relies on java.io)
String[] loadPatternFilenames(String path) {
File folder = new File(path);
FilenameFilter pattFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".patt");
}
};
return folder.list(pattFilter);
}
Pattern Look like that..