PWM IDEA

Okay so im not an electrical engineer im mechanical with a IT degree. Im not a programming expert. Be kind and patient. Well i have an idea to control a motor but i want it to vary with a specific analog input. I am using a thermal couple two pin to control the duty cycle of the PWM. I think i get the math to get it right. If i need to compensate the temperature is two high i can edit the equation to give my desired voltage on the mosfet via duty cycle. Here is my current problem before i get into the math. Via serial and ive never done this and just yesterday began to read on arduino coding. Bare with me.
Can i get a read out of the analog thermal input so i can them modify my math. I need to get a sweet spot on the duty cycle. Whats is occurring is not exponential its like a flat curve. Im controlling a fan and the duty cycle either over does it or doesnt keep up with temperature.

1.Serial readout of analog input
2.Math

To elaborate i would like to understand maybe a IF statement would help. Anything from analogread below 256 makes analogwrite = 0 so 0 duty cycle. Anything 257-1023/3=min duty cycle of 25.2 to 133% (I know it cant go over 33 % but i havent figured out the exponential way to have it respond to a smaller area of the analog input looking like 255-400 out of the whole 1023)Id like the fan to conserve power below a critical point then step in varying with temp.

Sorry for the long write up trying to hit all birds with 1 stone

int ledPin = 9; // pwm to mosfet gate with resistor to ground connected to digital pin 9

int analogPin = 3; // thermal couple connected to analog pin 3

int val = 0; // variable to store the read value

void setup()

{

pinMode(ledPin, OUTPUT); // sets the pin as output

}

void loop()

{

val = analogRead(analogPin); // read the input pin

analogWrite(ledPin, val / 3);

A thermocouple cannot be connected directly to an Arduino and generate useful data - the voltage generated by a thermocouple is miniscule and requires a special chip to read - these are readily available and common on ebay and the usual hobby vendors. A thermistor is another 2-pin device used to read temperature; it requires an appropriately sized external resistor (the details depend on the specific thermistor) - you set it up as a voltage divider where the thermistor is one of the resistors. You will need to do a bit of math to convert the value to a temperature. There are also a wide variety of temperature sensing IC's that output data either digitally or as a linear analog voltage, which may make the processing easier.

Your specific needs will dictate which type of sensor is appropriate - considerations of accuracy and precision, as well as things like how you mount the sensor (for example, if it's inside an oven at a couple hundred degrees, you need a thermocouple rated for those temperatures, if it's underwater, you need a waterproof sensor, etc)

Generally speaking, that idea looks very feasible.

cyrut2:
Can i get a read out of the analog thermal input so i can them modify my math. I need to get a sweet spot on the duty cycle. Whats is occurring is not exponential its like a flat curve. Im controlling a fan and the duty cycle either over does it or doesnt keep up with temperature.

If you want to control the speed of a fan to keep a heat source cooled to a specific temperature you should probably study "PID Loops". This is a feedback control loop that uses the current temperature, the rate at which it is changing, and the amount of time it has been over or under temperature to calculate how fast to run the fan. If has to be tuned for your specific system but once tuned it does a good job of stabilizing the temperature.

You are right my appologies not thermo couple its a thermosistor and yes i though of doing a r2+r1/R1 divider to get the appropriate range i was looking for.

Maybe there lies the answer create the voltage range from the divider to increase the analog range and the compensate the math on the analogwrite.

Let me try it out and ill give the results from what i got.

Im going to try to create a lookup table from what results i get to compensate the PWM duty cycle.

Link of what i found

http://playground.arduino.cc/ComponentLib/Thermistor

Thanks got alot to read up on.

I appreciate the quick and informative responses.

I didnt even know that these little guys could do loops and control scenarios.

Cool