PWM test sketch for Arduino UNO?

General Electronics chit chat
Post Reply
User avatar
LePaul
Reactions:
Posts: 3966
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): 24 - Yes I have a problem!
Contact:

PWM test sketch for Arduino UNO?

Post by LePaul »

I am hoping Amedee can share the UNO sketch and breadboard layout so I can test the new fans I bought.

If they work in this setup, I can consider putting them in my UMO

(reference: viewtopic.php?f=7&t=74&start=45#p859)
User avatar
Amedee
Reactions:
Posts: 599
Joined: February 15th, 2016, 11:10 am
Location: Brussels, Belgium
3D Printer(s): UMO / UMO+
Contact:

Re: PWM test sketch for Arduino UNO?

Post by Amedee »

You have some transistor in house?
User avatar
LePaul
Reactions:
Posts: 3966
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): 24 - Yes I have a problem!
Contact:

Re: PWM test sketch for Arduino UNO?

Post by LePaul »

I might! I have all the contents of the Sparkfun Inventor's Kit and a few odds and ends :)
User avatar
Amedee
Reactions:
Posts: 599
Joined: February 15th, 2016, 11:10 am
Location: Brussels, Belgium
3D Printer(s): UMO / UMO+
Contact:

Re: PWM test sketch for Arduino UNO?

Post by Amedee »

If you can give me the reference of what you have and also the Amp rating of your fan, I can check if it will work and which resistor we need...
You probably need a flyback diode as well (1N400x or whatever) unless the transistor has one builtin.
User avatar
LePaul
Reactions:
Posts: 3966
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): 24 - Yes I have a problem!
Contact:

Re: PWM test sketch for Arduino UNO?

Post by LePaul »

User avatar
Amedee
Reactions:
Posts: 599
Joined: February 15th, 2016, 11:10 am
Location: Brussels, Belgium
3D Printer(s): UMO / UMO+
Contact:

Re: PWM test sketch for Arduino UNO?

Post by Amedee »

You are all set ;)

So you need something like this:
LePaul_schem.png
For the transistor & diode, use what you have.
For the resistor, to be safe use 2 330 Ohms in series.

That gives us on the breadboard
LePaul_bb.png
Now, be careful with the transistor, you need the minus on the emitter and the fan/diode on the collector side (I find the drawing confusing)
Batteries are your 12V battery

Sketch in next episode ;)
User avatar
LePaul
Reactions:
Posts: 3966
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): 24 - Yes I have a problem!
Contact:

Re: PWM test sketch for Arduino UNO?

Post by LePaul »

Can the USB provide enough power?
User avatar
Amedee
Reactions:
Posts: 599
Joined: February 15th, 2016, 11:10 am
Location: Brussels, Belgium
3D Printer(s): UMO / UMO+
Contact:

Re: PWM test sketch for Arduino UNO?

Post by Amedee »

Here it is...

Code: Select all

/*
  PWM Fan Test  
*/

/*
  Arduino Pin assignement
*/

//  Digital
const int usbSerialRxPin     = 0;    // Reserved
const int usbSerialTxPin     = 1;    // Reserved

const int fanPin             = 3;   // Fan control (pwm)


/*
  Globals 
*/
uint8_t fanSpeed = 0;    // Start as ...


/*
  Setup routine
*/
void setup() {
  // Serial
  Serial.begin(9600);

  // Fan pin setup
  pinMode(fanPin, OUTPUT);
  analogWrite(fanPin, fanSpeed);

  Serial.println("Setup done");
  Serial.println("Enter desired fan speed (0-100%)");
}

/*
  Main loop
*/
void loop() {
  // Check input
  if (Serial.available()) {
    long i = Serial.parseInt();
    if (i < 0 || i > 100) {
      Serial.println("Invalid input");
    } else {
      Serial.print("Setting fan to ");
      Serial.print(i);
      Serial.println("%");
      fanSpeed = 255 * i / 100;
      analogWrite(fanPin, fanSpeed);
    }
  }
}
Note that all this is untested ;)
User avatar
Amedee
Reactions:
Posts: 599
Joined: February 15th, 2016, 11:10 am
Location: Brussels, Belgium
3D Printer(s): UMO / UMO+
Contact:

Re: PWM test sketch for Arduino UNO?

Post by Amedee »

LePaul wrote:Can the USB provide enough power?
USB powers the Arduino.

You should power the fan separately (I remember I saw A 12v battery in one of your pictures)
User avatar
LePaul
Reactions:
Posts: 3966
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): 24 - Yes I have a problem!
Contact:

Re: PWM test sketch for Arduino UNO?

Post by LePaul »

Oh yes have many of those
Post Reply

Return to “General Electronics Discussion”