How to include Timer.h library to Arduino Uno

Hi everyone,

I am doing project on Live Temperature and Humidity Monitoring over Internet using Arduino and ThingSpeak. I have added the code for this project also. Can anyone pls tell me how to include Timer.h library .

I am getting following error,

Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Admin\Documents\Arduino\Temp_Humidity\Temp_Humidity.ino:4:18: fatal error: Timer.h: No such file or directory

#include<Timer.h>

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The code is here.

[/#include"dht.h"                      // Including library for dht
#include<LiquidCrystal.h>
LiquidCrystal lcd(14,15,16,17,18,19);
#include<Timer.h>
Timer t;
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3);
#define dht_dpin 12 
#define heart 13
dht DHT;
char *api_key="SIWOYBX26OXQ1WMS";     // Enter your Write API key from ThingSpeak
static char postUrl[150];
int humi,tem;
void httpGet(String ip, String path, int port=80);
void setup()
{
 lcd.begin(16, 2);
 lcd.clear();
 lcd.print("   Humidity   ");
 lcd.setCursor(0,1);
 lcd.print("  Measurement ");
 delay(2000);
 lcd.clear();
 lcd.print("Circuit Digest ");
 lcd.setCursor(0,1);
 lcd.print("Welcomes You");
 delay(2000);
 Serial1.begin(9600);
 Serial.begin(9600);
 lcd.clear();
 lcd.print("WIFI Connecting");
 lcd.setCursor(0,1);
 lcd.print("Please wait....");
 Serial.println("Connecting Wifi....");
 connect_wifi("AT",1000);
 connect_wifi("AT+CWMODE=1",1000);
 connect_wifi("AT+CWQAP",1000);  
 connect_wifi("AT+RST",5000);
 connect_wifi("AT+CWJAP=\"1st floor\",\"muda1884\"",10000);
 Serial.println("Wifi Connected"); 
 lcd.clear();
 lcd.print("WIFI Connected.");
 pinMode(heart, OUTPUT);
 delay(2000);
 t.oscillate(heart, 1000, LOW);
 t.every(20000, send2server);
}
void loop()
{
  DHT.read11(dht_dpin);
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  humi=DHT.humidity;
  lcd.print(humi);   // printing Humidity on LCD
  lcd.print(" %    ");
  lcd.setCursor(0,1);
  lcd.print("Temperature:");
  tem=DHT.temperature;
  lcd.print(tem);   // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C   ");
  delay(1000);
  t.update();
}
void send2server()
{
  char tempStr[8];
  char humidStr[8];
  dtostrf(tem, 5, 3, tempStr);
  dtostrf(humi, 5, 3, humidStr);
  sprintf(postUrl, "update?api_key=%s&field1=%s&field2=%s",api_key,humidStr,tempStr);
  httpGet("api.thingspeak.com", postUrl, 80);
}
//GET https://api.thingspeak.com/update?api_key=SIWOYBX26OXQ1WMS&field1=0
void httpGet(String ip, String path, int port)
{
  int resp;
  String atHttpGetCmd = "GET /"+path+" HTTP/1.0\r\n\r\n";
  //AT+CIPSTART="TCP","192.168.20.200",80
  String atTcpPortConnectCmd = "AT+CIPSTART=\"TCP\",\""+ip+"\","+port+"";
  connect_wifi(atTcpPortConnectCmd,1000);
  int len = atHttpGetCmd.length();
  String atSendCmd = "AT+CIPSEND=";
  atSendCmd+=len;
  connect_wifi(atSendCmd,1000);
  connect_wifi(atHttpGetCmd,1000);
}
void connect_wifi(String cmd, int t)
{
  int temp=0,i=0;
  while(1)
  {
    lcd.clear();
    lcd.print(cmd);
    Serial.println(cmd);
    Serial1.println(cmd); 
    while(Serial1.available())
    {
      if(Serial1.find("OK"))
      i=8;
    }
    delay(t);
    if(i>5)
    break;
    i++;
  }
  if(i==8)
  {
   Serial.println("OK");
        lcd.setCursor(0,1);
      lcd.print("OK");
  }
  else
  {
   Serial.println("Error");
         lcd.setCursor(0,1);
      lcd.print("Error");
  }
}code]

Post a link to where you found this code. Please use the chain links icon on the toolbar when you post links to the forum to make them clickable.

Well that wasn't very helpful. I always wish authors would put a link to the library dependency in the tutorial or a comment in the sketch code.

Give this a try:

  1. Click this link to download the library:
    https://github.com/JChristensen/Timer/archive/master.zip
  2. Select Sketch > Include Library > Add .ZIP Library... from the Arduino IDE menus.
  3. Select the downloaded ZIP file (Timer-master.zip)
  4. Click the "Open" button.

Hopefully after that the sketch will compile.

Thanks a lot . It works fine.
But then i got following error

Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\Admin\Documents\Arduino\libraries\DHT_sensor_library\DHT_U.cpp:22:0:

C:\Users\Admin\Documents\Arduino\libraries\DHT_sensor_library\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

#include <Adafruit_Sensor.h>

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You need to install that library too:

I have added that library .

For DHT libraray , I added library from

But still I am getting following errors

Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Admin\Documents\Arduino\Temp_Humidity\Temp_Humidity.ino:2:56: fatal error: Adafruit_Sensor.h: No such file or directory

#include<Adafruit_Sensor.h>// Including library for dht

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Also , when I write #include<Adafruit_Sensor.h>, it is not coming in bold and orange color

PavamanaKJ:
For DHT libraray , I added library from
GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors

If you read the README.md file for that library you will see it says:

You must have the following Arduino libraries installed to use this class:

Adafruit Unified Sensor Library

If you follow the instructions in my previous reply that library should be installed.

PavamanaKJ:
Also , when I write #include<Adafruit_Sensor.h>, it is not coming in bold and orange color

That doesn't make any difference. It just means that Adafruit_Sensor isn't in any keywords.txt file. That library doesn't even have a keywords.txt file. It makes absolutely no functional difference. It's just cosmetics.

How to download libraries from this website
Arduino/libraries/DHTlib at master · RobTillaart/Arduino · GitHub even though there is no option for downloading. This library may suit my program. If I have to add other library, then i need to change whole program.

That repository is kind of annoying because he lumped a bunch of unrelated stuff into the same repository instead of giving each its own but still easy enough to install them. You will need to navigate to the root of the repository, where you will find the usual "Clone or Download" link, download the entire repository, then install only the library you want from the repository.

Detailed instructions:

But when I tried to add that library , I am getting following errors.

[/Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Admin\Documents\Arduino\Temp_Humidity\Temp_Humidity.ino:1:16: fatal error: dht.h: No such file or directory

 #include<dht.h>

                ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.
Specified folder/zip file does not contain a valid library

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
code]

You didn't correctly follow my instructions. Read them again carefully.

Actually I did what you said. I have attached the photos

Wrong. I didn't tell you to change your sketchbook location. I told you to copy the folder from the downloaded zip file to your sketchbook folder. I only mentioned File > Preferences as a way to find your sketchbook folder if you didn't already know where it was. Change the sketchbook location in preferences back to C:\Users\Admin\Documents\Arduino and leave it there.

Do you know how to copy folders from one place to another on your computer?

Okay. I corrected my mistake. Can you pls tell me the solution for following errors

[/Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

WARNING: library DHTlib claims to run on [atmelavr] architecture(s) and may be incompatible with your current board which runs on [avr] architecture(s).
libraries\DHTlib\dht.cpp.o (symbol from plugin): In function `dht::_readSensor(unsigned char, unsigned char, unsigned char)':

(.text+0x0): multiple definition of `dht::_readSensor(unsigned char, unsigned char, unsigned char)'

sketch\dht.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\DHTlib\dht.cpp.o (symbol from plugin): In function `dht::_readSensor(unsigned char, unsigned char, unsigned char)':

(.text+0x0): multiple definition of `dht::read11(unsigned char)'

sketch\dht.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\DHTlib\dht.cpp.o (symbol from plugin): In function `dht::_readSensor(unsigned char, unsigned char, unsigned char)':

(.text+0x0): multiple definition of `dht::read(unsigned char)'

sketch\dht.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
code]

Programs for dht.cpp and dht.c are here.

Open C:\Users\Admin\Documents\Arduino\libraries\DHTlib\library.properties in a text editor

  • Change the line:
architectures=atmelavr

to:

architectures=avr
  • Save the file
  • Restart the Arduino IDE if it's running.

I have submitted a pull request to fix this issue:

Okay. I dint get warning now. what about others errors??? If you knoe , pls tell me

Do you have any files other than Temp_Humidity.ino in the C:\Users\Admin\Documents\Arduino\Temp_Humidity folder?