School project, SOLVED

Hello, Arduino community,

I would love your guidance on an issue I have for a school project.

I am trying to make a system that, when one hand is removed from a steering wheel, an engine (3D printed and powered by a DC motor) will slow down, and a green light strip (LED strip) will cycle through each pixel. In addition, an LCD screen will display this drop in speed as a percentage.

For components, I am using:
Arduino Uno R3
2 Force Sensitive Resistors
DC Motor
Resistors (220 and 10k ohm)
LED strip (4 pixels)
LCD Display (16x2)
9V battery

I can get the LCD and FSR's to work fine, however, the motor isn't spinning fast enough to rotate the engine. It doesn't create enough power to rotate enough. And the LED strip doesn't even turn on when plugged into the system.

Here is my wiring (I switched to an I2C LCD display, but the rest is the exact same):

And here is my code:
// include the library code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// include neopixel library
#include <Adafruit_NeoPixel.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int pressurePin1 = A0;
int forceA;
int pressurePin2 = A1;
int forceB;
int DCMotor = 9;
//Led Strip constraints
const int dinPin = 6; // Din pin to Arduino pin 6
const int numOfLeds = 4; // Number of leds
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numOfLeds, dinPin, NEO_GRB + NEO_KHZ800);
// Colour LED pixels
int red = 0; //Value from 0(led-off) to 255().
int green = 255;
int blue = 0;

void setup() {
Serial.begin (9600);
pinMode (DCMotor, OUTPUT);
pixels.begin(); // Initializes the NeoPixel library
pixels.setBrightness(100); // Value from 0 to 100%
// set up the LCD's number of columns and rows:
lcd.begin();
// Print a message to the LCD.
lcd.print ("Initialising...");
delay (1000);
lcd.clear ();
delay (1000);
lcd.print(" Safety Wheel ");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print (" Arya Nayak ");
delay (5000);
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor(0, 1);
lcd.print ("100%");
analogWrite (DCMotor, 255);

}
void loop (){
forceA = analogRead(pressurePin1);
forceB = analogRead(pressurePin2);
Serial.println(forceA);
Serial.println(forceB);

if(forceA < 500){
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("50%");
analogWrite (DCMotor, 128);
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(200); // Delay for a period of time to change the next led
pixels.clear ();
delay (200);
delay (100);
}
}
else if (forceB < 500){
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("50%");
analogWrite (DCMotor, 128);
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(200); // Delay for a period of time to change the next led
pixels.clear ();
delay (200);
delay (100);
}
}
else {
analogWrite (DCMotor, 255);
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0,1);
lcd.print ("100%");
for(int i=0;i<numOfLeds;i++){
pixels.clear ();
delay (200);
}

}
delay (4500) ;
}

Would deeply appreciate any recommendations from you guys.

Thank you so much (and sorry for the lengthy post).

1 Like

The Uno is not a power supply. It will not supply enough current to power a motor. You need a driver for the motor. Pololu has a line of motor drivers. Hopefully you have not damaged the Uno by trying to power a motor with an output.

Read the forum guidelines.

Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

Post your code in code tags.

1 Like

If the motor is to rotate in only one direction, the motor driver can be a simple transistor driver (BJT or MOSFET). If it has to be reversible, you will need an H-bridge driver (see the link to Pololu drivers).

1 Like

Hi groundFungus,

Thanks for your reply.

Could you refer me to a link that would show me how to wire up a transistor into my circuit, and potentially the subsequent code?

Thanks.

Adafruit DC motor tutorial.

MOSFET motor driver:

Choose the transistor based on the stall current of the motor. The stall current can be several times the running current. To estimate the stall current, measure the motor winding resistance. Take several measurements rotating the motor a bit between readings. Use the lowest reading in the calculation. The estimated stall current is the motor supply voltage divided by the measured resistance.

1 Like

@groundFungus Thanks for the idea.

I tried this, however, I'm still not getting the desired result. Could you please suggest any more ideas?
Would using a larger (12v) battery work?

Thanks.

Can you confirm that the transistor is a logic-level device? Can you confirm that the voltage at the gate is switching up and down correctly - with an oscilloscope, perhaps?

And yes, the motor may need a higher drive voltage, but only do that after you have confirmed the two points above.

Different ways to control a dc motor speed

What results DID you get? Is the 1n4007 in backwards?
Paul

@SteveThackery Thanks for the response. I'm not sure, all I know is that the transistor is a BC548. Where would I find it it's a logic-level device and all that?

Thanks.

@Paul_KD7HB My results are as follows:

  • When plugged into the arduino directly (like in the image above), the motor spins normally, however, it doesn't generate enough Torque or speed to rotate an enigne through pulleys.
  • The same issue is faced when i put the motor into a gear box. The motor doesn't seem to have enough power.
  • When wired with a transistor, the motor spins, but marginally faster, and the torque appears to be the same as when directly plugged in (GND and pin 9).

Also, there are no diodes in this circuit (unless a transistor is a diode, I'm not sure).

Thanks.

See the Ground fungus schematic? There is a diode and capacitor across the motor terminals. Does you project have at lease the diode? Necessary for long life of your circuit.
IF your motor runs for only a minute with a long cooling off period, you can double the voltage and get more current/torque.
Paul

Hi Paul,

No, my project doesn't have any diodes, I'm not sure how that would help and how I would wire it. what do you mean by

Is this when it's plugged directly into Arduino (GND and pin 9) or when wired with a transistor.

The Arduino is not a power supply, certainly not for any motor. You MUST use a transistor to control the power to the motor. The Arduino JUST controls the transistor.
When any motor is turned off, it becomes a generator and generates a voltage of opposite polarity to what was being supplied. The transistor likely cannot handle the back voltage and will die. The diode safely shorts that voltage for the short time it is being created.
You wire the diode across the motor terminals, just like in the schematic that was shown.
Paul

Thanks, Paul. I will add a transistor and diode to my project.

Will there be any code required to control the transistor giving power output to the motor? If so, where could I find a link or source to help me code it.

Thanks.

If you are following the Ground fungus schematic, any digits write(high) to the pin it is connected to will turn on the motor. A low will turn off the motor.
Paul

Complete rubbish!

Do you not know how a motor functions? :roll_eyes:

@Paul_KD7HB I don't know how to read schematics, and the motor has to be analog, since I need it to rotate at 100% and 50% capacity. Could you please suggest how I can incorporate these pre-existing aspects to my project.

Thanks

By the way, I suggest you edit your first post to remove the inappropriate "Help Needed" from your subject title. :face_with_raised_eyebrow:

IF you intend to continue with this hobby, you will need to work on reading schematics.
IF you turn the motor on and off rapidly, do you not think you can get 50% capacity?
Paul