DC motor and a LM35

Greetings! I have a project I am trying to build but I am new to all this so I ask from you as much help as you can give me :slight_smile: I need to build a circuit with a temperature sensor LM35 connected to analog in and a DC motor. When the temperature is lower than 30°C the motor doesn't spin. When the temperature is ranging from 30°C<T<=40°C the motor spins on 50%, and when the temperature is over 40°C the motor goes all out and spins on 100%. I need help with the wiring and coding. Thank you very much!

Take it one step at a time!

Have you found the information about how to wire-up and read the LM35? If you have trouble, you can read the "raw data" using the Analog Read Serial example.

BTW - You don't actually need to convert the reading to degrees if you can figure-out the raw readings that correspond to the temperatures of interest.

Even though you don't need to display the temperature in your "final product", you can use the serial monitor (as in the Analog Read Serial example) to "watch" what your program is doing. You can display the temperature (or the raw ADC readings, or the voltage) from the LM35 and you can send-out little messages like "motor off" or "motor half-speed", etc.

You can't drive a motor directly with the Arduino. [u]Here is a motor driver circuit[/u]. You can use [u]analogWrite()[/u] to adjust the motor speed. Note that 50% PWM (127) may not correspond to 50% motor speed, so you may have to experiment. ...Actually, you can use digitalWrite() for off & full speed if you wish, and analogWrite() for half-speed.

Before you connect a motor you can experiment with dimming an LED. If you use the built-in Pin-13 LED you can test the "motor speed" output without connecting any additional hardware.

You can work on controlling motor speed with software before integrating the temperature sensor.

Once you can read the temperature and control motor speed, you can use [u]if-statements[/u] (or if/else statements) to control the speed depending on temperature.