Need help with sensors not updating

Hi! I have a problem with sensors that won't update. It's two photoresistors and one temperature sensor.
I have that and an lcd hooked up as it says on arduino.cc, but the sensors wont update no matter what I do. The photoresistors show 55 ohms and 56 ohms, and the temperature sensor says -2.46 °C.

Can someone help me with that and how I do to log the data to adafruits sd/datalogger shield + keep the lcd?

Code:

2.1EXPERIMENTAL

2STABLE

Thanks!!!!!

#if Cescius ?

goto
Just say No

How do you have those sensors wired to the Arduino?

KenF:
#if Cescius ?

Error from copy paste, in my code it is celcius.

UKHeliBob:
goto
Just say No

How do I do it without goto?

SurferTim:
How do you have those sensors wired to the Arduino?

Google it and look at the examples at arduino.cc

I have triple-checked the wiring, and so did my dad and grandpa. My dad works with it and has built his own computers and stuff from just components ( resistors, diodes ect.).

Google it and look at the examples at arduino.cc

That is what I expected you to provide. If you can't help yourself by posting the link, how do you expect me to help you?

SurferTim:
That is what I expected you to provide. If you can't help yourself by posting the link, how do you expect me to help you?

Pin 0 is pin A1 for one of the sensors and A2 for the other one.

Temperature sensor

Thanks! :slight_smile:

What does the serial monitor show for the raw analogRead on analog pin 0?

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(0));
  delay(1000);
}

How do I do it without goto?

A while loop would do it neater but there are more fundamental problems with the code. In this section you print 3 variables but you never update them by reading the sensors.

                             #if Celcius
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                delay(100);
                                start:
                                analogRead(tempOne);
                                analogRead(lightOne);
                                analogRead(lightTwo);
                                delay(500);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Temperature");
                                lcd.setCursor(0, 1);
                                lcd.print(temperatureC);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Outside");
                                lcd.setCursor(0, 1);
                                lcd.print(lightReadingOne);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Indoors");
                                lcd.setCursor(0, 1);
                                lcd.print(lightReadingTwo);
                                delay(2000);
                                goto start;

SurferTim:
Thanks! :slight_smile:

What does the serial monitor show for the raw analogRead on analog pin 0?

void setup() {

Serial.begin(9600);
}

void loop() {
 Serial.println(analogRead(0));
 delay(1000);
}

There it updates but shows 142, in my script it updates (but it shows the temperature off with 20 °C).

Your change made the photoresistors work, but they show 100 units off each other when they are taped over with electrical tape.

UKHeliBob:
A while loop would do it neater but there are more fundamental problems with the code. In this section you print 3 variables but you never update them by reading the sensors.

                             #if Celcius

lcd.clear();
                                lcd.setCursor(0, 0);
                                delay(100);
                                start:
                                analogRead(tempOne);
                                analogRead(lightOne);
                                analogRead(lightTwo);
                                delay(500);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Temperature");
                                lcd.setCursor(0, 1);
                                lcd.print(temperatureC);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Outside");
                                lcd.setCursor(0, 1);
                                lcd.print(lightReadingOne);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Indoors");
                                lcd.setCursor(0, 1);
                                lcd.print(lightReadingTwo);
                                delay(2000);
                                goto start;

How do I update them without double declaring them? I still want them in the #if Farenheit part.

You will get some variation between units. If they show exactly the same value, you are just lucky.

How do I update them without double declaring them? I still want them in the #if Farenheit part.

How about using the same variables for both C and F, reading the values and doing the conversions just before displaying them ? As it is when you are stuck in one of the endless goto loops that you have created you never read the sensors into variables so you cannot do the conversion anyway.

I take it that you realise that the start of the loop() function will only run once in your current code.

Most of the code in your goto loops is duplicated. Why not create a function with a parameter flagging degrees C or degrees F, call the function, read the sensors, do the conversion based on the flag, display the appropriate text based on the flag and the converted temperatures.

I found with the problem, the temperature reading (raw value) is 120 in my program, but when I use ladyadas program it is 140. Here is her program witm my modafication to show the raw value too.

    //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.println(reading);
    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");
    // now convert to Fahrenheit
    float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
    Serial.print(temperatureF); Serial.println(" degrees F");
    delay(1000); //waiting a second
    }

What is wrong?!

Can I suggest that you don't go off at a tangent and get hung up about accurate values until you change your program to read the value more than once in the first place.