Temperature sensor library errors

Temp.h: #ifndef Temp_H
#define Temp_H

#include <Arduino.h>

class Temp {
void tmp(String u, int x);


Temp.cpp: #include “Temp.h”



void Temp::tmp(string u, int x){
int sv = analogRead(x);
if (u == “F”) {
float tmpF = (((sv * 5 / 1024) - 0.5) * 100) * 1.8 + 32;
if (u == “C”) {
float tmpC = (((sv * 5 / 1024) - 0.5) * 100);
if (u == “K”) {
float tmpK = (((sv * 5 / 1024) - 0.5) * 100) + 273.15;
if ( u == “F”) {
return tmpF;
if ( u == “C”) {
return tmpC;
if ( u == “K”) {
return tmpK;

Keywords.txt: Temp KEYWORD1

Error Message: Arduino: 1.8.3 (Windows XP), Board: “Arduino/Genuino Uno”

C:\Documents and Settings\mbryant\My Documents\Arduino\sketch_aug05b\sketch_aug05b.ino: In function ‘void loop()’:

sketch_aug05b:10: error: ‘F’ was not declared in this scope

Serial.println(tmp(F, 3));


sketch_aug05b:10: error: ‘tmp’ was not declared in this scope

Serial.println(tmp(F, 3));


exit status 1
‘F’ was not declared in this scope

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Main Code: #include <Temp.h>

void setup() {
// put your setup code here, to run once:

void loop() {
Serial.println(tmp(F, 3));


Sorry, this is very rushed, but I am very new to libraries, so can anyone help me to fix this?

Endy: this is very rushed,

Evidently. You might explain what you think the problem is, and what your intentions are.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]`` [color=blue]// your code is here[/color] ``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but spaces for no reason just make for more scrolling when we’re trying to read your code.


Serial.println(tmp(F, 3));

you’re attempting to pass a variable to tmp() but you never declared a variable named F, thus the error. From the code I’d guess you had intended this:

Serial.println(tmp("F", 3));

passing a string literal to tmp().