Please send help! Anything is appreciated.

I have been working through some of the beginner tutorials and I am running into a problem. I am on project #4 and the project is to have a temperature gauge take a reading and turn on a light depending on the temperature.But it is not even taking a reading, in fact when I plug in the temperature sensor, the lights go dark and when I take out the sensor then all lights turn on. Here is my code:

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

void setup()
{
Serial.begin(9600); // opens a serial port and sets speed to 9600 bits per second

for(int pinNumber = 2; pinNumber<5; pinNumber++) // creates local variable, sets it to 2, tells it to add one each time and stop at 5
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}

}

void loop()
{
// creates local variable, and calls analogRead() to read the pin AO (line 1) and stores that in variable

int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: "); // Prints "Sensor Value"
Serial.print(sensorVal); // and puts in the sensorVal value in

// Converts sensor reading and converts it into voltage

float voltage = (sensorVal/ 1024.0) * 5.0;

Serial.print(" , Volts: ");
Serial.print(voltage);

// Converts the voltage to temp, and sends that to the computer

Serial.print(" , Degrees C: ");

float temperature = (voltage - .5) * 100;// convert the voltage to a temperature in degrees C

Serial.print(temperature);

if(temperature < baselineTemp)
{
digitalWrite(2, LOW);
digitalWrite(3, LOW); // Turns LEDs off for a low temp
digitalWrite(4, LOW);

}

else if(temperature >= baselineTemp+2 && temperature <= baselineTemp+4)
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW); // Turns on 1 LED for a lowish temp
digitalWrite(4, LOW);
}

else if(temperature >= baselineTemp+4 && temperature <= baselineTemp+6)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH); // Turns on 2 LEDs for a meduim temp
digitalWrite(4, LOW);
}

else if(temperature >= baselineTemp+6)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH); // Turns on all LEDs for a high temp
digitalWrite(4, HIGH);
}
delay(1);
}

I was just wondering if you guys could help me find the problem, thanks!

Welcome to the group.

You posted this in the tutorial forum, the projects or programming forum would have been a better place.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Lolo_Shaun:
it is not even taking a reading, in fact when I plug in the temperature sensor, the lights go dark and when I take out the sensor then all lights turn on.

from your description, it IS taking a reading, or you have an electrical problem.

Does anything get printed to the monitor?

Hello Lolo_Shaun

1/Have you verified at least five times your actual wiring?

2/Which Arduino are you using?
3/How is your Arduino powered?

Regards,
bidouilleelec