Written By: Mohamed Ihsan

Written on 11/16/2021

Using a Transistor to Control High Current Loads (like DC Motor):

IMG_20211116_214943.jpg

Process: This lab was relatively straightforward to make. I followed the lab as instructed on this link, and it worked well. I really enjoyed considering the possible project ideas that could be done with this technology.

Code:

const int transistorPin = 9;    // connected to the base of the transistor
 
 void setup() {
   // set  the transistor pin as output:
   pinMode(transistorPin, OUTPUT);
 }
 
 void loop() {
  //read the potentiiometer
  int sensorValue = analogRead(A0);
  // map the sensor value to a range of 0 to 255
  int outputValue = map(sensorValue, 0, 1023, 0, 255);
  //use that to control the transistor
  analogWrite(transistorPin, outputValue);
  
//   digitalWrite(transistorPin, HIGH);
//   delay(1000);
//   digitalWrite(transistorPin, LOW);
//   delay(1000);
 }

H-bridge Lab:

Parts of the H-bridge:

Untitled

IMG_20211117_014032.jpg

Process: understanding and completing this lab was pretty straightforward. However, when I implemented the code, and ran the lab, I found that my motor did not run both directions once I toggled the switch, it didn't run the other direction when I changed the switch to off - it just stopped turning. I intend on seeking help on this issue from the instructor.

Fixed Issue: I realized, with the help of Yeseul, that the issue with my DC motor was that my wire attached to my switch was not attached to pin 2, but in fact attached to the ground. Once I rewired correctly, the DC motor was able to turn both ways as intended.

https://youtu.be/in2e3RaESV4