EM Pendulum - Coil as sensor and actuator?

Hello everyone, my current goal is to make a simple electromagnetic pendulum, for those of you who don't know what this is, it's basicly a pendulum with a magnet on it's bob and it's powered by and electromagnet that makes it swing back and forth.

I know the theory behind it, it consists on a sensor that detects the bob aproaching, then the EM(electromagnet) is powered to give the bob and impulse, from this alone I could make one working pendulum by myself with little effort, but I want to try to make it using a single coil and an Arduino.

I know how to configure the coil as a sensor, currently I'm using a comparator and hooking the coil to one of it's inputs and when the magnet is approaching a small emf is induced on the coil which creates a voltage difference between the inputs of the comparator that he amplifies and I can use as an output.

I also think that I know how to configure it as an actuator, just connect it with a transistor to a power supply and power the base, although I don't really know if I'm doing it right, should I use a relay? I must connect a diode in parallel to the coil right not to damage the transistor or the Arduino right?

My problem lies when I try to combine both, I cannot think of a simple way to use my coil both as a sensor and actuator, because when I use it as an actuator, this current that's used to move the magnet also triggers the sensor. I know I could program the Arduino someway to not read the input of the coil when it's powered or something similar, but I know this can be done even without microcontrollers.

To sum up, I'd like to work this problem out using only hardware, keeping the code at a minimum just to read the sensor and power the coil. I'd appreaciate any help you could give me on this topic, also i'd thank you if you found and corrected any mistakes in my thinking on how in theory this works. Finally I apology for my rather simple english and for any grammar mistakes, it's not my mother language, thank you everyone.

It sounds straightforward to me. You need to detect a positive voltage in the coil, and then supply a positive impulse to it in order to give the pendulum a boost. This is what I would do:

  1. Design the coil to have a resistance of 150 ohms or more, so that the current it will draw from an Arduino pin will be no more than about than 30mA. [The induced EMF will oppose the voltage being applied, so in practice the current will be less.] If the coil has less than 150 ohms resistance, add a series resistor.

  2. Connect the coil between an Arduino analog input pin and ground, and connect a 1N4148 or preferably a Schottky diode in parallel with the coil (anode to ground) to catch the back emf.

  3. In the Arduino code, do continuous analogRead() calls until the voltage from the coil exceeds a preset amount, indicating that the bob is approaching. Then set the pinMode of that pin to output and write HIGH to it. After delaying for suitable period of time, change the pinMode back to input to terminate the impulse. Then delay some more before going back to doing analogRead().

In hardware you would use a transistor to short the comparator output to zero while you activate the coil. (after a suitable resistor if needed).

First of all, thank you all for answering, I think i'm not explaining myself correctly, I already know that I should detect some voltage with the arduino then power the coil (no need for the 30mA limit since i'll use an external power supply with a transistor) the problem is that when I power the coil, it'll generate some current on it and this will be detected, I want to find a way to avoid this if there is possible (which i belive from what've seen) and not solve this problem using software because that'd be "too easy" and not so elegant. Thank you everyone.

Flague:
the problem is that when I power the coil, it'll generate some current on it and this will be detected, I want to find a way to avoid this if there is possible (which i belive from what've seen) and not solve this problem using software because that'd be "too easy" and not so elegant.

That's exactly why I suggested two delays in the code, so that once you have detected the approaching pendulum, you ignore the signal for long enough for the pulse to finish and the pendulum to go away again.