[go: up one dir, main page]

0% found this document useful (0 votes)
17 views10 pages

Arduino: Ambient Temperature Display

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

Arduino

Ambient Temperature Display


Arduino Uno R3
Temperature Monitoring
Temperature Monitoring

Refer to the LM35 Temperature sensor datasheet posted on Titanium:


Example
/*
prints the temperature to the Serial Monitor
*/

const int inPin = 0; // analog pin

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

void loop()
{
int value = analogRead(inPin);
Serial.print(value); Serial.print(" > ");
float millivolts = (value / 1024.0) * 5000;
float celsius = millivolts / 10; // sensor output is 10mV/Celsius
Serial.print(celsius);
Serial.print(" degrees Celsius, ");
Serial.print( (celsius * 9)/ 5 + 32 ); // converts to fahrenheit
Serial.println(" degrees Fahrenheit");
delay(1000); // wait for one second
}
Using the 4-digit 7-segment Display
Using the 4-digit 7-segment Display

The wiring below was used for the example on the next slide.

4-digit 7-seg module <--> arduino uno r3


a-2, b-3, c-4, d-5, e-6, f-7, g-8, dp-9, d1-10, d2-11, d3-12, d4-13
LM35 temperature sensor: 1=5V, 2=arduino pin 14 (A0), 3=gnd
Using the 4-digit 7-segment Display
// bit map for digits 0 to 9, common anode type used

int num_array[10][8] = { { 0,0,0,0,0,0,1,1 }, // 0


{ 1,0,0,1,1,1,1,1 }, // 1
{ 0,0,1,0,0,1,0,1 }, // 2
{ 0,0,0,0,1,1,0,1 }, // 3
{ 1,0,0,1,1,0,0,1 }, // 4
{ 0,1,0,0,1,0,0,1 }, // 5
{ 0,1,0,0,0,0,0,1 }, // 6
{ 0,0,0,1,1,1,1,1 }, // 7
{ 0,0,0,0,0,0,0,1 }, // 8
{ 0,0,0,1,1,0,0,1 }}; // 9

void Num_Write(int);

void setup()
{
// configure display driver pins
for (int i = 2; i < 14; i++)
pinMode(i, OUTPUT);
// turn off all digits
for (int i=0; i < 4; i++) {
digitalWrite(10 + i, LOW);
}
// turn off all segments
for (int i=0; i < 8; i++) {
digitalWrite(2 + i, HIGH);
}
}
Using the 4-digit 7-segment Display
void loop()
{
//counter loop
for (int digit=0; digit < 4; digit++) {
// turn on selected digit
digitalWrite(10 + digit, HIGH);
for (int counter = 10; counter > 0; --counter)
{
delay(1000);
Num_Write(counter-1);
}
delay(3000);
// turn off selected digit
digitalWrite(10 + digit, LOW);
}
}

// this functions writes numeric values to the 7-seg digit


void Num_Write(int number)
{
int pin= 2;
for (int j=0; j < 8; j++) {
digitalWrite(pin, num_array[number][j]);
pin++;
}
}
Displaying Floating-Point Numbers

• Convert floating-point value to character array. How?


Use the function dtostrf to convert floating-point value
to string (do your own research on how to use this
function)
• Convert each numerical character to number by using:
num = num_character – ‘0’;
• Display one numerical digit at a time from left to right
• Checking for the decimal-point in the string array and
turn on the DP on the corresponding digit

You might also like