PWM test sketch for Arduino UNO?

General Electronics chit chat
User avatar
LePaul
Posts: 2162
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): Ultimaker Original HBK, Ultimaker 2+
Contact:

PWM test sketch for Arduino UNO?

Postby LePaul » March 1st, 2016, 1:14 pm

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
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?

Postby Amedee » March 1st, 2016, 2:45 pm

You have some transistor in house?
Phil.

User avatar
LePaul
Posts: 2162
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): Ultimaker Original HBK, Ultimaker 2+
Contact:

Re: PWM test sketch for Arduino UNO?

Postby LePaul » March 1st, 2016, 2:48 pm

I might! I have all the contents of the Sparkfun Inventor's Kit and a few odds and ends :)

User avatar
Amedee
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?

Postby Amedee » March 1st, 2016, 2:58 pm

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.
Phil.

User avatar
LePaul
Posts: 2162
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): Ultimaker Original HBK, Ultimaker 2+
Contact:

Re: PWM test sketch for Arduino UNO?

Postby LePaul » March 1st, 2016, 3:05 pm


User avatar
Amedee
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?

Postby Amedee » March 1st, 2016, 3:34 pm

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 ;)
Phil.

User avatar
LePaul
Posts: 2162
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): Ultimaker Original HBK, Ultimaker 2+
Contact:

Re: PWM test sketch for Arduino UNO?

Postby LePaul » March 1st, 2016, 4:26 pm

Can the USB provide enough power?

User avatar
Amedee
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?

Postby Amedee » March 1st, 2016, 4:28 pm

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 ;)
Phil.

User avatar
Amedee
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?

Postby Amedee » March 1st, 2016, 4:31 pm

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)
Phil.

User avatar
LePaul
Posts: 2162
Joined: February 7th, 2016, 10:26 pm
Location: Bangor, Maine USA
3D Printer(s): Ultimaker Original HBK, Ultimaker 2+
Contact:

Re: PWM test sketch for Arduino UNO?

Postby LePaul » March 1st, 2016, 5:39 pm

Oh yes have many of those


Return to “General Electronics Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest