Hybrid: Project 3 + Project 5 (Temp Sensor & Servo)


I’m trying to make Arduino move the servo motor by reading the temp sensor.

#include <Servo.h>

Servo myServo;   

int const sensorPin = A0;  
float baselineTemp = 20.0;    
int angle;    

void setup() {

void loop() {
 int SensorVal = analogRead(SensorVal);  
  Serial.print("SensorVal: ");
  float voltage = (SensorVal/1024.0)*5.0;

  for (int pinNumber = 2; pinNumber < 5; pinNumber++);

  Serial.print (",Volts:");
  Serial.print (voltage);
  Serial.print (".degrees C:");
  float temperature = (voltage - .5) * 100;
  Serial.print (temperature); 

if (temperature < baselineTemp) {
  myServo.write (45);
} else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
  myServo.write (90);
} else if(temperature >= baselineTemp+4 && temperature < baselineTemp + 6){
  myServo.write (135);
}else if(temperature >= baselineTemp+6){
  myServo.write (179);

  Serial.print(", angle: ");



In the Serial Monitor I’m not getting any data related to the servo, however I detected that if the servo is not connected to the circuit, the temperature is normal. If it’s connected, then the temp values start going high (an the servo gets very hot) – regardless of the 100uf capacitors.

I’m not sure if I should use the map function or stay with the if / else if functions. Are they exclusionary?

I believe the wiring is OK (since is based on Project 5, I just switched the potentiometer with the TempSensor)

Please, let me know if you can help me out with this.