Introduction: Odd Use of Watch Dog Timer

What I meant of Odd Use is the result not my expected but exactly what I needed.

I experiment 7 segment LED display driven by 74HC595, I found the circuit and the code to build on, I previously built the DHT11 and 1602 LCD to test the temperature and humidity without problem, now I give it a try to display with 7 segment LED. I found a problem, I cannot run the getData() and displayData() simultaneously in the loop() function, the left three digits kept on flickering, though I still can guess it.

void loop() {



The getData() is the function to fetch data from DHT11, I have heard DHT11 is slowly respond, so I need a method to run it out of the loop().

void getData() {
int humid=0, temp=0;

switch( {

case DHT11::OK:







Step 1: Watch Dog Timer

After research, I found some piece of code regarding Watch Dog Timer, I have no full experience on WDT, I only knew that it will reset the computer if something has not done properly. I merge them and have the getData() put inside the setup() function, when the WDT executing the program will reset once and force run the getData().

From the video you'll find the digits are not flickering any more, but steadily for 3 seconds and blink out 3 second, I don't have to guess it.

#include <DHT11.h>
int pinLatch = 4;

int pinClock = 7;

int pinData = 8;

int pinDht = 2;

unsigned char characterMap[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99,

0x92, 0x82, 0xF8, 0X80, 0X90};

unsigned char characterBuffer[] = {0xF1, 0xF2, 0xF4, 0xF8};

DHT11 dht11(pinDht);

int displayData = 0;

void setup (){

pinMode(pinLatch, OUTPUT);

pinMode(pinClock, OUTPUT);

pinMode(pinData, OUTPUT);

delay (2000);




Step 2: Final Code

There is no final code, the code given here are not my work, I just post here for interesting issue, actually I have post it in the forum as a problem to be solved, if some experts can give me some advises.

void watchdogSetup(void) {

WDTCSR |= (1<<WDCE) | (1<<WDE);

WDTCSR = (1<<WDIE) | (1<<WDE) | (0<<WDP3) |

(1<<WDP2) | (2<<WDP1) | (1<<WDP0);


ISR(WDT_vect) {// Watchdog timer interrupt.