Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Electromagnet question (claw machine)  (Read 1741 times)

0 Members and 1 Guest are viewing this topic.

Draco_Elessar

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 62
  • Last login:May 05, 2018, 12:40:02 pm
  • Way too curious for my own good.
Electromagnet question (claw machine)
« on: January 16, 2016, 12:05:01 pm »
I'm working on a claw machine and would like to change the strength of the claw grip. It has a 24v 1 amp coil. When I lower the voltage to reduce strength, the coil makes a noise. Is reducing the voltage going to damage the coil? If not is there a way to reduce or remove the noise the coil is making?

Draco

lilshawn

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7513
  • Last login:July 04, 2025, 12:24:07 pm
  • I break stuff...then fix it...sometimes
Re: Electromagnet question (claw machine)
« Reply #1 on: January 18, 2016, 03:13:22 pm »
the coil should have a strength adjustment already that you use to adjust your payout. unless you have what's known as a "Cali" setup. in california, claw machines are considered gambling machines so the strength was set at the factory and was not adjustable.

take a look inside you machine. maybe post a couple pics of the board. if you don't have an adjustment, it could be easy to set one up by just installing a pot on the board and removing the jumper.

Draco_Elessar

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 62
  • Last login:May 05, 2018, 12:40:02 pm
  • Way too curious for my own good.
Re: Electromagnet question (claw machine)
« Reply #2 on: January 19, 2016, 05:01:22 pm »
Sorry I forgot to mention I am programming this myself using an Arduino. I'm using a motor controller to control the strength via voltage.

Draco

lilshawn

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7513
  • Last login:July 04, 2025, 12:24:07 pm
  • I break stuff...then fix it...sometimes
Re: Electromagnet question (claw machine)
« Reply #3 on: January 19, 2016, 06:01:30 pm »
would be better to use a PWM signal that you can vary the duty cycle with.

use a FET to drive the solenoid and then use an output of the microcontroller to drive the FET.

back in the day we had a 555 oscillator circuit driving a FET. then you just dial down the 555 pulses with a pot to vary the strength.

Draco_Elessar

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 62
  • Last login:May 05, 2018, 12:40:02 pm
  • Way too curious for my own good.
Re: Electromagnet question (claw machine)
« Reply #4 on: January 20, 2016, 05:19:54 pm »
would be better to use a PWM signal that you can vary the duty cycle with.

use a FET to drive the solenoid and then use an output of the microcontroller to drive the FET.

back in the day we had a 555 oscillator circuit driving a FET. then you just dial down the 555 pulses with a pot to vary the strength.

 :dizzy: ??? :dizzy: I have no idea, about what you just said. I am kind of learning as I go. I have been changing the PWM thinking that it was the same as changing the voltage. I'm not sure if I can change the duty cycle or not. Here is my code:

Code: [Select]
/*
Code for crane machine that will just play and return home.
*/

// include the SPI library:
#include <SPI.h>

// L9958 slave select pins for SPI
#define SS_M4 14
#define SS_M3 13
#define SS_M2 12
#define SS_M1 11

// L9958 DIRection pins
#define DIR_M1 2
#define DIR_M2 3
#define DIR_M3 4
#define DIR_M4 7

// L9958 PWM pins
#define PWM_M1 9
#define PWM_M2 10    // Timer1
#define PWM_M3 5
#define PWM_M4 6     // Timer0

// L9958 Enable for all 4 motors
#define ENABLE_MOTORS 8

int pwm1, pwm2, pwm3, pwm4;
int dir1, dir2, dir3, dir4;
const int joyup = 15;
const int joydown = 16;
const int joyleft = 17;
const int joyright = 18;
const int joypress = 19;
const int coin = 21;
const int front = 20;
const int left = 22;
const int clawup = 23;
const int clawdown = 24;
unsigned long currentime = 0;
int credit = 0;
int charge = 0;
long int gametime = 0;

