News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Ball bearing detector

Started by charliecoutas, Jul 29, 2025, 04:45 PM

Previous topic - Next topic

charliecoutas

We are building a new fun exhibit for the museum. I want to add a Perpetual Motion Machine (??). The type where a ball-bearing runs down a track then gets sent up into the air and back into the original hopper where it came from, repeat. Spoiler Alert: It is accelerated during its fall by a powerful pulse from a hidden electromagnet. That part is easy. I am struggling with the bit that detects the ball on the track. Optical is no good. There is a way of detecting a lump of metal (not magnetised but steel) and generating a signal but I can't figure it out.

Any ideas?

Charlie


top204

#2
Why not use one of the simple methods of metal detecting, using an LC. It has been done on PIC microcontrollers since the 1990s, and is very easy to do with a coil and a capacitor and the built-in op-amp.

There are many circuits and explanations of it on the internet, and below is one of them:

https://www.hackster.io/teodor-emilian-petre/metal-detecting-with-pic18-q71-microcontroller-f9597c

Or, if the ball is initially moved by a magnet, it should pick up some magnetism, so a linear Hall sensor should detect some gauss difference when it moves over it. Then it will alter its voltage out slightly, so an ADC can detect it. A few of them detecting in sequence will make sure it is not a single anomalous event.

They are very simple to operate. Power them up with 5 volts, and put the output to an ADC channel, a change in gauss will alter its voltage out, and that's it.

charliecoutas

Les, Bob

Many thanks. I will look into your ideas after din-dins.

Best
Charlie

charliecoutas

The reader-made sensor that Bob suggests is good, but I feel that I should struggle a bit. The tuned circuit idea is perfect and that's what I'll try.

Thanks both.
Charlie

david

I'm not so sure about that Hackster item.  It's basically a resonant pulse induction system.  I don't think a 2:1 drive is ideal for this topology as you're effectively damping things for 50% of the cycle.  About 5-15% is more typical. The unity gain buffer is probably not required as you can change the RC time constant to a higher impedance and you may also want to reduce the time constant.  The ball is only briefly in the right zone for accelerating with the electromagnet so you would need a small search coil and a short integration time.  RC resonance?  That's new to me but may be a hint about the calibre of the writer.   
I would have though an optical sensor just before the electromagnet and positioned (hidden) just under the ball funnel would have been the easier solution but I'm sure we will all watch your project with interest.
I have an inductive switch just like the one linked to above.  If I could e-post it to you I would but it's probably bigger than you want.  There are also Hall sensors in the same package but I've only used digital types where a known pole is presented.
Good luck with the project.

Cheers,
David

ken_k

A couple methods come to mind.
A variable reluctance pick-up or depending on the ramp material a change of capacitance as the ball rolls over two hidden insulated electrodes. The capacitance change could be measured with a meter and the data used to design the switch electronics.
A simple variable reluctance pick up may suffer from false triggering when the electo magnet fires.
I have never used a PIC capacitive touch switch, maybe they could be made to work.

Fanie

#7
Quote from: charliecoutas on Jul 29, 2025, 04:45 PMWe are building a new fun exhibit for the museum. I want to add a Perpetual Motion Machine (??). The type where a ball-bearing runs down a track then gets sent up into the air and back into the original hopper where it came from, repeat. Spoiler Alert: It is accelerated during its fall by a powerful pulse from a hidden electromagnet. That part is easy. I am struggling with the bit that detects the ball on the track. Optical is no good. There is a way of detecting a lump of metal (not magnetised but steel) and generating a signal but I can't figure it out.

Any ideas?

Charlie

You can purchase the complete working unit off Temu.com.  I suspect the acceleration is done with a small dc motor and a rubber disk on the shaft. You then adjust the motor speed to where it accelerate the ball just enough to land back in the hopper.
Hope this doesn't take the fun out of your project  :-[

https://www.temu.com/za/stickman-running-dynamic-fingertip-gyroscope-visual-illusion-running--finger-gyroscope-game-g-601100793176965.html

Of course all these things can be 3D printed

https://www.temu.com/za/1pc-usb-clock-fan-portable-with-led-time-display-mini-flexible-cooling-fan-with-switch--desktop-laptop-tablet-convenient-and-energy--g-601099527593384.html

charliecoutas

Thanks guys, very useful. No Fanie, the unit I have seen senses when the ball bearing is about 2cm away from the electromagnet. This causes a MOSFET to discharge some capacitors into the electromagnet, this lasts about 10mS. Anyway, buying a ready-made unit takes all the fun away. This gives the ball enough speed to go up the ramp and back into it's home position. The sensing is done with a resonant LC circuit which the presence of the ball damps, just like Les described.

I am going to try a simple LC oscillator (not using the PIC) and watch its output, which will drop when the ball is near. As David said, I don't think an op-amp is needed. I will use a PIC (otherwise the guys at the museum will rib me to hell) but only for the timing and drive pulse to the MOSFET. It will need a gate driver. I have wound a solenoid with 1.5mm wire and it measures about 1 ohm. So 12V into 1 ohm is 12amps which is well over 100 watts. That should be a good starting point.

Charlie

david

When you say the LC oscillator's output will drop are you meaning in amplitude or frequency?   The frequency should drop with steel in the field and if you can induce eddy currents into the ball it should absorb some energy and lower the amplitude.
12V at 12A seems a lot - more like a rail gun.  You should only need to top up the ball's potential energy to have it run continuously but timing will be critical.  I don't think you will need a gate driver.  The PIC can easily cope with the gate drive and the solenoid inductance means you can only ramp up the current so fast.  I would go for about 150R between PIC and gate with a 10k pull down to ensure the gate can't float up at start up.   Don't forget the fast, inverse diode across the solenoid.

Cheers,
David

charliecoutas

#10
Cheers David, yes, I meant that the amplitude should drop but experiments are not giving the result I expected. With about 20 turns of 0.2mm wire pile-wound on a 1cm dia former, and a one transisor Colpitts oscillator the frequency was around 2Mhz. But I had to almost insert something steel (screwdriver) into the coil to get any drop in amplitude. So I remade the coil to be about 5cm dia. Frequency was again 2Mhz but same poor sensitivity. I haven't got the ball bearings yet but I think about 5mm dia will be ok.

Yes, I realise that over a hundred watts is on the high side, but I can always bring it down. Also, the capacitors probably won't discharge much during the 10mS pulse. The timing will be done by the PIC. Running at 64Mhz will give lots of timing latitude.

david

2MHz is certainly high.  Many metal detectors work from a few kHz up to 10s of kHz. Sounds like your resonant capacitor must be only about 2nF.  Can you try a 0.22uF and see how it behaves?  Skin depth of steel at 2MHz is going to be very small (<20uM) so it may be hard to couple much energy into it and so the amplitude won't change much.
A wide photo interrupter may be an easier path.

Cheers,
David

charliecoutas

Thanks David, I didn't know about the frequency, useful stuff.

A photo-interrupter would be easy but we want it to appear that there is no external fiddling going on. No visible wires. The ball-detector will be under a thin wooden or plastic base as will the solenoid. A suggested a gate driver because the MOSFET used will need to be driven hard into conduction. Overkill maybe but that's me!

An unnamed member of our team spent quite a lot of energy on Monday explaining how "the energy in a magnet" could easily power such a machine.

I'll try a lower frequency tomorrow. Thanks for your help.

Charlie

top204

This thread sparked my interest, so I did a bit of searching, and found a few ways of doing simple metal detecting, using a single PIC microcontroller. A few methods caught my eye, and they use the device's Watchdog Timer as a reference oscillator, and an LC circuit as the microcontroller's main oscillator. So after an initial calibration of a few seconds, if the oscillator frequency is different to its initial reference frequency, based upon the watchdog, it means metal is present near the inductor.

It should detect a ball bearing, as long as a decent inductor is used.

I created a circuit for it, and built a reference circuit on a breadboard, using the only Inductor I could find, and it worked extremely well, and will work better with a proper inductor without all of the ferrite around it.

Below is the code listing for the Metal Detector, using a small PIC12F683 device:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A simple metal detector for most standard 14-bit core devices.
' Written by Les Johnson for the Positron8 BASIC compiler for a PIC12F683 device.
' Based upon the circuit of Bruno Gavand.
'
' The idea of the microcontroller's circuit is to replace the oscillator crystal with a coil.
' The frequency of the oscillator then alters with the presence of metal near the coil.
' To detect changes of the main oscillator frequency, the program uses the PIC microcontroller's watchdog as an internal time reference.
' By comparing both oscillator frequencies, it can be known if a piece of metal is near the coil, and then light an LED.
'
' PIC12F683 Pin Assignments:
' GP0 connects to the detect Red LED indicator.
' GP1 connects to the calibrate Green LED indicator.
' GP2 is Not Connected
' GP3 is Not Connected
' GP4 and GP5 connect to the 10uH to 330uH inductor.
'
    Device = 12F683                                                     ' Tell the compiler what device to compile for
    Declare Xtal = 4                                                    ' Tell the compiler what frequency the Device is operating at (in MHz)
    Declare Optimiser_Level = 1                                         ' Make the code a bit smaller and more efficient

$define Detect_LED_Pin    GPIO.0                                        ' Connects to a red LED, that illuminates whan metal is present
$define Calibrate_LED_Pin GPIO.1                                        ' Connects of a green LED, that initially illuminates when the power is first applied to the device.

$define cMaxTrys 15                                                     ' The number of watchdog restarts to calibrate the loop counter
'
' Create global variables here
'
    Dim bLoopCount      As Byte                                         ' Holds the number of loops between two watchdog resets
    Dim bPrev_LoopCount As Byte                                         ' Holds the rrevious value of bLoopCount
    Dim bCalibValue     As Byte                                         ' Holds the calibration value when oscillator runs free
    Dim bRestarts       As Byte                                         ' Holds the number of watchdog restarts
    Dim tEn_Flag        As Byte                                         ' Enable flag. Set high with detection

'-------------------------------------------------------------------------------------
' The main program starts here
' Detect frequency changes, and illuminate the Red LED if present.
' The Green LED illuminates when power is first applied to the microcontroller, as it calibrates.
'
Main:
    Low GPIO                                                            ' Make all the GPIO pins output low
    Do                                                                  ' Create a loop
        If STATUSbits_NOT_TO = 1 Then                                   ' Power up?
            bRestarts = 0                                               ' Yes. So reset bRestarts
            bCalibValue = 1                                             ' Setup bCalibValue
        EndIf

        If bRestarts < 255 Then Inc bRestarts                           ' Watchdog reset counter

        If (bPrev_LoopCount ^ bLoopCount) > bCalibValue Then            ' Does the counter differ too much from the calibration value?
            Detect_LED_Pin = tEn_Flag                                   ' Yes. So illuminate the detect LED
            If STATUSbits_NOT_TO = 0 Then                               ' If not on, then power up
                If bRestarts < cMaxTrys Then                            ' While in calibration mode...
                    bCalibValue = bCalibValue << 1                      ' Shift the calibration value
                    DelayMS 10                                          ' And wait a while
                EndIf
            Else                                                        ' Otherwise...
                PinClear Detect_LED_Pin                                 ' Extinguish the detect LED
            EndIf
        EndIf
        bPrev_LoopCount = bLoopCount                                    ' Save the previous counter value

        If bRestarts > cMaxTrys Then                                    ' Is calibration finished?
            PinClear Calibrate_LED_Pin                                  ' Yes. So extinguish the calibrate LED
            tEn_Flag = 1                                                ' And set the enable flag
        Else                                                            ' Otherwise...
            PinSet Calibrate_LED_Pin                                    ' Illuminate the calibrate LED
            tEn_Flag = 0                                                ' And clear the enable flag
        EndIf
        OPTION_REG = %10001001                                          ' Set the 1:2 prescaler to the watchdog
        bLoopCount = 0                                                  ' Start counter, to be interrupted by watchdog
        Do                                                              ' \
            Inc bLoopCount                                              ' | Create a loop and increment bLoopCount within it
        Loop                                                            ' /
    Loop                                                                ' Do it forever

'-------------------------------------------------------------------------------------
' Setup the config fuses for an HS oscillator, with the watchdog enabled, and the MCLR pin disabled.
' For a PIC12F683 device
'
    Config HS_OSC, WDT_ON, PWRTE_OFF, CP_OFF, MCLRE_OFF

