Monday, March 28, 2011

Arduino IR Distance Sensor UPDATE


Recently I’ve been trying to make my IR distance sensor look like real sensor. I’ve created it from small piece of protoboard and male headers. It’s still just Beta I’ve had some issues with it, but now it seems that it works good. [Update 22 July 2012] I have added picture of circuit.



Sunday, March 13, 2011

Arduino IR distance sensor

For a long time I’ve been trying to create some sort of robot, to accomplish that I need a bunch of different sensors. One of the big problems for me was a distance sensor.


I’ve found PING ultrasonic sensor, but it’s almost impossible to get one in my county. So I’ve been looking for a cheap solution. I’ve decided to use 2x IR LEDs one receiver and one transmitter.  Transmitter transmits for human invisible IR light it bounces from the object and returns to the receiver. Receiver it’s hooked up to an analog pin on the arduino. At first I’ve made measurements and then I’ve made equation based on which  you can get distance in centimeters.




Code for Arduino :

int IRSense = A0;
int IRTrans = 2;
int valueAmbient = 0;

void setup()
{
pinMode(IRSense, INPUT);
pinMode(IRTrans, OUTPUT);
Serial.begin(9600);
digitalWrite(IRTrans,LOW);
}

void ambient()
{
digitalWrite(IRTrans,HIGH);
delay(20);
valueAmbient = analogRead(IRSense);
delay(20);
}

void loop()
{
ambient();
digitalWrite(IRTrans,LOW);
delay(20);
int value = analogRead(IRSense);
int value2 = round(value - valueAmbient);
int dist = (((value2+15.0)/(value2*(value2+100.0)))*2000.0);
Serial.print(dist);
Serial.print("cm.");
Serial.println("");
delay(20);
}


Code for Processing :

import processing.serial.*;
Serial Port;
String distance ="";
String data ="";
int index = 0;
PFont font;

void setup()
{
size(500,500); 
Port = new Serial(this, "COM3", 9600);
Port.bufferUntil('.');
font = loadFont("AgencyFB-Bold-200.vlw");
textFont(font, 200);
}

void draw()
{
background(0,0,0);
fill(200,0,0);
text(distance,50,300);
}

void serialEvent (Serial port)
{
data = port.readStringUntil('.');
data = data.substring(0, data.length() - 1);
distance = data;
}

Thursday, March 3, 2011

RGB Mixer

Hi there today I will show you project with which I’ll be attending a competition. I hope I’ll be choosed for a grand final. It’s a RGB mixer and it’s a toolkit for teaching how RGB color mixing works. So I hope you’ll like it.