I made this circuit:

enter image description here

The part with the DC motor is from this tutorial: https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-12-driving-a-motor ( I only use another resistor, with 220 OHM)

As you can see, I also have a TMP36 sensor attached. What I would like to do is this: When the temperature is 25 degrees or more, the motor should turn on.

I have this code:

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures

 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
void setup()
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor 

void loop()                     // run over and over again
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  

 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 

 // print out the voltage
 Serial.print(voltage); Serial.println(" volts");

 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");

 if(temperatureC >= 25){
  analogWrite(9, 250);

 delay(1000);                                     //waiting a second

But I get this result:

0.74 volts
24.22 degrees C
0.74 volts
24.22 degrees C
0.74 volts
24.22 degrees C
0.74 volts
24.22 degrees C
0.74 volts
24.22 degrees C
0.74 volts
24.22 degrees C
0.75 volts
25.20 degrees C <------
0.87 volts
36.91 degrees C
0.66 volts
16.41 degrees C
0.78 volts
27.64 degrees C
0.77 volts
26.66 degrees C
0.84 volts
34.47 degrees C

The point where the sensor measures > 25 degrees, the motor turns on but the circuit gets "poluted" and the temp sensor starts to send all kinds of strange values.

How do I solve this? Thanks in advance!

I got it to work in with the following: http:// i.stack.imgur.com/4GFPH.png

1 Answer 1


Motors tend to use more current than the arduino can supply, try hooking up the motor to a different power supply than the arduino 5V. What most likely is happening, is that when the motor turns on, it alters the value of the voltage, which the temperature sensor is using to tell the arduino what the temperature is. You need to have the temperature sensor hooked up to the arduino to have the reference at the right voltage, so the motor should be on a different power supply. That should fix things.

  • Thank you rocketman412. I can't figure out how to add a battery to the circuit. I've removed the red + and black - wires from the bottom and changed the circuit to this: i.imgur.com/2haaNqd.png But it's not working. Nov 3, 2015 at 9:40
  • I would think connecting the ground of the arduino to the ground of the battery should help. Other than that, I'm not entirely sure why it wouldn't work.
    – bit0fun
    Nov 3, 2015 at 16:19
  • I've just tried it, but still not working :( Nov 4, 2015 at 8:47
  • Did you get the motor to work without the temperature sensor? That may be the issue. What transistor are you using as well? 2n2222s aren't as available now, so if you switched it out for a different one, the different properties of that new transistor could cause it to act the way it is.
    – bit0fun
    Nov 4, 2015 at 15:08
  • I did get it to work without the temperature sensor. As the 2n222's are unavailable, I've used the following: BC547B. The Diode I'm using is 1N4001 50V 1A. Nov 5, 2015 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.