89Views5Replies

Author Options:

I want to build a temperature sensor, any idea? Answered

I'm having problems connecting the wires together and my code is not compiling please help?

#include <LEDDisplay.h>
#include <SevSeg.h>

SevSeg sevseg;

LEDDisplay *led;
int ledPin = 9;
int inputPin = 13;
int core = 0;
int val;
int tempPin = 0;
int buttonState = 0;
float celsius;
int tempUnits = celsius;
int refreshTime = 5000;

unsigned long timer;
float kelvin = 0;

const int buttonPin[] = {2,3};     // the number of the pushbutton pins
const int ledPin =  13;      // the number of the LED pin
void setup(){
  pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
// initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);    
for(int x=0; x<2; x++)
  {
    pinMode(buttonPin[x], INPUT);
  } 

int digitFlagPins[] = {10, 11};
int segmentPins[] = {1, 3, 4, 5 ,6 ,7 ,8, 9, 10};
led = new LEDDisplay(2, digitFlagPins[2], segmentPins[9]);
}
void loop(){
  // read the state of the pushbutton value:
  for(int x=0; x<2; x++)
  {
    buttonState = digitalRead(buttonPin[x]);

    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonState == HIGH && buttonPin[x] == 2) {   
      // turn LED on:  
      digitalWrite(ledPin, HIGH);
    }
    if (buttonState == HIGH && buttonPin[x] == 3) {
      // turn LED off:
      digitalWrite(ledPin, LOW);
   
  }
  }
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
sevseg.PrintOutput();
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 2.5 - 273.15;
unsigned long mils=millis();
  if (mils-timer>=refreshTime) {
    timer=mils;
    //Print teperature to the displays
  sevseg.NewNum(tempUnits,(byte) 2);
  }
delay(1000);
}

Tags:arduino

Discussions

0
None
steveastrouk

3 years ago

What's the point of pressing the buttons ?

This looks like someone else's code edited together.

What's the temperature sensor ?

0
None
Houtarou-steveastrouk

Answer 3 years ago

Well, it is bunch of coeds altogether, but I di some modifications to it today but still having problems:
#include
#include

SevSeg sevseg;

LEDDisplay *led;
//int ledPin = 9;
int inputPin = 13;
int core = 0;
int val;
int tempPin = 0;
int buttonState = 0;
float celsius;
int tempUnits = celsius;
int refreshTime = 5000;

unsigned long timer;
float kelvin = 0;

const int buttonPin[] = {2, 3}; // the number of the pushbutton pins
const int ledPin = 9; // the number of the LED pin
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
sevseg.Begin(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
for (int x = 0; x < 2; x++)
{
pinMode(buttonPin[x], INPUT);
}

int digitFlagPins[] = {10, 11};
int segmentPins[] = {1, 3, 4, 5 , 6 , 7 , 8, 9};
int decimalPointPin=9;
led = new LEDDisplay(2, digitFlagPins, segmentPins,decimalPointPin);
}
void loop() {
// read the state of the pushbutton value:
for (int x = 0; x < 2; x++)
{
buttonState = digitalRead(buttonPin[x]);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH && buttonPin[x] == 13) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
if (buttonState == HIGH && buttonPin[x] == 12) {
// turn LED off:
digitalWrite(ledPin, LOW);

}
}
val = analogRead(tempPin);
float voltage = val * 5.0;
voltage /= 1024.0;

// print out the voltage
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");

/*float mv = ( val / 1024.0) * 5000;
float cel = mv / 10;
sevseg.PrintOutput();
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 2.5 - 273.15;
unsigned long mils = millis();
if (mils - timer >= refreshTime) {
timer = mils;
//Print teperature to the displays
sevseg.NewNum(tempUnits, (byte) 2);
}*/
//led->displayDecimalPoint(temperatureC);
led->displayNumber(2, 1);
led->displayNumber(4, 0);

delay(1000)
}
and the question is Make a temperature monitor. The minimum components should be:

Arduino
A display (numeric LED, or LCD)
Two buttons
Temperature sensor
The behaviour of the system should be:

In the default state, the temperature is displayed on the display.
When button 1 is pressed, the system records ten temperatures at one-second intervals, with some form of indication to show that it is gathering data. When data collection ends, the system should return to the default state, and give some form of indication that it has done so. The temperatures recorded should be stored for later use.
When button 2 is pressed, either:
If there are stored temperatures in memory, the system displays them.
If there are no stored temperatures in memory, the system indicates this.

0
None
steveastroukHoutarou-

Answer 3 years ago

Take it slowly, and in stages. Don't attempt to do everything at once, when you've clearly not written code, and you have a homework project.

Forget Kelvin and Fahrenheit, they are not part of the question. The output of your sensor is probably something like the LM35, a voltage scaled like this

Make that bit work, make it output temperature to the serial port first.

Make the LED display 0..99 on the screen, display 0, wait, display 1 etc. Master that.

NOW make it display temperature.

NOW add code to save temperatures every button press. Make it save them in a circular buffer, so it always displays the last 10 temperatures. Use the decimal points to show you are displaying stored stuff.

0
None
Downunder35m

3 years ago

What wires, what eroor messages?

We won't ask crystal balls around here, so you have to provide thew required details if you expect any useful answers.