Another problem with Arduino project

Hello everyone,

I already got help with my project on here, but I have come across another problem.

The motor is not working if I wire the Gate of the Mofset on the negative (-).

The led graph is working fine (left side).

The led on the right side is also working fine.

What I would like to have is a working motor and that it’s functioning while I use the potentiometer.
It should be synschronized with the led graph on the left side and the led on the right side.
What am I doing wrong?

I’ve attached a picture of the circuit.

Thanks for your time and help!

Code:

#define MOF_PIN 12

const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 8; // the number of LEDs in the bar graph

int ledPins = {
2, 3, 4, 5, 6, 7, 8, 9,
}; // an array of pin numbers to which LEDs are attached

void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
Serial.begin(9600);
}
}

void loop()
{
// read the potentiometer:
int pot = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(pot, 0, 1023, 0, ledCount);

// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++)
{
// if the array element’s index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel)
{
digitalWrite(ledPins[thisLed], LOW);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], HIGH);
}
}
// motor control
analogWrite(MOF_PIN, pot/4);
}

What is the part number of the MOSFET? Do you have a data sheet for it? What is the voltage on the gate when the LED is on?

If this is a continuation, why not link to the previous thread. Quote tags are not code tags (<>).

Glad to meet you again groundFungus!

I'm sorry about making another thread. I can't find the other thread on my profile. Where is it located?

About the MOSFET:

I am going to use a BUZ11. Above the BUZ11 it says F 1F52AJ.

Datasheet of a BUZ11: http://www.onsemi.com/pub/Collateral/BUZ11-D.PDF

BUZ11 is not a logic level MOSFET. You cannot successfully drive it direct from an Arduino pin.

There are many better MOSFETs, look for "Logic level" in the description.

Also I'm not sure what "wire the Gate...on the negative" means. The gate should connect to a pin not to anything negative.

Steve

Your previous thread. Why did you delete your original post in that thread? Not cool. It takes away the context for all subsequent posts. To find your previous posts, click on your avatar, then below your avatar there will be a list of actions. Click on show posts.

To choose an appropriate logic level MOSFET you will need to know the stall current of the motor. The MOSFET must be able to handle that current,

I made a mistake there. I thought I didn't have to connect it to a pin. I will try it out Steve, thanks!

Thank you groundFungus! The reason I deleted my original post is because I thought it was working properly and that it was finished. It's my bad and I am very sorry for that. I've learned from my mistake. It seems like I can always come across more questions but I didn't realise it at that moment.

Now I know for next time. Thank you! I'm quite new to Arduino and a forum like this.

I'm still thinking about what DC motor I should use. I thought about a simple 3V motor but I am not quite sure about it yet.

Both led sides are working perfect while using the potentiometer:

Both led sides work using the potentiometer

DC motor is working while using the potentiometer:

DC motor works using the potentiometer

When the DC motor is working, leds are turning off while I actually wanted both to work together at the same time:

DC motor works / leds are turning off

I have taken some screenshots in the links above. What am I missing? Do I have to change the code?

Thank you for your time and help!

So I have been trying to find out how to fix it. I think I have almost got it but I'm stuck.

I've swapped HIGH and LOW in the code and now the green leds are working with the DC motor, but the blue led is turning off:

Green leds work with the DC motor / blue led turns off

Is there a way to fix the blue led turning off while the green leds and DC motor are working? Or would you recommend something else?

Post your current circuit diagram and current code and we may be able to find out what's going on.

Hi,
What do you think the MOSFET is doing in this application.
64da449ec15e9f28d3dd31e13cbaa6e7c9f6df3b.png
Please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Not a fritzy.

Can you post a picture of your project, please?

Thanks… Tom… :slight_smile:

Hello,

I have heard that I could rather use a MOSFET than a normal transistor.
Using a MOFSET because my project is about PWM. I would like to control the speed of the motor as well as the blue led at the same time. The green leds are there to show how fast / how much power it is.

The current code I have is:

#define MOF_PIN 11

const int analogPin = A0;   // the pin that the potentiometer is attached to
const int ledCount = 8;    // the number of LEDs in the bar graph

int ledPins[] = {  2, 3, 4, 5, 6, 7, 8, 9,
};   // an array of pin numbers to which LEDs are attached


void setup() {
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
    Serial.begin(9600);
  }
}
void loop()
{
  // read the potentiometer:
  int pot = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  int ledLevel = map(pot, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++)
  {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel)
    {
      digitalWrite(ledPins[thisLed], HIGH);
    }
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW);
    }
  }
  // motor control
   analogWrite(MOF_PIN, pot/4);
}

Also attached a picture of the current circuit to this post.

I would like to hear what I could fix or do something in a better way.

Thank you for your time!

I'm afraid you either missed or don't understand the "not a Fritzy" part. That are not circuit diagrams. A mess of wires, very hard to follow. No markings on the parts (values, pinout). Two light blue wires that go off screen - to where?

For circuit diagram, sketch one on paper, or install real circuit design software such as KiCAD or EagleCAD.

Anyway, do get rid of Fritzing. It's useless. Really.

Ah right! Could I also use EasyEda? Or would you only recommend KiCAD and EagleCAD?

I will draw the circuit once I get home from work.

Hi, Use one of them that you feel happy with.

BUT when you go to post the schematic, look for the "EXPORT as image" tool. We all don't have the CAD that you use, but our browsers and OS will be happy displaying jpg file.

Thanks.. Tom... :) PS A picture of a hand drawn circuit will be fine also.

I'm using KiCAD and love it except for its outright terrible library management, but luckily that's one of the least used bits (the moment you get the libraries added all is fine, and it comes with lots of libraries included). It's FOSS.

EagleCAD is another popular one, haven't tried it myself. The pages of Adafruit and Sparkfun always refer to EagleCAD.

I never heard about EasyEda.

Hi, ExpressPCB is what I use, but I haven't used it to make a PCB commercially, I'm not sure if the latest version does, but it didn't make a Gerber file needed for PCB production.

Most of mine are one offs, so laser printer method is the usual way I make mine.

I prefer Express because it does not need buckets and buckets of hard-drive and is not encumbered with unnecessary parameters on the components and is easy to make and load components. It boots real quick.

https://www.expresspcb.com/free-cad-software/

Tom... :)

You don't have to go the full CAD route, although it would allow you to design a PCB for your components... you could use one of these free schematic editors: Schemit, CircuitBee and CircuitLab (used by electronics.stackexchange, my favorite). In fact, you can start to ask a question at stackexchange, then select the schematic editor [ctrl-M], but [u]don't[/u] POST the question. Grab a screenshot of the "question".

When it looks good, export a JPG/PNG or

1) capture a screenshot of the schematic (ctrl-alt-print) 2) paste it into an image editing program (Paint, GIMP, IrfanView) 3) save it as a JPG/PNG

When you have a JPG file, attach it to your post (described here).

You could just use an image editing program to sketch it out (save as JPG/PNG). Or, like TomGeorge suggested, go old school and draw it on paper and take a pic. Attach the camera JPG as described above.

I just attached the picture as JPG file to this post.

Hope I drew it correct and that it is visible! I would love to hear if I made any mistake or if I did not understand something well.

Sorry I have made a mistake. I will edit it and attach a new picture. Will be right back!