School project, SOLVED

Thanks, @Paul_KD7HB for your message. I will learn how to read schematics, but at the moment my main goal is to get this project finished for school.

I guess turning the motor on and off rapidly might work, but I'm not sure how?
What might you suggest? How would I make it go on and off so quickly to achieve a specific speed? Wouldn't it be easier to just set it as an analog Output and set speed to 128 when I need?

Thanks.

Quick tip:
Read up on Arduino PWM motor control

Thanks for the idea @lastchancename

I just had an idea. My problem is that I'm not getting enough power through the DC motor for it to rotate a larger object. So to resolve this issue, would there be a way to increase the voltage delivered to the DC motor, without changing code or adding any additional parts?
Would it be possible to maybe set the DC motor in parallel with the entire circuit so it receives 9V?

Thanks.

Reply #5 is the charm…
Note the motor draws more current than your Arduino can provide, so your motor power should always be drawn from a separate source with a common Ground/0V shared.

Motors require voltage (V per the motor spec), and current (A) to support the load experienced by the motor.

In Ohms law, these V x A are expressed as Watts (power)…. this is the magic that determines how well your motor driver will work in specific applications.

There are many threads on the forum that discuss motor drivers and PWM control.

Alright, no worries. Thanks @lastchancename

I will try this and let you know how it goes.

Thanks.

Would it be possible for someone to make a fritzing diagram for the schematic? It's just because I still don't know how to read them, and I'm running short on time for the due date for this.

Thanks.

A Frizzy will get less uptake than a pen & paper drawn with some thought.

This Transistor idea isn't getting me anywhere. It hasn't worked at all.

Instead, I'm thinking of using a larger battery (12-14V), plugging that into Vin and GND, with both being to the power rail. So while the LCD display is connected to 5V, then (if I use 14V), that leaves 9V for other parts, such as the motor and LED strip, which should give them enough voltage to start working.

Let me know if this idea won't work, and another solution (other than transistors, because they aren't working, and I'm running out of time).

Thanks.

Sadly, it seems you have no idea about voltage and current.
If you decide to join the conversation, and provide answers to the replies above, we may have a chance of helping, but at the moment, you're well on the way to destroying your components.

1 Like

I shall not bore you with the full description, but using "Vin" at all, let alone what you are thinking - is a really bad idea.

I would like to remind you of what I posted in #19. :roll_eyes:

1 Like

Don't! Using a larger battery doesn't provide increased voltage to the component itself. You're going to burn your components.

if you want to power it externally, just use a USB powerbank and the included cable. Wire it as normal.

A fundamental error you made is making the Arduino a power supply, which you can get away with if your current draw is miniscule, however with a motor it will not work and you may burn out components.

Since you are a bit low on time, I suggest using a USB powerbank with the supplied data cable, or the circular power cord attachment if you have a battery case with the required cable.

Post this project, I would personally advise you to learn how the microcontroller works and how voltage and current work independently as well as how they work hand in hand together.

Because you are doing it wrong. Switching transistors are used all the time for controlling motors with a microcontroller. If it isn't working, we should look into why. But I can tell that you are starting to panic and get impatient.

This shows that you have a fundamental misunderstanding about voltage and current. The idea that the LCD display "takes" 5V and "leaves" 9V for everything else proves my point. Everything in that sentence is simply wrong - profoundly wrong. Not only that, but you risk blowing up the Arduino.

I don't know how much time you have left, but unless you co-operate now, and completely, with the people trying to help you, then you will fail. Post your schematic. Post your code. Then we can see where the problems lie.

But I've actually got another suggestion (and I'm saying this as an ex-lecturer). Recognise that your knowledge and understanding are nowhere near sufficient to achieve this aim; recognise and accept that you are going to fail. But turn that fail into a win.

A win? Certainly. It's fine to fail - people do it all the time. The important thing is to go down fighting, then you will get respect and recognition from your teacher. Write up an account of how you tackled the problem; how you developed your solution; how your tried to overcome the problems; how far you have got and what is left to do; what conclusions you have reached thus far; and, most importantly of all, what you have learned. It is fine, indeed valuable, to say that you discovered your knowledge of basic electrical theory (volts, amps, resistance) is lacking.

Talk about what you have learned about electronics and microcontrollers, but also talk about what you have learned about project management. You can discuss the challenges you had getting help on this forum, and why. You can discuss and criticise the approach you took.

Frankly, if you can give a good account along those lines, then the fact that the project is unfinished (i.e. not working yet) will seem an insignificant detail.

Now, the above is what I would expect of a university student. I take it you are still at school? If so, it doesn't matter - the principle is the same. Concentrate on how you did it, what you got wrong, and what you've learned. Those are far more valuable than successfully making an electric motor behave in a certain way.

You can still get a win out of this, both for yourself and in the eyes of your teacher.

Although I would love to solve the issues for OP's project in time because it does sound like a lovely idea, I'm going to have to agree with @SteveThackery on this one.

@SteveThackery Thank you for your kind words. You're right, I am running out of time and patience, but I truely, truely appreciate your kind words. It means a lot to me to have people willing to help me, so thank you all.

As I mentioned before, I don't know how to read/draw schematics, and I don't have time to learn, however, I can provide an image of my wiring.

And 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;

#define pwm 3 //NEW STUFF
// #define pot1 A0 //NEW STUFF
// #define pot2 A1 //NEW STUFF

void setup() {
pinMode(pwm, OUTPUT); //NEW STUFF
//pinMode(pot1,INPUT); // NEW STUFF
//pinMode (pot2, INPUT); //NEW STUFF
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);

float val = analogRead(pressurePin1);//NEW STUFF
float duty = map(val, 0, 1023, 0, 255); //NEW STUFF
analogWrite(pressurePin1, duty); //here's how to generate PWM signal from Digital arduino pin NEW STUFF
Serial.println(duty);// NEW STUFF

float val2 = analogRead(pressurePin2);//NEW STUFF
float duty2 = map(val2, 0, 1023, 0, 255); //NEW STUFF
analogWrite(pressurePin2, duty2); //here's how to generate PWM signal from Digital arduino pin NEW STUFF
Serial.println(duty2);// NEW STUFF

if (forceA < 500) {
lcd.clear ();
lcd.print (" Engine Speed");
lcd.setCursor (0, 1);
lcd.print ("50%");
analogWrite (DCMotor, 255); // 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, 255); // 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, 128);// 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) ;
}

Hope this helps.

Thanks.

Your transistor needs a base resistor !

Could you please elaborate? What kind? Which pins does it connect do.
Can you show a diagram (Not schematic)?

Thanks

What’s written on the transistor ?


int pressurePin2 = A1;
. . .

float val2 = analogRead(pressurePin2);
. . .
analogWrite(pressurePin2, duty2);

You do know that A1 is not a PWM pin ?

And A1 (pressurePin2) is an analog input pin ?


Same with pressurePin1.


Hi @LarryD. I didn't know that A1 isn't a PWM pin. Can you please suggest what I should do. I.E Tell me what to wire where and the subsequent code.

Thanks.

PWM pins:

Uno, Nano, Mini 3, 5, 6, 9, 10, 11         490 Hz (pins 5 and 6: 980 Hz)


What’s written on the transistor ?

Thanks. The Transistor has BC548 written on it.

Thanks.