void setup() {
  unsigned int configWord;
 
    // put your setup code here, to run once:
  pinMode(SS_M4, OUTPUT); digitalWrite(SS_M4, HIGH);  // HIGH = not selected
  pinMode(SS_M3, OUTPUT); digitalWrite(SS_M3, HIGH);
  pinMode(SS_M2, OUTPUT); digitalWrite(SS_M2, HIGH);
  pinMode(SS_M1, OUTPUT); digitalWrite(SS_M1, HIGH);
 
  // L9958 DIRection pins
  pinMode(DIR_M1, OUTPUT);
  pinMode(DIR_M2, OUTPUT);
  pinMode(DIR_M3, OUTPUT);
  pinMode(DIR_M4, OUTPUT);
 
  // L9958 PWM pins
  pinMode(PWM_M1, OUTPUT);  digitalWrite(PWM_M1, LOW);
  pinMode(PWM_M2, OUTPUT);  digitalWrite(PWM_M2, LOW);    // Timer1
  pinMode(PWM_M3, OUTPUT);  digitalWrite(PWM_M3, LOW);
  pinMode(PWM_M4, OUTPUT);  digitalWrite(PWM_M4, LOW);    // Timer0
 
  // L9958 Enable for all 4 motors
  pinMode(ENABLE_MOTORS, OUTPUT);  digitalWrite(ENABLE_MOTORS, HIGH);   // HIGH = disabled
 
  /******* Set up L9958 chips *********
  ' L9958 Config Register
  ' Bit
  '0 - RES
  '1 - DR - reset
  '2 - CL_1 - curr limit
  '3 - CL_2 - curr_limit
  '4 - RES
  '5 - RES
  '6 - RES
  '7 - RES
  '8 - VSR - voltage slew rate
  '9 - ISR - current slew rate
  '10 - ISR_DIS - current slew disable
  '11 - OL_ON - open load enable
  '12 - RES
  '13 - RES
  '14 - 0 - always zero
  '15 - 0 - always zero
  */
 
  // set to max current limit and disable ISR slew limiting
  configWord = 0b0000010000001100;
 
  SPI.begin();
  SPI.setBitOrder(LSBFIRST);
  SPI.setDataMode(SPI_MODE1);  // clock pol = low, phase = high
 
  // Motor 1
  digitalWrite(SS_M1, LOW);
  SPI.transfer(lowByte(configWord));
  SPI.transfer(highByte(configWord));
  digitalWrite(SS_M1, HIGH);
  // Motor 2
  digitalWrite(SS_M2, LOW);
  SPI.transfer(lowByte(configWord));
  SPI.transfer(highByte(configWord));
  digitalWrite(SS_M2, HIGH);
  // Motor 3
  digitalWrite(SS_M3, LOW);
  SPI.transfer(lowByte(configWord));
  SPI.transfer(highByte(configWord));
  digitalWrite(SS_M3, HIGH);
  // Motor 4
  digitalWrite(SS_M4, LOW);
  SPI.transfer(lowByte(configWord));
  SPI.transfer(highByte(configWord));
  digitalWrite(SS_M4, HIGH);
 
  // Reduce the PWM frequency to about 8kHz
  // Note, this will screw up the timer functions that use Timer0 such as millis()
  setPwmFrequency(PWM_M1, 8);
  setPwmFrequency(PWM_M3, 8);
  pinMode(joyup, INPUT_PULLUP);
  pinMode(joydown, INPUT_PULLUP);
  pinMode(joyleft, INPUT_PULLUP);
  pinMode(joyright, INPUT_PULLUP);
  pinMode(joypress, INPUT_PULLUP);
  pinMode(coin, INPUT_PULLUP);
  pinMode(front, INPUT_PULLUP);
  pinMode(left, INPUT_PULLUP);
  pinMode(clawup, INPUT_PULLUP);
  pinMode(clawdown, INPUT_PULLUP);
}


// *******************************************
// ************** Main Loop ******************
// *******************************************
void loop() {
  // put your main code here, to run repeatedly:

if (digitalRead(joypress) == HIGH)
    {
      digitalWrite(ENABLE_MOTORS, LOW);
      while (digitalRead(clawdown) == LOW)
      {
        analogWrite(PWM_M3, 200);  digitalWrite(DIR_M3, 0);
      }
      analogWrite(PWM_M3, 0);  digitalWrite(DIR_M3, 0);

      digitalWrite(ENABLE_MOTORS, HIGH);
      delay(3000);
      digitalWrite(ENABLE_MOTORS, LOW);
      analogWrite(PWM_M4, 255);  digitalWrite(DIR_M4, 0);
      while (digitalRead(clawup) == LOW)
      {
        analogWrite(PWM_M3, 200);  digitalWrite(DIR_M3, 1);
      }
      analogWrite(PWM_M3, 0);  digitalWrite(DIR_M3, 0);
      while (digitalRead(left) == LOW)
      {
        analogWrite(PWM_M2, 200);  digitalWrite(DIR_M2, 0);
      }
      analogWrite(PWM_M2, 0);  digitalWrite(DIR_M2, 0);
      while (digitalRead(front) == LOW)
      {
        analogWrite(PWM_M1, 200);  digitalWrite(DIR_M1, 1);
      }
      analogWrite(PWM_M1, 0);  digitalWrite(DIR_M2, 1);

      delay(3000);
      analogWrite(PWM_M4, 0);  digitalWrite(DIR_M4, 0);

      digitalWrite(ENABLE_MOTORS, HIGH);
      credit = credit - charge;

    }
    else
    {
      digitalWrite(ENABLE_MOTORS, LOW);
      while (digitalRead(joyup) == HIGH)
      {
        analogWrite(PWM_M1, 200);  digitalWrite(DIR_M1, 0);
      }
      analogWrite(PWM_M1, 0);  digitalWrite(DIR_M1, 0);
      while (digitalRead(joydown) == HIGH)
      {
        analogWrite(PWM_M1, 200);  digitalWrite(DIR_M1, 1);
      }
      analogWrite(PWM_M1, 0);  digitalWrite(DIR_M1, 0);
      while (digitalRead(joyright) == HIGH)
      {
        analogWrite(PWM_M2, 200);  digitalWrite(DIR_M2, 1);
      }
      analogWrite(PWM_M2, 0);  digitalWrite(DIR_M2, 0);
      while (digitalRead(joyleft) == HIGH)
      {
        analogWrite(PWM_M2, 200);  digitalWrite(DIR_M2, 0);
      }
      analogWrite(PWM_M2, 0);  digitalWrite(DIR_M2, 0);
      digitalWrite(ENABLE_MOTORS, HIGH);
    }
}
// ***********************************************
// ************** End Main Loop ******************
// ***********************************************


