Show Posts
Pages: [1]
1  Topics / Robotics / Re: simple two position servo on: May 10, 2011, 12:14:32 pm
The reassessment of ir value is to prevent servo action if value does not persist after delay.

The code you posted doesn't re-read the I/O pin, so the value in the IRvalue variable will not have changed between the two if statements. (This is a common mistake in Arduino programming, treating the variable that holds an I/O value the same as the I/O itself.)

If you're posting code fragments, and merely left out the part where you re-read the pin, it's best to include all the relevant code. Otherwise it's not possible to see how the sketch will work.

-- Gordon
2  Topics / Robotics / Re: simple two position servo on: May 09, 2011, 04:55:17 pm
if (IRvalue < 3) {                                         //sensor output went low  TRIGGERED
    delay (6000);                                         // wait a  while for validation that rattie is munching

I assume you're posting code fragments, which makes it a bit hard to follow. But in any case, you're testing for (IRvalue < 3) twice, one right after the other. You only need one, unless you're re-establishing IRvalue with a new reading.

Maybe your rats are slower eaters than the ones that bother our house, but in six seconds ours will have gone in, got the food, and run back out. Remember that because of the way the delay statement works for those six seconds the Arduino is a hung process, and doesn't do anything else.

Here's where you may want to delay for 500 or 1000 milliseconds at a time, each time re-reading the input to check if the rat is still eating. Assuming 1000 delays, you'd repeat that loop six times. You still have a six second total delay, but each second you're re-reading the input and can more quickly act upon a change.

-- Gordon
3  Topics / Robotics / Re: simple two position servo on: May 05, 2011, 01:56:37 pm
The GP2Y0D80's are more consistent than the older style, and they update at about 300 Hz, giving better accuracy.

As these aren't expensive, even on the breakboard boards that Pololu provides, have you considered using two? One for when the rat enters, and one when it's at the feeding area. You could use the two to pretty much eliminate any false triggers, and it (I would think) avoid the problems of having to use a delay.

In any case, a simple delay when the sensor hits its trigger point ought to do it. You shouldn't have to use the counter. Simply:

read IR sensor
is rat there? {
  rotate servo

The nnn for delay is whatever you want to make it. A couple seconds perhaps? So delay(2000); will give a two second delay once the IR sensor has detected said rat.

-- Gordon
4  Topics / Robotics / Re: simple two position servo on: May 04, 2011, 11:33:33 am
I'm having trouble visualizing your setup if what you're doing is trying to close a bait trap after the rat has come all the way in.

First thing I'd do is replace the IR sensor, which can be be unreliable, with a force sensitive resistor like this one:

Place the sensor right at the bait. Connect it between 5V and Gnd in series with a resistor (play with the value of the resistor to get good sensitivity for the weight of the average ravenous rat; start with perhaps 100k and go from there). Connect the output to an analog pin. (For a hookup example use a photoresistor circuit; the concept is exactly the same -- you are converting a resistance to a voltage.)

In the setup() function, set up your servo object, rotate the servo to open the trap, and detach it. If you don't the slight "throbbing" of the servo will cause the rat to run away.

In the loop() function wait for the value to drop to indicate the rat is at the bait. Then close the trap in one swift move.

In pseudocode

setup() {
  define Servo object
  attach object to servo pin
  rotate servo to open trap
  delay one second for full transit
  detach servo

loop {
  read analog input
  is rat on sensor? {
     re-attach servo
     rotate to close trap

The LED code you can add later. I'd not worry about the arc of the servo; rather define the values you need to open and close the trap door. Depending on the mechanics you may not need anything close to the full 180-200 degree arc of the servo.

In any case, you don't really need delays beyond the first one. Be sure to keep the servo attached (energized) after the trap has been sprung, or work up a locking mechanism to keep the door shut.

Anyway, this is how I envision a rat trap might be set up.

-- Gordon

5  Topics / Robotics / Re: Mr General Robot wiring on: May 04, 2011, 11:19:15 am
The Uno doesn't have enough analog pins to support that layout. The Uno has six analog inputs, and you'll need eight, in order to connect the four photo transistors from the compound eye, and the four LDRs for the corner sensors.

You'll need to either use an Arduino Mega, or add an analog multiplexer, such as the 74HC4067, to expand the number of analog inputs available to you.

The Arduino uses very straightforward pinout identification, and what you posted shows exactly what to connect (except for the fact there is no analog A6 or A7 on an Uno). Read up on the hardware reference at

as it explains what all the pins do, and how they are named.
6  Using Arduino / General Electronics / Re: if i accidentally drop my arduino on water.... on: May 01, 2011, 11:47:45 am
A squirt with some dewatering fluid such as WD40 might help after the event but you will end up with a sticky circuit board. 

While I'm always keen to promote WD-40 as a way to help the local San Diego economy, I learned long ago it's a bad choice for complex PCBs, especially those with socketed parts. Over time the connections get poor.

The best and SAFEST way to dispel water from a small electrical device is to put it in a bowl of new, clean, dry white rice. After a day the rice will have absorbed all of the moisture. The same technique "fixes" cell phones dropped into the sink, but won't remove the red mark from the moisture label!
7  Topics / Robotics / Re: simple two position servo on: May 01, 2011, 11:27:09 am
Good to know you're having success. Just a couple of points about the code.

You've duplicated the lines


twice within the if block. You might want to delete these and have just one, right after you've read the IR value. These kinds of consolidations can make the code easier to track as you try different values.

You have some extremely long delays waiting for the servo to transit. Are these really necessary or are you adding additional waiting time for demonstration purposes? Example: you have one specifying a delay of over two seconds


Following this is a servo position value that looks extraordinarily out-of-bounds for most any servo:


What kind of servo is this? Standard, sail winch, something else?

Some servos will accept out-of-bound limits to prevent internal damage, and I wonder if yours is doing that, giving you a false impression of the usec values you should be using. A more common lower and upper limit is along the lines of 650 us to 2400 us, and even these are outside some brands of servos.
8  Topics / Robotics / Re: how can i create a program for a 6v motor on: May 01, 2011, 11:14:34 am
Simplify your sketch and try one thing at a time.

First create a sketch that just runs the motor back and forth. Get that working before going to the next step

Then create another sketch that reports the IR status on the Serial Monitor window. Get that working.

Now you can combine the two.

Without getting into the sketch itself, your problem could be just about anything, so you need to take things one step at a time, and verify that the parts of your scheme work as expected. Maybe you're not using the right type of IR remote for the codes you're looking for. Who knows.
9  Using Arduino / General Electronics / Re: tlc5940 and hs422 on: April 26, 2011, 04:08:49 pm
Have you tried playing with the constants in tlc_servos.h? Looks like there's quite a bit of latitude for adjusting to particular servo models.

-- Gordon
10  Using Arduino / General Electronics / Re: Arduino resetting when running 2WD platform, why? on: April 26, 2011, 03:56:04 pm
Since you're already running the motors from their own supply I'd look at these things:

1. Noise from the motors. Try adding .1 uF caps across the motor terminals (right AT the terminals).

2. Verify that your bridge can provide enough current to the motors. (Please indicate the bridge you are using so folks don't have to guess whether that's the culprit.)

3. You should have a shared 5V line between the Arduino and the bridge (that provides logic power to the bridge), and a shared ground. Ground from your 5 AAs should connect to the bridge, not to the Arduino. Some bridges will parasitically draw current from the motor power for their logic supply if the V+ logic line is left unconnected. That can cause weird behavior.

4. Use a fresh 9-volt battery for the Arduino. When these things deplete they can put out some volts, but very little current.

A full diagram of the connection you're actually using would be helpful.

-- Gordon
11  Using Arduino / Sensors / Re: Wheel Encoders for complet newbies on: April 21, 2011, 04:39:07 pm
Using a treaded base you won't get a lot of accuracy in turns even with an encoder (though the encoder won't hurt if it's there). The agility in turns for a tank-type robot depends on the surface it's going over. The rubber treads used on this kit -- and many like it -- is very compliant, meaning it literally sticks to hard surfaces. That means it may skate unpredictably if the tread simply skips over the surface in turns.

Over carpet and other slippery surfaces the treads won't skate, but the amount of turn is very hard to determine.

You can still play and experiment using the kit you have, but the turns will seldom be as accurate as what you may be looking for. Instead of worrying about odometry, maybe apply a different type of project. A line or wall follower doesn't need encoders, for example.

12  Topics / Robotics / Re: simple two position servo on: April 21, 2011, 04:20:16 pm
The Part 3 (from the ArdBot series in SERVO Magazine) example code shows attaching and detatching. Get it here:

Simplify your tests by initially including only the servo code. The example "exercises" a servo from one end to the other.

A couple of things about your code:

1. When you create a new servo object its position gets set to 90 (or 1500 microseconds). You can change the initial position with servo.write. You don't have to attach it first.

2. Be sure you delay long enough to the next statement for the servo to transit where you want it to go.

3. You need to re-read the value of your IR pin each time in the loop. You have it as:

 if (IRval == HIGH)

which only checks what you put into the IRval previously, outside the loop. Since the variable will never change your servo will not move.

4. You don't need to set servo pins as OUTPUTs, as the class does that implicitly.

5. When in idle mode standard (non-converted) servos don't consume a lot of current. One good use of the detach method is when you have servos converted to continuous rotation. By detatching the servo won't creep, which can be the case if their center points drifts from the usual 1500 usec.
13  Topics / Robotics / Re: Where to find a guide to build a simple robot? on: April 15, 2011, 03:34:23 pm
I've been in lurk mode for a year, and it's nice to finally be able to come out from under my rock (yes, I've been working on the book for that long!)

@cr0sh, if you wouldn't mind, send me an email at the contact listed on the Robotoid site. I'd like to send you some advance material that might interest you.

Anyway, yes, the original TAB format had its particular advantages. They partly did it that way to save pages. Two-column layouts take longer to do, so they try to avoid them when possible. I notice they still use it on their Evil Genius books, though that's also in large format.

@Terry, Thanks for the kind words!

-- Gordon
14  Topics / Robotics / Re: Where to find a guide to build a simple robot? on: April 15, 2011, 12:15:05 pm
Caught this thread and thought I might reply.

Indeed, the fourth edition of Robot Builder's Bonanza is due out soon, but the details about it on Amazon are very out of date. They should be updating it (and the cover, which is completely different) pretty soon, but in a nutshell, cr0sh is correct that it drops a bunch of old stuff to make room for new stuff -- specifically Arduino (yeah!!) and some PICAXE.

RBB4 isn't an Arduino-specific book (doing one of those now), but it has numerous code examples for Arduino, and relies on it as the primary processor for the various projects involving a microcontroller. Pretty soon I'll be able to post an updated table of contents on my site, but I have to wait until the publisher "goes live" with their version first.

Looks like Robotshop is reprinting the whole series of SERVO Magazine ArdBot articles, though trailing a few issues back. The series is up to Part 6 in the magazine (out of seven parts), but RobotShop has just the first four at the moment. They're listed here:

under the Electronics heading. My guess is that eventually they'll have all seven.

Be sure to also visit my Web site at robotoid. com for ArdBot construction notes and errata.

-- Gordon
Pages: [1]