Output Devices

Electromagnets

Assignment:

I plan to work with electromagnet in this week to prepare for my final project.

Kris ordered a few 5V Electromagnet - 2.5 Kg Holding Force - P20/15.

In the description on Adafruit website, it says that “since its a coil, you’ll need to use a motor or solenoid driver with kick-back protection.”

That specific electromagnet requires 220mA at 5V. I checked the Electrical Characteristics in Attiny412 datasheet. Under 35.2 Absolute Maximum Ratings, the max current of each I/O pin is 40mA, which is much smaller than 220mA. That’s why we need to bring in the motor driver, to be specific, the H-bridge.

How Transistors Work

What Is an H-Bridge

I found Allegro A4953 in fablab.

a4953-1 a4953-2

a4953-3

Kris suggested that I should use MOSFET and regulator instead of H-bridge because H-bridge is for controlling motors. I don’t need to control current direction.

Illustration by Kris:

kris1

I decided to add a 2x2 headers for networking assignment next week.

kris2

How does MOSFET work?

The MOSFET transistor has three pins: Gate, Source, and Drain.

MOSFET works similar to the NPN transistor

To Turn on

A amount of voltage bigger than threshold have to apply between Gate and Source. The datasheet of N-Channel MOSFET (1.7A, 30V) indicates the Gate Threshold Voltage is 1.6v.

To Turn off

When you apply a voltage between gate and source, this voltage stays there until it’s discharged.

Therefore, to turn off the MOSFET, I added a resistor as below. With the resistor, there is a path for the gate-source capacitor to discharge so that the transistor turns off again.

dn

Regulator

According to the datasheet of NCP1117, I added two 10uF capacitors.

regulator

Electronics components

  1. ATtiny412
  2. 10uF capacitors x 3
  3. UPDI 1x2 header
  4. 2x2 header
  5. 1x2 Screw Terminal
  6. 10K resistors x 2
  7. MOSFET N-CH
  8. LED x 2
  9. Regulator
  10. Power Jack

Here’s the schematic part:

sch_magnet

pcb_magnet

CopperCam

I used CopperCam to generate tool path since it’s easier for creating drilling path than mods.

One issue that trapped me was that the front copper layer disappeared after I imported drilling file.

Capture

Solution is to redefine the dimension!

Capture2

Align the drilling spots by using reference pads.

Capture4

Define the hole size.

Capture5

Set origin point.

Capture6

Choose tools.

Capture7

Got the board! Nice and clean!

Magnet board

To test and program, I made a adaptor board.

sch_adaptor

pcb_adaptor

Connect them together:

Heroshot

Arduino

const int Gate = 2; //  PA1 of the ATtiny412
int incomingByte;      // a variable to read incoming serial data into

void setup() {

  // initialize serial communication:

  Serial.begin(115200);

  // initialize the LED pin as an output:

  pinMode(Gate, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'H') {
      digitalWrite(Gate, HIGH);
    }
    if (incomingByte == 'L') {
      digitalWrite(Gate, LOW);
    }
  }
}

Demo video:

Useful Reference

Download