Assignment:
- add an output device to a microcontroller board you’ve designed, and program it to do something
- measure the power consumption of an output device
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.
I found Allegro A4953 in fablab.
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:
I decided to add a 2x2 headers for networking assignment next week.
How does MOSFET work?
The MOSFET transistor has three pins: Gate, Source, and Drain.
MOSFET works similar to the NPN transistor
- In the NPN transistor, the current from base to emitter decides how much current can flow from collector to emitter.
- In the MOSFET transistor, the voltage between gate and source decides how much current can flow from drain to source.
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.
Regulator
According to the datasheet of NCP1117, I added two 10uF capacitors.
Electronics components
- ATtiny412
- 10uF capacitors x 3
- UPDI 1x2 header
- 2x2 header
- 1x2 Screw Terminal
- 10K resistors x 2
- MOSFET N-CH
- LED x 2
- Regulator
- Power Jack
Here’s the schematic part:
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.
Solution is to redefine the dimension!
Align the drilling spots by using reference pads.
Define the hole size.
Set origin point.
Choose tools.
Got the board! Nice and clean!
To test and program, I made a adaptor board.
Connect them together:
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
- kicad magnet board
- kicad adaptor board