Brandon Roots
  • INTERACTIVE
  • FILM
  • ABOUT
  • CONTACT
November 15, 2020

Lab: Using a Transistor to Control High Current Loads with an Arduino

broots ITP, Physical Computing

This week in Physical Computing we learned about controlling devices that require more current than can be provided by an Arduino directly. Because Arduino pins are limited to supplying 10mA it is necessary to provide additional power externally for high current peripherals. To try this out I put to use a DC fan I pulled from an old computer that requires 220mA to run.

My diagram and assembled breadboard:

After wiring everything up I ran the sample code below and success! The fan runs.

const int transistorPin = 9;    // connected to the base of the transistor
 
 void setup() {
   // configure the serial connection:
   Serial.begin(9600);
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void loop() {
   // read the potentiometer:
   int sensorValue = analogRead(A0);
   // map the sensor value to a range from 0 - 255:
   int outputValue = map(sensorValue, 0, 1023, 0, 255);
   Serial.println(outputValue);
   // use that to control the transistor:
   analogWrite(transistorPin, outputValue);
 }

While running this code something I noticed is that the motor only runs when the analogWrite value is 255, or full on the potentiometer. At all other values the motor would turn off. My guess is that this has something to do with the frequency of the PWM function and combination with this particular motor.

My gut feeling on this was that a slower on/off cycle than the PWM pin was operating at might work. Modify the code to include a delay of variable length allowed for slower speeds on the fan.

Is this ok for the motor? I’m not sure. Thankfully this is a junk shelf fan 🙂

const int transistorPin = 9;    // connected to the base of the transistor
 
 void setup() {
   // configure the serial connection:
   Serial.begin(9600);
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void loop() {
   // read the potentiometer:
   int sensorValue = analogRead(A0);
   // map the sensor value to a range from 0 - 255:
   int outputValue = map(sensorValue, 0, 1023, 0, 255);
   Serial.println(outputValue);
   // use that to control the transistor:
   analogWrite(transistorPin, 255);
   delay(outputValue);
   analogWrite(transistorPin, 0);
 }
Week 10: Sound I Lab: DC Motor Control Using an H-Bridge

Related Posts

Fractal Plant – Foiled by  Registers

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Foiled by Registers

Since receiving the PCBs and successfully soldering the board together I have been trying to rewrite code for the I2C port expander. This has been immensely difficult! The Inkplate Arduino Library makes considerable use of an “Mcp” class, which is written to work with the MCP23017 GPIO expander IC. These chips are quite difficult to […]

“Handling” Playtest Week

Handling, ITP

“Handling” Playtest Week

Last week we attended “Playtest Thursday” on the second floor of 370 Jay St with our games. I came away from the experience with some very specific feedback. Seeing a number of people play the game showed me things I didn’t anticipate. Some folks approached the cabinet and immediately treated it as a touch screen. […]

Fractal Plant – Beta Build

Homemade Hardware, ITP, Solar Plant

Fractal Plant – Beta Build

The boards arrived! Amazingly within an hour of one another. Based on the experience I think that JLCPCB is a better value. With shipping OSHPark was $55.50 for 3 boards. JLCPCB was $26.36 for 10 boards. Aside from a higher cost OSHPark also left sharp bits of tabs around the edges of the boards which […]

Recent Posts

  • Fractal Plant – Foiled by  RegistersFractal Plant – Foiled by Registers
    May 9, 2022
  • “Handling” Playtest Week“Handling” Playtest Week
    May 5, 2022
  • Fractal Plant – Beta BuildFractal Plant – Beta Build
    April 24, 2022
Brandon Roots