Pages: [1]   Go Down
Author Topic: Intro and temp controlled DC motor  (Read 1794 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm new to PIC's and general electronics but I've been making progress.

I've been working on a climate control system replacement for an old car which originally used a feedback system that controls a water valve, the blower speeds and some vacuum functions. So far I've managed to build a servo controlled valve and do some 12V switching of auto headlights with the Arduino and a MOSFET. (I'm using the headlight as a proxy for the blower motor before moving on to more complicated PWM for the motor)

I was very excited to get the Arduino to control the servo (RC servo) valve by using examples and tinkering with the code. I was even more excited when I managed to get the Arduino to switch a high amp load like a 12V headlight! Baby steps, but I'm learning and things are looking a lot more feasible than when I started!

I'm actually amazed by the power of these little assemblies and I'm having trouble keeping focused because of all the possibilities!

Now that I'm getting the hardware nailed down I need some nudges towards successful programming.

The system I'm working on will require a few things:

1- It will need an input for the ambient temp and:
2- It will require a "Set Point" controlled by a potentiometer and:
3- It needs to be "smart" enough to increase/decrease the blower speed based on how much difference there is between the "set Point"         and the ambient temp and:
4- open/close the water valve when the "Set-Point" requires more/less heat.

For now I'm working out the blower speeds. I was thinking about having 4-5 different speeds using PWM. Most of the tutorials seem to focus on using a pot to increase/decrease speeds but I'm looking for guidance on how to have multiple speeds controlled via the Arduino. My first thought is using different pins to output different values. Pin 1- low, Pin 2- med low, pin 3 - med, etc. I understand that not all pins will output PWM but hopefully someone gets the idea.

For starters I would like to program (Or adapt some existing programs) to start out at one speed and switch through several other speeds. Similar to making an LED on, then blink, then change the blink rate etc. That way I can see the code in action and hopefully learn some things I can build upon. I'm sorry about the LED example, but it seems that I'm learning a lot by making little LED's flash.

I have NO experience with programming other than G/M code work years ago (CNC Machines) and some tinkering with HTML.

Sorry about the long post but I'm new to this and it's a bit complicated to me. I have a "fuzzy" idea about how to proceed but no real world experience.

Thanks in advance! I hpe this makes sense.

Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, and welcome !
I'm actually amazed by the power of these little assemblies and I'm having trouble keeping focused because of all the possibilities!
Agreed.  Before you know it your calendar is full of projects for sure smiley
The system I'm working on will require a few things:

1- It will need an input for the ambient temp and:
2- It will require a "Set Point" controlled by a potentiometer and:
3- It needs to be "smart" enough to increase/decrease the blower speed based on how much difference there is between the "set Point"         and the ambient temp and:
4- open/close the water valve when the "Set-Point" requires more/less heat.

For now I'm working out the blower speeds. I was thinking about having 4-5 different speeds using PWM. Most of the tutorials seem to focus on using a pot to increase/decrease speeds but I'm looking for guidance on how to have multiple speeds controlled via the Arduino. My first thought is using different pins to output different values. Pin 1- low, Pin 2- med low, pin 3 - med, etc. I understand that not all pins will output PWM but hopefully someone gets the idea.
Okay, quite a few ideas there.  But the good news is you won't be needing all those pins.  If you go checkout any of the tutorials for controlling LED brightness by PWM you'll find that they're all done on the one pin, just varying the value output.  That means for your 4-5 different speeds, all you'll be doing is setting the PWM value for that output pin to a known PWM value.  You'll use AnalogWrite() to do this http://arduino.cc/en/Reference/AnalogWrite

Now, stepping back through your requirements:
1) there are a heap of different temperature sensors you can use.  Some of the simplest to use are the LM35 types, which you just setup on an analog pin.  A great tutorial on these is here http://www.ladyada.net/learn/sensors/tmp36.html
2) Very easy, you'll just need to work out what relationship between temperature and pot value you want (potentiometer tutorial here http://www.arduino.cc/en/Tutorial/Potentiometer)
3 & 4) This will require you to define the rules for it to conform with, and then code the logic to make it happen.  Since you're on track to control the fan and servo, look to the if/else structure to make it do what you need based on the values of the pot and the thermometer (http://arduino.cc/en/Reference/Else).

And that's all there is to it  smiley

Cheers !
Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Full Member
***
Karma: 0
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Geoff!

I have the day off so I'm tinkering some.

I managed to get a big 12v DC motor (Pulls about 15 amps) working using the "fade" example here:
-------------------------------------------------------------------------------------------------------------------------------------------------------------


/*
 Fading
 
 This example shows how to fade an LED using the analogWrite() function.
 
 The circuit:
 * LED attached from digital pin 9 to ground.
 
 Created 1 Nov 2008
 By David A. Mellis
 modified 30 Aug 2011
 By Tom Igoe
 
 http://arduino.cc/en/Tutorial/Fading
 
 This example code is in the public domain.
 
 */


int ledPin = 9;    // LED connected to digital pin 9

void setup()  {
  // nothing happens in setup
}

