Question

In: Electrical Engineering

Write a Micro C program to: -Measure temperature using LM35 -Show the temperature on LCD You...

Write a Micro C program to:
-Measure temperature using LM35
-Show the temperature on LCD

You can use headers. if you use header, send headers with main code as homework.

Solutions

Expert Solution

/* LCD + LM35 Temperature sensor arduino sketch
includes fahrenheit and kelvin modes
push button to chnage modes
default 10 minutes inactivity power off time
*/
#include <avr/sleep.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd (10, 9, 8, 7, 6, 5);

byte degree[8] =
{  
0b00000,
0b11100,
0b10100,
0b11100,
0b00000,
0b00000,
0b00000,
};

const int buttonPin = 1; // the pin that the pushbutton is attached to
const int tempPin = 0;
const long interval = 500; // the delay in milliseconds for the temperature reading to update
unsigned long previousMillis = 0;
int buttonState; // current state of the button
int lastButtonState; // previous state of the button
float tempC = 0;
float tempF = 0;
float tempK = 0;
int reading = 0;
unsigned long pwrofftime = 600000; //initial time before powering down in milliseconds
int tempmode = 0; //0 = celcius, 1 = fahrenheit, 2 = kelvin


void setup()
{
analogReference(INTERNAL); //sets the reference voltage for Arduino's ADC to 1.1 volts
pinMode(buttonPin, INPUT);
lcd.begin(8, 2);
lcd.createChar(8, degree);
lcd.setCursor(0, 0);
lcd.print("Hello");
lcd.setCursor(0, 1);
lcd.print("World!");
delay(1000);
}

void loop()
{
buttonState = digitalRead(buttonPin);
unsigned long currentMillis = millis();

if(buttonState != lastButtonState)
{
if (buttonState == LOW)
{
lcd.clear();
tempmode = tempmode + 1;
if(tempmode > 2)
{
tempmode = 0;
}
if(tempmode == 0)
{
lcd.setCursor(0, 0);
lcd.print("Celsius");
lcd.setCursor(0, 1);
lcd.print("Mode");
}
else if(tempmode == 1)
{
lcd.setCursor(0, 0);
lcd.print("Fahrenhe");
lcd.setCursor(0, 1);
lcd.print("it Mode");
}
else if (tempmode == 2)
{
lcd.setCursor(0, 0);
lcd.print("Kelvin");
lcd.setCursor(0, 1);
lcd.print("Mode");
}
}
pwrofftime = pwrofftime + currentMillis;
delay(500);
lastButtonState = buttonState;
}

if(currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;  
int reading = analogRead(tempPin);
tempC = reading / 9.31;
tempF = (9/5)*tempC + 32;
tempK = tempC + 273.15;
lcd.setCursor(0, 0);
if(tempmode == 0)
{
lcd.print("TempC: ");
lcd.setCursor(0, 1);
lcd.print(tempC);
lcd.write(8);
lcd.print("C ");
}
else if(tempmode == 1)
{
lcd.print("TempF: ");
lcd.setCursor(0, 1);
lcd.print(tempF);
lcd.write(8);
lcd.print("F ");
}
else if(tempmode == 2)
{
lcd.print("TempK: ");
lcd.setCursor(0, 1);
lcd.print(tempK);
lcd.write(8);
lcd.print("K ");
}
}
if(pwrofftime < currentMillis)
{
sleep();
}
}


void sleep()
{
lcd.setCursor(0, 0);
lcd.print("Powering");
lcd.setCursor(0, 1);
lcd.print(" Down...");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("Powered ");
lcd.setCursor(0, 1);
lcd.print(" Down.");
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
}


Related Solutions

Write a Micro C program to: -Measure temperature using LM35 -Show the temperature on LCD You...
Write a Micro C program to: -Measure temperature using LM35 -Show the temperature on LCD You can use headers. if you use header, send headers with main code as homework.
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Write a C# Program (using loops) to read temperature of the 7 days of the week...
Write a C# Program (using loops) to read temperature of the 7 days of the week (one day at a time) and calculate the average temperature of the week and print it.
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program...
Write in java Q 4.Centigrade and Fahrenheit are two scales to measure temperature. Write a program that that prompts the user to enter Centigrate and then print the Fahrenheit. Use following formula for conversion. Fahrenheit = Centigrade*1.8 +   32 ; Q. 7 Write a program to calculate the bill of a customer. The program will -           Prompt the employee to enter the monthly plan fees. -           Prompt the employee to enter the rate per additional minute. -          Print the bill...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that is in Fahrenheit for some water. Input the temperature (either an int or a double).   then output one of three statements: if the temperature is below 32 degrees or below tell them it is ice. For example if they input 22 then the output would be: At a temperature of 22 degrees the water would take the form of ice. if the temperature is...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the corresponding temperature in Celsius and print it prompt the user if they want to do another temperature conversion if the user enters y, repeat 1), 2) and 3) if the user enters n, then print Bye and exit the program if the user enters any other character, ask the user to enter y or n only Note : c = (5.0/9.0)*(f-32.0) Sample output Enter...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Write a C program to show sum of 10 elements of array and show the average....
Write a C program to show sum of 10 elements of array and show the average. [10]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT