Skip to content

Playing with temperature sensor and Arduino

As said in previous page we need software to program Arduino for our needs.
Here it is, very simple

// Riccardo Giuliani for

// Words after double slash are simply comments, don't affect real code
// Two variables, first accept decimals, second no.
float mycelsius = 0;
int myinput = 0;

// Important function where setup starting conditions
void setup() {
  pinMode(myinput, INPUT);
  pinMode(13, OUTPUT);
  // Serial communication set with a 9600 baudrate

// Main program loop
void loop(){
  //Listening on Arduino's Analog 0 pin
  mycelsius = analogRead(myinput);
  // Calculation of temperature
  mycelsius = (mycelsius*5.0*100)/1024.0;
  Serial.print("start: ");
  //Print result directly in Arduino's serial monitor, and goes ahead

  // Comparing test
  if (mycelsius < 30) {
    digitalWrite(13, LOW);
  else {
    digitalWrite(13, HIGH);
  // 2 seconds delay