Your shopping cart is empty!
Maker Uno Portable GPS With DHT 11
- Hussien Jawhar Sathik
- 14 Mar 2022
- Tutorial
- 1159
Introduction
In this tutorial, we shall see how we can build a Maker Uno portable GPS with DHT 11 using the Arduino Uno form shields and other electronic devices.
Video
Hardware Preparation
This is the list of items used in the video.
Building The Circuit
- Building the circuit for this tutorial is pretty straight forward since we have used the shield type board. Hence all the boards are stacked on top of another as shown in the video. The DHT 11 is connected to port D2 on the grove base shield and the lcd is connected to port I2C of the grove base shield as well.
Once the connection are made as per the figure above, we can now start to code.
Code
For the code, initially i have use a code to check if the GPS is giving the correct coordinate. Once we confirmed that the code is working fine and we are receiving the serial output, we use this data to feed to the u-center software.
/*
Demo code for GPS Shield
It records the GPS information onto the TF card,
and display on serial monitor as well.
http://makerstudio.cc
*/
#include
#include
#include
const int chipSelect = 10;
SoftwareSerial mySerial(6,7);//(RX,TX), (6->GPS_TX,7->GPS_RX)
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
return;
}
}
void loop()
{
// make a string for assembling the data to log:
char index = 0;
char temp = 0;
String dataString = "";
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if(dataFile)
{
while(mySerial.available())
{
temp = mySerial.read();
Serial.print(temp);
dataString += String(temp);
index++;
if(index>200)
break;
}
dataFile.print(dataString);
dataFile.close();
}else
{
Serial.println("Open file failed");
}
}
Below is the output from the u-center software
Once we have confirmed the GPS data, now we can upload the final program and check the result.
#include
#include "DHT.h"
#include
#include
#include "rgb_lcd.h"
rgb_lcd lcd;
SoftwareSerial mySerial(6,7);//(RX,TX), (6->GPS_TX,7->GPS_RX)
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// The TinyGPSPlus object
TinyGPSPlus gps;
const int chipSelect = 10;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
Serial.begin(115200);
mySerial.begin(9600);
dht.begin();
}
void loop() {
//put your main code here, to run repeatedly:
while (mySerial .available() > 0)
gps.encode(mySerial.read());
double h = dht.readHumidity();
double t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature: ");
Serial.println(t);
lcd.setCursor(0, 0);
lcd.print(gps.location.lat(), 5);
lcd.setCursor(9, 0);
lcd.print(gps.location.lng(), 5);
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.setCursor(2, 1);
lcd.print(t);
lcd.setCursor(9, 1);
lcd.print("H:");
lcd.setCursor(11, 1);
lcd.print(h);
displayInfo();
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
Outcome
Thank You
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.
"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."