I'm looking to build an autonomous robot car, but needed to set it a difficult problem beyond following a line or avoiding edges. I've settled on getting it to learn to collect objects and drop them off in a fixed area, initially unknown to the robot. The obvious mechanism seems to use a magnet and for the objects to be small iron objects, nails perhaps or small polystyrene blocks tagged with iron tags. The magnet needs to be switchable so the iron can be collected and later dropped off.

First of all I need an electro-magnet controlled by a RPi on battery power only. Secondly, I need to know when the magnet has picked up an object.

The first is obviously a purchasable item, but I haven't found anything suitable. Secondly, I need a sensor to tell when it has collected an item.

Advice please?

  • 1
    I found a bunch of small magnets with a very simple search. If none is suitable, you can make your own with an iron core and enameled copper wire. I expect the nature of the magnetic field will change when your magnet is holding an object, and there are small, inexpensive magnetometers. Some experimentation would be required. – Bob Brown Apr 8 at 13:18
  • 2
    One word of warning: Don't power the magnet through the Pi. When the magnet is turned off, the energy stored in the collapsing magnetic field is transferred to the windings as inductive voltage; that can fry your Pi. Use a separate power supply, a relay, and a flyback diode. – Bob Brown Apr 8 at 13:18

You could put a "force sensitive resistor"(7usd on adafruit) on the face of the magnet that will make contact with the picked up object. If the magnet has successfully attached to the object the pressure sensor will read it. I have never experimented with one of those so i have no idea if the magnetic field would collapse it when activated and read a false event, but i imagine the magnetic field of your magnet should be able to pick up a relatively light object through the pressure sensor on it. They also have several elctromagnets in their website also fairly cheap (around 8usd) You will need to connect it to a motor selenoid driver to protect your pi as Bob mentioned

| improve this answer | |

To sense when you have picked something up, my choice would be mechanical ( that is, a microswitch ), or a reflective eye; OR, use an AC electromagnet on a "U" core, might be able to tell by the current draw, but you should be able to tell by using a second winding ( one on each side of the "U" ) and reading voltage on that. Note that DC electromagnets tend to become magnetized which sometimes makes dropping things tricky.

| improve this answer | |

To "control" the magnet you can either use a transistor (rated for the current you need) or any DC motor driver. They are easy to use and still relatively cheap. They also have protective free run diods so I would go for that. I actually implemented this years ago with a DC h-bridge something like this . That way you can switch the external(!) voltage to the magnet on with the RPi.

To sense if you picked something up that depends on what you have as sensors. Easiest are micro switches. When you have the magnet implemented maybe it is possible to sense a pickup by the current the magnet draws, but you'd have to test that. Otherwise you could put a resistive/capacitive film sensor on the magnet, that will trigger when your object is pushed against the magnet.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.