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...
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 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...
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 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 program for hotel booking system using C++ Program Requirement 1. You can write any...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any program based on the title assigned. 2. The program must fulfill ALL the requirements below. The requirements listed below are the MINIMUM requirement. Your program may extend beyond the requirements if needed. a) Create at least one (1) base class. b) Create at least two (2) derived classes that inherit from the base class created in 2(a). c) Create at least one (1) object...
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]
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT