Connect the WDT to your Arduino (or other compatible MCU) in order to provide your 'Arduino' with a watch dog timer. It is a simple two wire hookup (not counting +5V and GND).
If the WDT does not receive a 'heartbeat' from the Arduino within a set time, the WDT will reset the Arduino. A reset prevents the Arduino from locking up due to poor code and/or unexpected event(s).
Solder all components as shown in the following assembly photo. Be careful, as some components have required orientation.
Assembly photo here...Wiring Connections | WDT | Arduino |
---|---|---|
5V | 5V | |
GND | GND | |
HB (heart beat) | Pin 8 (variable, see the Arduino .ino sketch) | |
RST | RESET pin |
//.ino code-
//sample code for the WDT, this code run on the Arduino Leonardo-
int pulsePin = 8;
unsigned long lastHeartbeat = 0;
unsigned long lastUptimeReport = 0;
void heartbeat() {
// bring pin low to sink current, to drain charge from watchdog circuit
pinMode(pulsePin, OUTPUT);
digitalWrite(pulsePin, LOW);
delay(300);
// Return to high-impedance
pinMode(pulsePin, INPUT);
lastHeartbeat = millis();
Serial.println("Heartbeat sent");
}
void setup() {
Serial.begin(9600);
Serial.println("Arduino startup/reset");
// Send an initial heartbeat.
heartbeat();
}
void loop() {
// Check for serial inputs. (This is done in the serial monitor.)
// If found, send a heartbeat.
if (Serial.available()) {
// Clear input buffer
while (Serial.available()) {
Serial.read();
}
heartbeat();
}
unsigned long uptime = millis();
if ((uptime - lastUptimeReport) >= 5000) {
// It has been at least 5 seconds since our last uptime status.
Serial.println("Uptime: " + String((uptime - (uptime % 5000)) / 1000) + " seconds (" + String((uptime - lastHeartbeat) / 1000) + " seconds since last heartbeat)");
lastUptimeReport = (uptime - (uptime % 5000));
}
// delay in between loops
delay(100);
}