Humidity Temperature 4 Digit 7 Segment Kit
by PlínioP in Circuits > Arduino
1691 Views, 3 Favorites, 0 Comments
Humidity Temperature 4 Digit 7 Segment Kit
This is my first Instructables. I always come here to see what people are doing and I find it amazing what even people without a technical background can make. So, I decided to publish this simple project for the people that enjoy Arduino and need to know their room temperature and relative humidity for whatever reason.
I actually made it recently for a job interview, they challenge me to create a simple project and send them the manual. I accepted the challenge and created this, just for shows. I named the project Hum-Art, because of the words humidity Arduino and temperature, just for fun.
I tried to make it simple, so if you have an Arduino, a sensor, and some other components you can do it too and show off your skills! Hope you have as much fun as I have when playing with Arduino!
P.S.1 The more experienced maker will point out that I could have used some shift register to avoid using all the digital ports. Or that another program/library would be ideal. You are correct it could be better! So never hesitate to give your suggestion to improve these ideas and help the community.
P.S.2 If you are a pro, skip to the Project Setup step. The first part is for beginners.
Supplies
- 1 ea. - Arduino UNO R3 - The “brains” of the kit, Arduino contains the programable Atmega 328p.
- 1 ea. -Small Breadboard - Containing internal connections it allows for fast prototyping so you can get this project running without any concerns with soldering.
- 1 ea. - 4-digit 7 segments LED display, Common Anode - This small display has a very low power consumption which allows direct connection to Arduino.
- 1 ea. -DHT11-5V Low consumption sensor for temperature and relative humidity.
- 30 ea. - Jumper Wire 3”x 28 AWG - With a diverse color and male termination compatible with the Arduino I/O’s.
- 4 ea. - ¼ watt Resistor 220 Ohms.
- 1 ea. - USB -AB Cable with 16”.
Arduino IDE Setup
Before proceeding, we need to install the Arduino IDE to be able to communicate with the Arduino board directly from our computer through our USB-AB cable.
From [1], download and install the Arduino IDE software on your computer according to your Operational System. Files can be founded for most of the commonly used OSs along with all the respective installation instructions
Figure 2- Arduino IDE Download Center [1].
After installation, Click on the Arduino Icon created to open the IDE window, figure 3.
Figure 3- Arduino IDE window.
The first thing that needs to be done is to select the correct Board. Click on “Tools” at the menu bar, then on “Board” and select “Arduino Uno”, figure 4.
Figure 4- Arduino IDE: Selecting correct Arduino Board.
Carefully take the Arduino board and connect it to the computer using the USB - AB cable, figure 5. Be aware of taking due measures to prevent ESD to avoid damages to your Arduino or computer. (Detailed information on electrostatic discharges and measures to avoid damages caused by them, can be found at [5]).
Figure 5- Arduino board connected to a computer.
After connecting, the Arduino board will power up blinking some of the LEDs on the top of the board for a few seconds.
Now, select the correct USB port you are using by
clicking on “Tools” at the menu bar, then click on “Port:”, the correct port should be showing, select it, figure 6. Most of the time the port configures itself automatically, but if not working, try a different USB port on your computer.
Figure 6- Arduino IDE: Selecting correct USB port.
Run a Board Test
Your IDE is ready to be used with your Arduino board. To validate the setup, run the “Blink” test example, available at “File” in the menu bar. Click “Examples”, then “01-Basics”, then “Blink”, figure 7.
Figure 7- Arduino IDE: Selecting example.
The code for this example will appear in the IDE white screen with a simple explanation of how it works and what should be seen on the on-board LED attached to the Pin 13 of the Arduino Board, figure 8. Select the button “Upload” (arrow to the right below the menu bar). It will load the program to the Arduino board (figure 8).
Figure 8- Arduino IDE: Loading program to the Arduino.
You should see a LED blinking fast while the program is being loaded into Arduino. Once it stops, only one LED will blink on and off close to the digital pin 13 in intervals of one second, figure 9. If that happens, the board is ready and the communication with the computer is working.
Figure 9- Arduino Uno: Red LED blinking on the board.
Project Setup
After verifying the Arduino board is being programed correctly and communication with your computer is established, it is time to assembly the Hum-Art kit with all the other components in order to measure and display temperature and relative humidity.
First, disconnect the Arduino board from the computer (remember to care for preventing ESD damages) and mount it to a stable, non-conducting, surface using double-sided tape or small screws.
Take the display and the DHT11 sensor and strategically position them on the breadboard. See figure 10 for the display and sensor pinout. An assembly suggestion is given in figure 11 where the display pin 1 “E” is positioned at the pin line number 5 of the breadboard. The DHT11 sensor pin 1 “-” is positioned at pin line 21, Figures 10 and 11.
For the display, A, B, C, D, E, F, G, represents each one of the seven LED segments that form a digit. The characters D1, D2, D3, D4 are the common anode pints for each of the digits. The “decimal”/ “DP” pin turns on and off the decimal dots beside the digits.
10- Seven Segment Display and HDT11 pinout.
The sensor DHT11 has a much more straight forward pinout, since it has it's on an internal controller it sends a coded signal with temperature and relative humidity directly through pin “S” (signal), being sufficient just to power it up using pins 1 (-) and 3 (+), 5 volts.
Then, position the four 220 ohms resistors in the digital pins from the display, D1, D2, D3, D4, this will limit the current drained from the Arduino to turn the segments on.
11-Assembly suggestion.
Carefully proceed to connect all the other pins to the correspondent pins in the Arduino board according to the diagram in figure 11 and the table of connections in figure 12. The pinout is written on the Arduino board.
From: 7 Seg. Display
To: Resistor
To: Arduino Digital Pins
12-Table for the display connections.
Finish by connecting the sensor DHT11 pin “s” to the pin D9 in Arduino, the pins “+” and “-” to the respective power bar in the breadboard. Then, connect the power bar to the Arduino board +5 volts and ground, respectively. Be careful to not short these terminals, under risk of burning out your Arduino and possibly your computer.
Installing the Libraries
Before running the program created for this project, attachment 1, install the necessary libraries to your Arduino IDE. Go to “Tools” in the menu bar and select “Manage Libraries”, figure 13.
13- Arduino IDE: Install Libraries.
Search for the libraries, “sevseg”, “dht.h” from Adafruit sensors and install them to your computer clinking at the button Install after selecting the library from the list, figure 14. For more information on these libraries or to install directly from the source, see the Github at [7], [8], [9].
14-Arduino IDE: Library Manager.
Project Program
The program with comments can be found in the attachment 1. It is divided into three parts: declaration of libraries and global variables, void setup(), and void loop ().
The first part has the declaration of the libraries, as seen before, “sevseg” is the library used to control the display and “dht” the library that controls the sensor. Then, the global variables to control the execution are declared: “i” and “MT”.
In Arduino, void setup() and void loop() functions must always be present for the compiler to work. These functions simplify the program by dividing it into two main parts: The setup(), where things run only once for setup purposes, such as sensor initialization or port configuration; and the loop(), where things will remain to execute indefinitely as long as there is power or until an interrupt function is called (no interrupt used in this program).
In this setup, the controller must read the signal coming from the sensor DHT and present the information in a four digits display. Since all information cannot be written at the same time on the small four digits display, one solution is to show a portion of it in small intervals (events). Thus, characters indicating what will be shown are presented preceding the corresponding measured values, first for the temperature and then for the relative humidity.
The sequence of events is divided into four individual “if” statements that run according to the count of the global variable “i” for as many as the quantity “MT”. This way, each event runs for some time without slowing down the constant loop and allowing time for the display to be seeing by the user. This aims to solve the challenge of programming in a single core controller a multitask (read sensor, write, read sensor again and write) since many tasks must occur in one passage of the loop avoiding the use of delay() function, (for more on multitask see [10]).
Without this artifice, If we delay the execution of the loop the display will not properly show the readings, and if we do not delay, everything will show so fast that it will not possible for our eye to make sense of the information presented. Remember, the Arduino runs at a 16 MHz frequency and our eyes only 30 to 60 Hz.
Proceed by copying the program in Attachment 1 to the Arduino IDE and upload it to the Arduino board. The board will start showing in sequence the temperature characters “Te-C”, the correspondent value in Celsius, the relative humidity characters “rH”, and the correspondent value in percent, figure 15.
While the board is connected to the computer through the USB-AB cable, it will remain being powered by the 5 volts in the USB. It is possible now to disconnect from the computer and attach the board to an external power source. Arduino UNO, has a female connector for a 5 volts power source if desired. Once connected, the embedded software will start and the readings as well.
Troubleshooting
Bellow, general issues that can occur during the setup of the KIT.
· If during running the display shows the message “ERR”, figure 16, the signal is not arriving at the Arduino pin 9. Check the DHT connections with Arduino and with the power source.
16- Hum-art displaying error.
· If the digits are showing however the numbers are displaying in the wrong order (from the left to the right) check the connections of the pins D1, D2, D3, D4 with the Arduino, refer to the table in figure 12. In addition, check the vector digitPins[] in the program to verify they match the pin connections.
· If the display segments are showing only partially with some staying off, check the connections and verify that all the vector segmentPins[] contain all the numbers correspondent to the digital outputs in figure 12.
· If nothing works, check the connection with the computer, change the USB port used, and test the cable USB-AB for continuity with a multimeter if necessary.
· If the DHT sensor does not respond, keeping the assembly as is, go to “File” in the menu bar of the Arduino IDE, then “Examples” then “DHT sensor library”. Change the DHTPIN from 2 to 9 since we are using digital pin 9 in our setup. Upload to the board and verify it the sensor produces data by checking the “Serial Monitor” in “Tools” at the menu bar. If not working, check connections again.
· If the display is too fast, adjust the value in MT to a number greater than 4000 and lower than 10000.
· If the display is not working at all, run a test on the display alone connecting to it a 5v power source. At the positive terminal attach a 220 ohms resistor, to the other end of this resistor connect to D1. With the negative of the power source, touch A, B, C, D, E, F, G, DP. If all segments light up, change D1 to D2 and repeat until D4.
The Code
// Libraries used: Adafruit DHT, SevSeg
#include
#include
SevSeg sevseg; //Instantiate a seven segment controller object
#define DHTPIN 9 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int i = 0;
int MT = 8000; //set the counter to let the loop cicle for some time in each event
void setup() {
byte numDigits = 4;
byte digitPins[] = {13, 12, 11, 10};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 0};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
sevseg.begin(hardwareConfig,numDigits,digitPins,segmentPins,resistorsOnSegments,updateWithDelays, leadingZeros);
sevseg.setBrightness(10);
dht.begin();
}
void loop() {
//event 1
if (i
if (isnan(dht.readTemperature())) {
//Display error
sevseg.setChars("Err");
}
else {
// Display temp
sevseg.setChars("Te-C");
}}
//event 2
if (i>=MT && i<(2*MT)){
if (isnan(dht.readTemperature())) {
//Display error
sevseg.setChars("Err");
}
else {
// Display temp
sevseg.setNumber((dht.readTemperature()),1);
}}
//event 3
if (i>=(2*MT) && i<(3*MT)){
if (isnan(dht.readHumidity())) {
//Display error
sevseg.setChars("Err");
}
else {
// Display relative humidity
sevseg.setChars("rH");
}}
//event 4
if (i>=(3*MT) && i<(4*MT)){
if (isnan(dht.readHumidity())) {
//Display error
sevseg.setChars("Err");
}
else {
// Display humidity
sevseg.setNumber(dht.readHumidity());
}}
if (i==(4*MT)){i = 0;}
i++;
sevseg.refreshDisplay(); } // Must run repeatedly
References
[1] More about Arduino UNO and Atmega 328p processor
Retrieved on November 20, 2020.
[2] More about 7 segments by 4 digit LED display at: https://osoyoo.com/2017/08/08/arduino-lesson-4-di...
Retrieved on November 20, 2020.
[3] More about DHT11 basic Temperature humidity sensor at: https://www.adafruit.com/product/386
Retrieved on November 20, 2020.
[4] More about basic electronics, breadboard, resistors, and more, at: https://www.makerspaces.com/basic-electronics/
Retrieved on November 20, 2020.
[5] More about Electrostatic Discharge and Arduino
at: https://unboxing-tomorrow.com/do-i-really-need-anti-static-protection-for-my-arduino/
Retrieved on November 20, 2020.
[6] More about online simulators at: https://www.tinkercad.com
Retrieved on November 20, 2020.
[7] More about sevseg library at: https://github.com/DeanIsMe/SevSeg
Retrieved on November 20, 2020.
[8] More about Adafruit library at: https://github.com/adafruit/Adafruit_Sensor
Retrieved on November 20, 2020.
[9] More about DHT sensor Adafruit library at: https://github.com/adafruit/DHT-sensor-library
Retrieved on November 20, 2020.
[10] More about multitasking in Arduino:
https://roboticsbackend.com/how-to-do-multitasking-with-arduino/
Retrieved on November 20, 2020.