Author Topic: Roboduino IR Range Finder, no scan, only view  (Read 3221 times)

0 Members and 1 Guest are viewing this topic.

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Roboduino IR Range Finder, no scan, only view
« on: March 07, 2009, 12:06:51 AM »
I want it so if the robot is close to a wall, it will turn. I just need to know how to set that up, I can get the turning in.

So I am asking, what is the C/C++ code for the IR Range finder to see stuff, and if ______ close it will turn. Thank you guys.

Offline Tomas

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 0
Re: Roboduino IR Range Finder, no scan, only view
« Reply #1 on: March 07, 2009, 04:35:30 AM »
Maybe you should inform us in what robot you are making, what sensors you are using, what microcomputer you are using, how many sensors you got, what code have you already written.
« Last Edit: March 07, 2009, 04:58:59 AM by Tomas »

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Roboduino IR Range Finder, no scan, only view
« Reply #2 on: March 07, 2009, 08:32:39 AM »
You want it using the Arduino libraries?
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #3 on: March 07, 2009, 08:57:23 AM »
I am using Roboduino, a IR Range Finder, only 1 sensor for now, I just want an example for how to make it use the range finder. Just tell me how to make it so if object is so close, it will just stop, I can do the rest. I can hook up turning and all of that.

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: Roboduino IR Range Finder, no scan, only view
« Reply #4 on: March 07, 2009, 09:41:25 AM »
Without the Arduino library:
val = a2dConvert8bit(pin your IR rangefinder is plugged in to);
With the Arduino library I think it's something like this:
val = analogRead(pin your IR rangefinder is plugged into);   
Robots are awesome!

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #5 on: March 07, 2009, 09:44:44 AM »
If I have it hooked up and set to a pin, how will I make it so it knows how far away something is? This is what I have been asking. I want it so if it is so close to something, it will go back. I can make it turn, go back and all of that, but I can't get it so it knows when to do that.

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: Roboduino IR Range Finder, no scan, only view
« Reply #6 on: March 07, 2009, 09:47:19 AM »
When something is close to it, it will return a greater value. When something is farther away it will return a lesser value.
Robots are awesome!

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #7 on: March 07, 2009, 10:09:46 AM »
Will this be right than?

Code: [Select]
#include <Servo.h>
 
Servo left;
Servo right;
 
int posl = 0;
int posr = 0;
 
void setup()
{
  left.attach(9);
  right.attach(10);
  val.analogRead(5);   
}
void loop () {
  if(val >= 1000){
right.write(135);
left.write(45);
}
if(val <= 999){
  right.write(135);
  left.write(45);
}
}

 In function ‘void setup()’:
error: ‘val’ was not declared in this scope In function ‘void loop()’:
« Last Edit: March 07, 2009, 10:11:33 AM by offy »

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Roboduino IR Range Finder, no scan, only view
« Reply #8 on: March 07, 2009, 10:24:54 AM »
The IR range finder is outputting a voltage depending on the distance to the object it detects. If the object is close, it will give you a high voltage, if the object is far, the voltage will get close to zero. You will need to connect the sensor to an analog pin (let's say Analog 0) and send the value that you are reading back to the computer through the serial port (USB) so you can see what value coresponds to the distance you want the robot to steer. After you have that value (treshold), you just make a function that will steer the robot when that sensor value is reached, like this:
Code: [Select]
int value = 0;
int treshold = 125; //change this to the proper value

void setup() {
    Serial.begin(9600); // initialize serial communication with computer
}

void loop() {
   ReadSharpSensor();
}

void ReadSharpSensor () {
   value = analogRead(0); // 0 means the analog pin number, change if you are using a different pin
   if (value > treshold) {
      steerRobot();
   serial.print("sharp value = ");
   serial.print(value, DEC);
   }
}
Check out the uBotino robot controller!

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #9 on: March 07, 2009, 10:38:58 AM »
How will I find the threshhold? I have everything hooked up, connected USB, how do I view the thresholds now?

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: Roboduino IR Range Finder, no scan, only view
« Reply #10 on: March 07, 2009, 10:54:40 AM »
You don't view thresholds, you decide on one yourself. Basically, you must decide what "close" means when how close you are to a wall.

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #11 on: March 07, 2009, 10:56:37 AM »
Is there a way I can put something infront of the IR range finder and it will tell me the threshold value so I dont have to keep on guessing?

This is my code, maybe it is wrong.

Code: [Select]
#include <Servo.h>
Servo left;
Servo right;
int posl = 0;
int posr = 0;
int value = 0;
int treshold = 125;
void setup()
{
  left.attach(9);
  right.attach(10);   
}
void loop() {
ReadSharpSensor();
right.write(45);
left.write(135);
}
void ReadSharpSensor () {
   value = analogRead(5);
   if (value > treshold) {
servoobject();
   }
}
void servoobject () {
  right.write(135);
  left.write(135);
  delay(15);
}

« Last Edit: March 07, 2009, 11:00:01 AM by offy »

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: Roboduino IR Range Finder, no scan, only view
« Reply #12 on: March 07, 2009, 11:17:07 AM »
Get rid of the if loop on the code that Ro-Bot-X posted, and then you will have something that will constantly print out the distance value.

The code you posted, if it sees an object, it will constantly turn and go straight at the same time (that's what you're telling it to do). ReadSharpSensor will make the robot turn if it sees an object, but as soon as it sends a turn signal to the servos, you make it go straight again.

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #13 on: March 07, 2009, 11:26:42 AM »
Will this be right than?

Code: [Select]
#include <Servo.h>
Servo left;
Servo right;
int posl = 0;
int posr = 0;
int value = 0;
int treshold = 120;
void setup()
{
  left.attach(9);
  right.attach(10);   
}
void loop()
{
  ReadSharpSensor();
}
void ReadSharpSensor ()
{
   value = analogRead(5);
   if (value > treshold)
{
   servoobject();
}
   else
{
  move();
}
}
void servoobject () {
  right.write(135);
  left.write(135);
  delay(15);
}
void move()
{
  right.write(45);
  left.write(135);
}

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Roboduino IR Range Finder, no scan, only view
« Reply #14 on: March 07, 2009, 11:43:59 AM »
Yes, that is much better.

Now, if you want to see the values the sensor returns, you have to add to the Setup function the serial port initialization and after you read the value, print it out like I have showned in my prevoius post. After you download the code to Roboduino, keep the USB cable connected and in the Arduino software, open the Serial Monitor (the last button that looks like a rectangle with a circle above it) and disconnect the servos so the robot does not move. Place in front of the sensor an object and look at the computer screen and you will see the value the sensor returns as you move the object farther or closer to the robot. Decide about a safe distance and write that value as the treshold.
Check out the uBotino robot controller!

Offline offyTopic starter

  • Supreme Robot
  • *****
  • Posts: 340
  • Helpful? 1
Re: Roboduino IR Range Finder, no scan, only view
« Reply #15 on: March 07, 2009, 11:54:02 AM »
Nothing shows up... I click the last button, power up my robot (servos unpluged) and it just shows a black box, with a drop down set at 9600 baud and a input box with send.

FIXED. I forgot to add the Serial lines.
« Last Edit: March 07, 2009, 02:36:26 PM by offy »

 


Get Your Ad Here

data_list