What happens in an oscillating electromagnet?

I have an electromagnet, which is connected to the motor output of a motor driver. The electromagnet switches direction 0.2 Hz - 100 Hz. I control the frequency with a potentiometer. With another potentiometer I control the duty cycle (0 % to 100 %). Everything works fine. The pots are connected to an Arduino. The Arduino is connected to an L298N board, which is connected to the electromagnet. The resistance of the electromagnet coil is 18 Ohm

My question is, is there something I should be concerned of. There are no additional components attached to the electromagnet coil, just the motor output of the motor driver. The driver has its flyback diodes. The purpose of the electromagnet is to create motion in a magnetized fidget spinner, but that's another story. As I said, everything is working, but does this thing need some extra components for say prevent damage or for increasing effect? A capacitor? An inductor? A resistor?

the same diode as for motor

If you are able to change direction of the voltage going to the electromagnet then yo are likely using an H bridge driver. Please check. If this is the case then the protection devices should be built into the driver.

John

The coil will be stronger if it has a ferrous core.

If you can get 3 coils arranged evenly in a circle and time them 120 degrees apart in phase, you will get a rotating field that should drag the spinner around. The electromagnet fields grow and fade, they result in a single moving field. Tesla used that to spin his metal egg and introduce induction motors only he used 3-phase AC to do it.

If you get a Linear Hall Sensor (not a Hall Switch) you can measure EM field in 1 direction/axis. The presence of magnets and metals in motion or stopped can all be seen as sensor values. You can sense electric fields through capacitance.