Skip to content

Commit 5ddbdf4

Browse files
committed
first push
1 parent b9322b0 commit 5ddbdf4

File tree

6 files changed

+261
-0
lines changed

6 files changed

+261
-0
lines changed

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Weather Station with Arduino Uno board, DHT11 Sensor, LCD screen and AWS IOT
2+
3+
This tutorial shows you how to use the [DHT11](https://amzn.to/2Qs9fcV) temperature and humidity sensors with the [Arduino Uno](https://amzn.to/3jmCpqx) board to build a simple weather station that displays current temperature and humidity on an [LCD](https://amzn.to/2FzJdT6) screen and pushes the data to AWS IoT through an [ESP8266](https://amzn.to/3hqqWom) board.
4+
5+
In the **first part**, we'll go through a quick introduction to the sensor, pinout, wiring diagram, and finally the Arduino sketch.
6+
7+
In the **second part**, we'll see how to connect out DYI weather station to AWS IoT in order to store the data, visualize it and run some analytics on it.
8+
9+
PART ONE
10+
========
11+
12+
⚡️ COMPONENTS AND SUPPLIES
13+
--------------------------
14+
15+
<img align="right" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/esp-32.jpg?raw=true" style="max-width:100%;" height="200">
16+
17+
* [ESP32 Board](https://amzn.to/3jmCpqx)
18+
* [Breadboard](https://amzn.to/2Ei40tP)
19+
* [Jumper Wires](https://amzn.to/2Ehh2ru)
20+
* [DHT11](https://amzn.to/2Qs9fcV) or [DHT22](https://amzn.to/31t7P8l) Temp & Humidity Sensor
21+
* [10k Ohm resistor](https://amzn.to/2Qo7vkW)
22+
23+
24+
EDIT: Or use this [KIT from WayinTop](https://amzn.to/3hxR01A) that already contains everything
25+
26+
🚀APPS
27+
------
28+
29+
* [Arduino IDE](https://www.arduino.cc/en/main/software)
30+
* [AWS cli](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
31+
32+
DHT11 vs DHT22 SENSORS
33+
----------------------
34+
35+
<img align="center" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/DHT11-DHT22-Temperature-Humidity-Sensor.jpg?raw=true">
36+
37+
The [DHT11](https://amzn.to/2Qs9fcV) and [DHT22](https://amzn.to/31t7P8l) sensors are used to measure temperature and relative humidity. These are very popular among makers and electronics hobbyists.
38+
39+
These sensors contain a chip that does analog to digital conversion and spit out a digital signal with the temperature and humidity. This makes them very easy to use with any microcontroller.
40+
41+
The DHT11 and DHT22 are very similar, but differ in their specifications.
42+
43+
The DHT22 sensor has a better resolution and a wider temperature and humidity measurement range. However, it is a bit more expensive, and you can only request readings with 2 seconds interval.
44+
45+
The DHT11 has a smaller range and it's less accurate. However, you can request sensor readings every second. It's also a bit cheaper.
46+
47+
Despite their differences, they work in a similar way, and you can use the same code to read temperature and humidity. You just need to select in the code the sensor type you're using.
48+
49+
Schematic Diagram
50+
-----------------
51+
52+
Wire the [DHT11](https://amzn.to/2Qs9fcV) or [DHT22](https://amzn.to/31t7P8l) sensor to the [ESP32](https://amzn.to/3jmCpqx) development board as shown in the following schematic diagram.
53+
54+
<img align="center" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/schematic.png?raw=true" style="max-width:100%;" height="600">
55+
56+
Installing Libraries
57+
--------------------
58+
59+
To read from the DHT sensor, we'll use the [DHT library from Adafruit](https://github.com/adafruit/DHT-sensor-library). To use this library you also need to install the [Adafruit Unified Sensor library](https://github.com/adafruit/Adafruit_Sensor). Follow the next steps to install those libraries.
60+
61+
Open your Arduino IDE and go to **Sketch > Include Library > Manage Libraries**. The Library Manager should open.
62+
63+
Search for **"DHT"** on the Search box and install the DHT library from Adafruit.
64+
65+
<img align="center" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/adafruit_dht_library.png?raw=true" style="max-width:100%;" height="600">
66+
67+
After installing the DHT library from Adafruit, type **"Adafruit Unified Sensor"** in the search box. Scroll all the way down to find the library and install it.
68+
69+
<img align="center" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/adafruit_unified_sensor_library.png?raw=true" style="max-width:100%;" height="600">
70+
71+
After installing the libraries, restart your Arduino IDE.
72+
73+
THE CODE
74+
--------
75+
76+
Rename the file [secret.h.public](https://github.com/isbkch/esp32-aws-weather-station/blob/master/secrets.h.public) to **secret.h** and edit it with your information:
77+
78+
* 1\. Select your thing from [this page](https://console.aws.amazon.com/iot/home?region=us-east-1#/thinghub)
79+
* 2\. From the left menu, select **Security** and click the button "**Create Certificate**"
80+
* 3\. Now download both files *.cert.pem and *.private.key and replace their content in the **secret.h**. And don't forget to activate your Certificate.
81+
* 4\. Back to the left menu, click **Interact** and copy the HTTPS link then paste it into **secret.h** as well.
82+
83+
Finally, open the file [esp32-aws-weather-station.ino](https://github.com/isbkch/esp32-aws-weather-station/blob/master/esp32-aws-weather-station.ino) with Arduino IDE
84+
85+
PART TWO
86+
========
87+
88+
AWS SETUP
89+
---------
90+
91+
Now that parts are connected and the libraries are installed, it's time to setup the AWS part.
92+
93+
As you see in the diagram below, the ESP board will be sending data through an MQTT topic to AWS IoT Core, we will be applying rules on the raw data and invoking a Lambda that writes the data to a dynamoDB table. Afterwards, we can read that data and display it on a webpage
94+
95+
<img align="center" src="https://github.com/isbkch/esp32-aws-weather-station/blob/master/docs/aws-architecture.png?raw=true" style="max-width:100%;" height="350">

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

platformio.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:uno]
12+
platform = atmelavr
13+
board = uno
14+
framework = arduino
15+
lib_extra_dirs = ~/Documents/Arduino/libraries
16+
monitor_speed = 9600

src/main.ino

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <dht11.h>
2+
#include <LiquidCrystal.h>
3+
4+
#define DHT11PIN 3
5+
dht11 sensor;
6+
7+
// initialize the library with the numbers of the interface pins
8+
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
9+
10+
void setup() {
11+
Serial.begin(9600);
12+
13+
// set up the LCD's number of columns and rows
14+
lcd.begin(16, 2);
15+
16+
// put cursor at the begining of row 0, line 0
17+
lcd.setCursor(0, 0);
18+
19+
// display a welcome message
20+
lcd.print("Temp & Humidity");
21+
// go to second line
22+
lcd.setCursor(0, 1);
23+
lcd.print("Sensor");
24+
25+
lcd.blink();
26+
delay(3000);
27+
lcd.noBlink();
28+
}
29+
30+
void loop() {
31+
32+
// read from the digital pin
33+
int check = sensor.read(DHT11PIN);
34+
35+
// display Hum on the LCD screen
36+
lcd.setCursor(0, 0);
37+
lcd.print("Humidity (%): ");
38+
lcd.print((float)sensor.humidity, 2);
39+
40+
// display Temp on the LCD screen
41+
lcd.setCursor(0, 1);
42+
lcd.print("Temp (C): ");
43+
lcd.print((float)sensor.temperature, 2);
44+
45+
// print Hum on the serial monitor
46+
Serial.print("Humidity (%): ");
47+
Serial.println((float)sensor.humidity, 2);
48+
49+
// print Temp on the serial monitor
50+
Serial.print("Temperature (C): ");
51+
Serial.println((float)sensor.temperature, 2);
52+
53+
delay(2000); // take measurements every 2 sec
54+
}

test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

0 commit comments

Comments
 (0)