Go Down

Topic: Temp Sensor to Output motor voltage (Read 2401 times) previous topic - next topic

tim5989

Hey,

So i have some problems with programming my arduino. I have an LM34 temperature sensor. this sensor is wired into my arduino uno. the ground is in the ground, the Vs is in the 5V, and the Vout is in the A0. i have a 1kOhm resister out of the PWM which is connected to the B of a BJT. the C of the BJT is going to the negative of a 12V DC motor and the E is connected to a 210Ohm resistor. The motors positive is connected to the arduino's Vin. What I am doing is trying to relate the temperature reading from the sensor to control the motors voltage. An suggestions to programming? i am new at all of this. thanks.

RuggedCircuits

Quote
and the E is connected to a 210Ohm resistor


It was all sounding good up to this point. I think E should go to ground. You also didn't mention where the "positive" of the 12VDC motor is going, but I'm assuming it is to 12V.

Also, how are you powering your Arduino? Are you supplying power from Vin? or supplying power from the DC power jack and drawing current from Vin to go to the motor?

Finally, what current is your motor rated for?

As for your code, you can start with something fairly simple: just use analogRead() to read the sensor and analogWrite() to set the motor PWM. If you have started a sketch already you can post it and we can review it.

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

tim5989

I have the positive of the motor going to the Vin on the Arduino...will this work? As for the arduino powering I have 12V plugged into the power jack that is fed from batteries. The motor is rated at 76 mA. here it is right here http://www.jameco.com/Jameco/Products/ProdDS/400995.pdf. So basically what we are doing is making a cricket. crickets chirps are dependent on ambient temp. so we are taking the reading from the temp sensor to set the speed of the motor which will drive 2 wings we have created to make a chirping cricket. the problem is i am not really an electrical guy. im a mechanical engineering student and this is the first time ever using any type of microprocessor. ive gone on arduinos website attempting to understand how to write the code and have even looked at examples. im having a hard time grasping this open source code.

tim5989

also any help is much appreciated. ive asked people in my college's department for help and they have not been too helpful and basically told me to search online and figure it out.

RuggedCircuits

Yes, this should work as long as you're not trying to move cricket wings that are particularly heavy or need a lot of force. Basically, 76mA "no load" is fine but once you actually start trying to do mechanical work that current is going to shoot up, and having it go above 500mA or so is not a great idea.

If you are really new at this then you should become familiar with the components independently. Run some of the example Arduino sketches (AnalogInput, for example) and become comfortable with the temperature sensor and motor independently before trying to make them work together.

--
The Rugged Motor Driver: two H-bridges, more power than an L298, fully protected


tim5989

thank you so much ill try to get a code written tomorrow and ill post it and maybe you could look at it. youre a life saver!

tim5989

Hey so this is what I got...


int tempsensorPin = A0;     
int motorPin = 5;
int sensorValue = 0;
void setup() {pinMode(motorPin, OUTPUT);}
void loop ()
{digitalWrite (motorPin, OUTPUT);
int reading = analogRead(tempsensorPin);
(reading * .037539 - 16.032) * 11.844;
}

so i have the input from the temp sensor. then i used a conversion that spits out a voltage to the motor that is the correct RPMs for my cricket to chirp. Do you think this will work. Also when I went to put it on the arduino uno it had an error of serial port 'Com1" not found. any thoughts? do i need to have all my stuff hooked up to the arduino before i program it?


RuggedCircuits

Code: [Select]
int tempsensorPin = A0;     
int motorPin = 5;
int sensorValue = 0;
void setup() {
  pinMode(motorPin, OUTPUT);
}


So far so good.

Code: [Select]
void loop ()
{
  digitalWrite (motorPin, OUTPUT);   [color=red]// I think you mean HIGH instead of OUTPUT[/color]
  int reading = analogRead(tempsensorPin);
  (reading * .037539 - 16.032) * 11.844;  [color=red]// This line has no effect[/color]
}


Unfortunately the above won't really control the motor speed. Try this:

Code: [Select]
void loop()
{
  int reading;

  reading = (analogRead(tempsensorPin) *0.037539 - 16.032) * 11.844;
  analogWrite(motorPin, reading);
  delay(100); // To prevent jitter
}


--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

tim5989

the motor isnt spinning for some reason.

tim5989

is it because its analogWrite and its coming out the digital pwm? should it be digitalWrite?

RuggedCircuits

No, analogWrite() is correct for PWM control of a digital output (the ones that support PWM at least).

Can you maybe sketch your connections and post? Did you remove the 210 ohm resistor?

--
Beat707: MIDI drum machine / sequencer / groove-box for Arduino

tim5989

for the int sensorValue should it be 0?

RuggedCircuits

It doesn't look like sensorValue is used so you can remove it.

You have to get rid of that 220 ohm resistor from emitter to ground.

You should also add a diode (1N4001, 1N4002, 1N4004, etc.) with anode at collector and cathode at Vin (essentially, across the motor terminals).

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

Go Up