void loop()  {
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  }
 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 155; fadeValue +=5) {
    // sets the value (range from 0 to 100):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  }
 
  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 155 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  }
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 55; fadeValue +=5) {
    // sets the value (range from 0 to 100):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  }
 
  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 55 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(500);                           
  } 
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------

I fooled with the code some to get a feel for it.  I still have some weirdness going on like the motor "singing" and my flyback diode getting hot but it looks promising!

I think I need to explore serial input to the computer (I think that's correct) so I can see what's going on with the code.

I really need to start doing a better job of documentation to help me along.

Thanks again for the help! This is really great fun and very satisfying!

Hoff
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Remember too not to try to pull too much power from your Arduino.  It's only good for 500mA (or 40mA per IO pin IIRC) max, so won't drive that big motor on its own.  To change the speed of a motor of that size, look for using some kind of external power supply and a MOSFET (maybe) or a motor driver IC (typically up to 2A per motor that I've seen) - ie use the Arduino to control something that can attenuate a much larger power load than it can on its own.

Since you're only talking about a small number of fixed speeds, this could be done using a resistor pack like they did on the multi-speed fans in cars for in-dash - use your Arduino to switch to each circuit using SCRs, relays or similar (in replacement of physical rotary switch as used in a car), rather than using PWM. 

I'm sure there's a stack of ways others have used here also.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Full Member
***
Karma: 0
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again!

I'm pretty familiar with relays and switching hi power stuff with lo power so I understand the concept. This just takes it to a whole 'nother level!

Here's where I'm at:



The MOSFET on the right is an FDP7045 N-Channel Logic deal. (Like I know what that means  smiley-razz) I put the diode in there to protect the circuit from "flyback". I do actually understand that!

I was surprised when it controlled a big 14 inch, 12v engine cooling fan that I was also testing with! My power supply is only 5 amps and the thermal overload kicked in before the MOSFET even got hot. My little diode did get pretty warm so I'll need one rated for more power.

I'm still working out some of the PWM stuff like what values (0-255, right?) will equal which voltage and motor speeds.

I may end up using a resistor bank like you suggested because the PWM makes a lot of whining noise but it's fun experimenting with!
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm pretty familiar with relays and switching hi power stuff with lo power so I understand the concept. This just takes it to a whole 'nother level!

Here's where I'm at:
<image snip>
The MOSFET on the right is an FDP7045 N-Channel Logic deal. (Like I know what that means  smiley-razz) I put the diode in there to protect the circuit from "flyback". I do actually understand that!
Looks like you've got it covered on the power side then smiley
I'm still working out some of the PWM stuff like what values (0-255, right?) will equal which voltage and motor speeds.
Using the components you have on hand you could write a small sketch combining the input from your potentiometer with PWM output to the motor, and have the present value output to the serial monitor - choose a few values that you like as slow/medium/fast from dialling the potentiometer and use those in your main sketch (combined with 0 = off & 255 = flat out, that you already know).

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3677
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's only good for 500mA (or 40mA per IO pin IIRC)
I think you may be thinking of the polyfuse limit. I believe the max current the board can source is 200mA
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still on track with this...  RS didn't seem to have ANY type of temp sensors in stock so I ordered some lm35's off ebay and I'll resume when they come in.

Another problem I have is finding proper resistors so I ordered a big organized assortment of about 1000 1/4 watts.

I may start a thread on starting out with a decently stocked parts bin.

I also picked up a propeller quickstart board and have been fooling with it more than the UNO.  I don't want to sound like I'm trolling but I'm having more luck with the prop.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still on track with this...  RS didn't seem to have ANY type of temp sensors in stock so I ordered some lm35's off ebay and I'll resume when they come in.

Another problem I have is finding proper resistors so I ordered a big organized assortment of about 1000 1/4 watts.
I also ordered one of those 1000 packs of resistors off eBay, but after it didn't arrive (grr) I went and ordered them independently from Tayda (www.taydaelectronics.com) and have found them to be brilliant.  BTW even after buying those resistors, I've routinely ordered others...the usual suspects are covered but I've always managed to find a requirement for something else.  Same goes for caps and ICs.  But it's all good smiley

Temperature (and other) sensors are easy to pickup from anyone that has a focus on robotics or hobby electronics rather than digi, e14, tayda etc.  Places like Adafruit, Sparkfun, Pololu, DFRobot and their distributors I've found are best.  eBay is also good, but postage from China is hit/miss and can test your patience.  Of course YMMV but since I started loading up the parts bin is the first time I've had to claim credits back from failed PayPal transactions...and I've had a few so far.

Can't comment on the propeller, but this isn't a religion nor a marriage so collecting the whole set won't be frowned upon smiley

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Full Member
***
Karma: 0
Posts: 204
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I ordered the resistors, some temp sensors, some hall sensors and a few of those sr04 ultrasonic sensors. Only about $50US worth of stuff.

All from China  smiley-slim

Hopefully they will get here and it won't take FOREVER...

If all goes well I should have plenty of little doo-dads to keep me busy!

I really need a decent capacitor assortment but I'm not sure which type to start with. Probably electrolytics but I have a repair project that calls for the tantalums. Radio Shack (A US electronics chain) has what looks like a decent variety of components but they never seem to have the EXACT value I need...
Logged

Pages: [1]   Go Up
Jump to: