Go Down

Topic: Taking and displaying 10 temperature measurements (Read 42 times) previous topic - next topic


Hi, I'm new to the forum and useless at coding.

I have an Arduino Uno connected with two buttons, two LEDs and a temperature sensor.  I want a program to do the following...

In standby mode, a message appears on my computer saying "stand-by mode" once.  The first LED blinks repeatedly waiting.  The message should appear once, not repeatedly every time the LED blinks.

When button A is pressed the program switches to measuring mode. 

In measuring mode, it will display "measurement mode" once, switch on the second LED and then record 10 temperature measurements.  The temperature sensor will take a measurement every time button B is pressed.  If button B is not pressed withing 5 seconds, it will record the temperature as missed and move onto the next one.  The temperatures will be displayed over the serial link. 

For example:

Standby mode
blinking LED
*button A pressed*
Measurement mode
*button B pressed within 5 s*
Count 1:  Temp = 30 C
*button B pressed within 5 s*
Count 2: Temp = 35 C
*button B not pressed within 5 s*
Count 3: Temp - missed.
repeats until count 10 and returns to standby mode.

If anyone can post the code to achieve this I would be most grateful.  Thanks.


I would like to help you with your project. Can you provide a schematic of the setup?  Please include component values and part numbers.


Hi groundfungus,

I'm just using the components that come in the Arduino starter kit.

The LEDs are connected to inputs 2 and 3 with 220 Ohm resistors on the returns.
The pushbuttons are connected to inputs 6 and 7 with 10 kOhms resistors on the returns.
The temperature sensor is TM36 and connected to input A0.


The pushbuttons are connected to inputs 6 and 7 with 10 kOhms resistors on the returns.
OK, first suggestion is to wire the button switches from ground to the input pin.  Lose the 10K resistor.  In setup you will enable the internal pullup resistor with the pinMode(pin, INPUT_PULLUP) statement.  Put a 100nf cap across the switch (to ground and the input).  The cap will help to debounce the switch to give clean transitions.

The LEDs are connected to inputs 2 and 3 with 220 Ohm resistors on the returns.
May just be semantics, but LEDs connected to inputs are not much good.  Outputs makes more sense.

I will start to work on the code with the above in mind and get back when I have a start.


Thanks groundfungus.  Regards the LEDs I meant outputs.  That was a typo.

Here is my terrible code so far:

<#include <EEPROM.h>

int detectionswitch = 0;
int measurementswitch = 0;
const int sensorPin = A0;

void setup()
  // open a serial port:

  // LED outputs:
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  // switch inputs:
  pinMode(6, INPUT);
  pinMode(7, INPUT);

void loop() {
   detectionswitch = digitalRead(6);
   measurementswitch = digitalRead(7);
   // standby mode:
   Serial.println("STAND-BY MODE");
   if (detectionswitch == LOW)
    digitalWrite(2, HIGH);
    digitalWrite(2, LOW);
   // measurement mode:
    Serial.println("MEASUREMENT MODE. ");

    for (int counter = 0; counter < 10; counter++)
        Serial.print("Count: ");
        int sensorVal = analogRead(sensorPin);
        float voltage = (sensorVal/1024.0) * 5.0;
        float temperature = (voltage - .5) * 100;

        Serial.print(". \t Sensor value: ");
        Serial.print(". \t Voltage: ");
        Serial.print(" V. \t Temperature: ");
        digitalWrite(3, HIGH);
        digitalWrite(3, LOW);


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131