The menu example in a previous post can easily be modified to conver the raw A0 analog reading into voltage. Since the Analog Devices AD592 converts temperature into a current proportional to absolute temperature, we can convert this to a voltage using a single resistor. By taking advantage of the Arduino’s 10-bit analog input, we read this voltage and convert to a temperature.
Here’s the updated code:
// Description: // Simple menuing system for Arduino // Demonstrates a menu with controls and // data readback // // Communicates with PC at 115,200 bps 8N1 // #define LED1 2 #define LED2 3 void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); Serial.begin(115200); menu(); } void loop() { int m = readMenu(); switch (m) { case 1: digitalWrite(LED1, HIGH); break; case 2: digitalWrite(LED1, LOW); break; case 3: digitalWrite(LED2, HIGH); break; case 4: digitalWrite(LED2, LOW); break; case 5: { // VT100 reset cursor to end of menu (row 15, column 1) char resetCursor[] = {27,'[','1','6',';','1','H',0}; Serial.print(resetCursor); double temp = analogRead(A0) * 4.9 / 10.0 - 273.1; Serial.print("Temp: "); Serial.print(temp); Serial.println("C"); break; } default: break; } } // Waits in a loop until key is pressed // then returns digit selected int readMenu() { while (!Serial.available()) { delay(100); } return Serial.read() - 48; } // Displays menu void menu() { // Clear char buf[] = {27,'[','2','J',0}; Serial.print(buf); // Print menu Serial.println("\n\n\n\n\n"); Serial.println("1....LED1 on"); Serial.println("2....LED1 off"); Serial.println("3....LED2 on"); Serial.println("4....LED2 off"); Serial.println("5....Read A0"); Serial.println("\n\n Select 1..5"); }
If you’d like to subscribe to this blog, please click here.