/*
 * Divides a given PWM pin frequency by a divisor.
 *
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *      o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *        256, and 1024.
 *      o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *        128, 256, and 1024.
 *
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired (Timer0)
 *   - Pins 9 and 10 are paired (Timer1)
 *   - Pins 3 and 11 are paired (Timer2)
 *
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 5, 6 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 *
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
 */
 
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) { // Timer0 or Timer1
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode; // Timer0
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode; // Timer1
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode; // Timer2
  }
}

Draco

lilshawn

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7513
  • Last login:July 04, 2025, 12:24:07 pm
  • I break stuff...then fix it...sometimes
Re: Electromagnet question (claw machine)
« Reply #5 on: January 20, 2016, 09:35:34 pm »
bleep bloop.  :laugh2:

sorry, i know nothing of code for microcontrollers.  :dunno i should learn one day.

but I think you have the right idea.

the coil still runs on 24 volts (or wahtever) but you vary the duty cycle to adjust the grip.

depending on the claw, you may have to go way down to like a 20% on 80% off in order to see an appreciable difference in the strength.

using a 555 to drive the FET, the 555 timer chip is setup to flip on and off an output.... by turning up a pot you can make it flip on and off faster...say 1000 times a second....you can then turn the pot down so the output flips off and on maybe 250 times a second.

this output is connected to a FET that supplies current to the coil of the claw. more pulses means more "on time" and less pulses meant less "on time"

a more advanced circuit would vary the duty cycle of the output to shorten the "OFF" time and lengthen the "ON" time instead of simply having more pulses.

maybe this will help explain about this a little more better than me for your case...

https://www.arduino.cc/en/Tutorial/PWM

Draco_Elessar

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 62
  • Last login:May 05, 2018, 12:40:02 pm
  • Way too curious for my own good.
Re: Electromagnet question (claw machine)
« Reply #6 on: January 21, 2016, 08:10:58 am »
Codeing for the arduinos is very easy.

Assuming that I understand this right. By changing the PWM I'm change the duty cycle. Its only changing the voltage because of how long or short the duty cycle has been change to.

When I was changing the claw strength I was changing the PWM. 255 for 100%, 229 for 90%, 204 for 80%, 178 for 70%, 153 for 60%. When ever I change the PWM to anything but 100% the magnet makes a noise. Is this because its not getting full voltage or the the duty cycle is making it open and close extremely fast? Now when I measure the voltage with a multi-meter its mostly constant.

lilshawn

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7513
  • Last login:July 04, 2025, 12:24:07 pm
  • I break stuff...then fix it...sometimes
Re: Electromagnet question (claw machine)
« Reply #7 on: January 21, 2016, 12:07:26 pm »
yes, you need a proper meter to measure a PWM'd voltage automatically. you can get close with a true RMS meter but it's really meant for a continuous sine wave AC as opposed to the asymmetric square wave supplied by a PWM DC circuit. lots of fluke meters have a duty cycle counter on them. (the 87 series for example)

with a regular meter it will appear that the voltage is dropping, but in actual fact it's still the full voltage supplied to it, it's just doing it a small percentage of the time. the sampling rate the meter operates at will highly influence what voltages it "sees" and displays.

nothing beats a good old oscilloscope to see what's going on though.

ed12

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 3972
  • Last login:March 31, 2018, 03:44:39 pm
  • it is what it is..."Nobody Said It Was Easy"....
Shipping something from the U.S. to Canada for repair/exchange?  Please use USPS to avoid (additional?/excessive?) shipping charges.  PM me if you have any questions.

lilshawn

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 7513
  • Last login:July 04, 2025, 12:24:07 pm
  • I break stuff...then fix it...sometimes
Re: Electromagnet question (claw machine)
« Reply #9 on: January 27, 2016, 10:59:10 pm »
here ya go... the 555...