Brandon Roots
  • FILM
  • INTERACTIVE
  • 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

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 […]

Fractal Plant – Beta Build

Homemade Hardware, ITP

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 […]

Fractal Plant – Boards Ordered

Homemade Hardware, ITP

Fractal Plant – Boards Ordered

Over the last week I rerouted the traces in my PCB design. Following feedback during class that the auto-router feature in Eagle isn’t very smart I did manage to make some cleaner routing manually. As part of the process I went through each component and made sure they were placed a closely as possible to […]

Recent Posts

  • Fractal Plant – Foiled by  RegistersFractal Plant – Foiled by Registers
    May 9, 2022
  • Fractal Plant – Beta BuildFractal Plant – Beta Build
    April 24, 2022
  • Fractal Plant – Boards OrderedFractal Plant – Boards Ordered
    April 18, 2022
Brandon Roots
Accessibility by WAH