The program only uses 113 words of code memory, and 11 bytes of RAM. Which is not bad at all!. Maybe it could be adapted for one of the tiny 6-pin PIC microcontrollers, but I will leave that up to the users of the forum. :-)

When the device is first powered up, the green LED will illuminate for a second or so, as it calibrates what the oscillator frequency should be without metal beside the inductor. Then the red LED will illuminate when metal is brought near the inductor, because the main oscillator frequency will change.

The code could be used on many PIC devices, because the method is standard with PIC microcontrollers. i.e. Watchdog and oscillator etc...

Below is the circuit diagram of the metal detector:

Metal_Detector_PIC12F683.jpg

And below is a video of the metal detector working on a breadboard:


I must find out how to take videos correctly with this bloody phone! :-)

Best regards
Les

ken_k

It seems there are a lot of good solutions to this problem. The time the ball bearing takes to pass the detector is certainly going to be a factor that needs to be considered. I'm going interstate so  won't have a chance to give it a try for over a week.
Do you mind answering some questions.
What size is the ball bearing?
What is the estimated velocity of the ball bearing, or the slope and distance traveled before the sensor?
What is the track made of.
What will the distance be between the ball and the ball detect device.
How much room is available for the sensor pickup?

ken_k

#15
Looking at youtube there a lot of scam perpetual motion devices one could copy and make function.

https://www.youtube.com/shorts/kJ02VdRRcdg

The steel ball on the metal rails could act as a switch, only a 555 needed.

https://www.youtube.com/shorts/U293YOWHa2I

https://www.youtube.com/shorts/E1HEDh0HfIo

https://www.youtube.com/watch?v=Bft7Wd8QElw


charliecoutas

#16
Les: what a good idea! The only snag could be the time it takes. The ball bearing is running pretty fast and the timing is critical, before the solenoid is fired. Ken shows a video of it in action.

Ken: Yes, that ball recirculating video is exactly what I am trying to reproduce. Your questions:

What size is the ball bearing?  About 5mm dia
What is the estimated velocity of the ball bearing, or the slope and distance traveled before the sensor? I don't know, the video gives a clue but it's pretty quick.
What is the track made of. Probably an old wire coat-hanger.
What will the distance be between the ball and the ball detect device. The thickness of the plastic/wooden base plus a bit. Say 8mm
How much room is available for the sensor pickup? As large you like, it in a larger model.

Charlie

Les's idea made me think about two oscillators, like in a Theremin where the resulting freq is the difference between two osc's.

Fanie

#17
I have a question.
Since the ball(s) is going to be accelerated over and over, why not simply drive the acceleration coils over and over ?

The speed of the acceleration sequence will be higher, hence switch faster than the ball is moving.
Also since two or more balls may follow in quick succession, it may be difficult to detect and do the acceleration for each.
The current drawed for the inductor cannot be calculated with ohm's law, depending on how long you excite the inductor, but the driver current should be small.
The electromagnetic fields created can only pull (plus gravity) because the balls have no magnetism, and I think stacking the spools of a relay or solenoids may be easy to obtain.


I still think a simple speed control motor with a rubber wheel will be a very simple solution that will accelerate each ball no matter how many sits in close following of the next.  If I'm not mistaken the tennis ball cannons/launchers work this way.  I understand the challenge of detecting and then switching the inductors to achieve an outcome, and you can still do it, however I think the simple solution is one that can be implemented easy and quickly.

charliecoutas

Watch the first video Ken listed Fani (I tried copy/paste but no luck) that is what I am trying to do. There is only one ball at a time, but the reset time is short enough to allow two close together. Yes, the solenoid fires just before the ball is over it so it just accelerates the ball enough to carry it up and over. Yes, the solenoid cannot "push" the ball.

I want it to look like magic (a rubber drive wheel would give the game away). I look forward to the day when some Very Clever Person stands in our gallery at the museum and explains how the ball gains enough kinetic energy from its fall to carry it back over the top. We get some Very Clever People in the museum, as you might imagine. They usually start with: "I think you'll find that.....".

Thanks for all the valuable input, it all counts.

Charlie

Fanie

I saw this picture, (just hide the small motor).