Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Arduino so im still getting used to it...ineed to read the temperature of temperature sensor in arduino. Whatever i do, it keeps displaying same temperature(don't even know if that's wrong, but i think the temperature should be changing) over and over again. Dunno what i've done wrong, but here is my code anyway...

int senzor = 0; 
int ldr = 0;
int ldr_vrednost = 0; 
int ldr_sensitivity = 500; 

void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() 
{

int vrednost = analogRead(senzor); 

float napetost = (vrednost) * (5.0/1024.0);

float temperatura = (napetost - 0.5) * 100;

Serial.print("Stopinj C: "); Serial.print(temperatura);
Serial.println();

int vrednost_ldr = analogRead(ldr);
Serial.print("Svetlobni senzor: "); Serial.print(vrednost_ldr);
Serial.println();

if (vrednost_ldr < ldr_sensitivity) 
  {
    digitalWrite(13, HIGH);
  }
else
  {
    digitalWrite(13, LOW);
  }

delay(2000); 
}

And the connection...

enter image description here

Result:

enter image description here

Any help will be appreciated!

share|improve this question

migrated from electronics.stackexchange.com Mar 5 at 0:00

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

    
What sensor are you using? How are the connections made on the sensor? – Josh Jobin Mar 5 at 0:07
    
it's a temperature sensor (tmp36). don't you see the connections on the picture?. btw i'm using online simulator on arduiono website...is the temperature not changing because it's a simulator? – fox Mar 5 at 0:09
    
Two suggestions: measure the sensor output with a multimeter, and print the raw value from analogRead() – uint128_t Mar 5 at 0:13
    
You could've mentioned you're using a simulator in the first place... that sort of changes things. – Matti Virkkunen Mar 5 at 0:14
    
@MattiVirkkunen im sorry, thought the picture was a clear sign, but yeh you're right i should've – fox Mar 5 at 0:14

To continue your simulation with realistic values, you'll need a way for you to supply the values the simulated sensor should supply to the program. The common ways to do this are

  • Each time the simulation needs a value it prompts you to type one;
  • It picks the next value from a table of values you've made a part of the simulation;
  • It runs a user-written function that generates the next value.

What you use may depend on the facilities built into the simulator.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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