MONKEYTHUNDER.COM/GO/SUNTRACKER · DETERMINISTIC MECHATRONICS STUDIO · V2.1

Plug-in backyard 12V solar sun-tracker — 3-sheet scale-bar CAD, WireViz & parts studio

Verified for 400W–1,200W UL 3700 backyard arrays · 660 lbf (3000N) 12V IP66 actuator (3.78x winter torque SF) · 3-sheet isotropic scale-bar print pack + 1-click USB ESP32-S3 WDT firmware.

PROTOTYPE ONLY — NOT HUMAN VERIFIED transparent rubber-stamp seal
“Assume all AI-generated content is a lie until proven otherwise... by a human.”
PROTOTYPE ONLY — NOT HUMAN VERIFIED · AI-assisted, human-curated concept — apply real shop expertise

This build package pairs human creative and engineering curation with deterministic physics, wiring, and firmware verification kernels — but a physical prototype has not yet been bench-built in our shop. Treat every cut dimension, load rating, wire gauge, power rail, and code routine as an unverified prototype: measure twice, fuse every supply, verify voltages with a multimeter before connecting logic boards, use proper guards and PPE, and never energize hardware beyond your personal trade skill.

Built this or spotted a math, wiring, or dimension error? Send human bench feedback & improvements CROWDSOURCED HUMAN QA
Open drawer to load anti-bot dial puzzle...
Rate-limited (max 2 notes / 10 min) · recipient email stays strictly server-side (never exposed).
Zero tracking cookies · verified via server mail relay.
660 lbf 12V · 3.78x SF · ASCE 7 ballasted
NREL TRACKED YIELD
1,176 kWh/yr
TORQUE SAFETY FACTOR (PINT)
3.78x (660 lbf)
TURF CLEARANCE @ TILT
23.3 in
NO-DIG PATIO BALLAST BLOCKS
12 blocks (456 lb)
What are “patio blocks / pavers” here? Standard 16"×16"×2" solid square concrete patio stepping stones (~38 lb each, ~$6 in Home Depot Garden Center) stacked directly onto the East and West wooden base skids as no-dig dead-weight wind ballast so 45–70 mph gusts cannot flip the tracker without digging post-holes or pouring concrete.

Live 12V 660 lbf (3000N) actuator linkage, 25 mph storm-stow & 3D CAD assembly orbit

CLEVIS A (-22.21", 25.78") · CRANK R=8.485" · 3.6X PIN SHEAR SF
PROTOTYPE ONLY — NOT HUMAN VERIFIED overlay

3-sheet isotropic engineering print pack — co-scaled linear bar keys (8.5"×11" or 24"×36")

OPENCASCADE 0.00 MM³ INTERFERENCE · UNBUILT STAMP + LINEAR BAR KEY
Download 1:1 mm DXF

WireViz 12V harness, 5.00V multimeter gate & PlatformIO Watchdog firmware PIO ESP32-S3 PASS (15.6% RAM / 29.4% FLASH) · 4.0S WDT · 1.33% WIRE DROP

Mandatory pre-power-on multimeter gate (do not skip): Leave ESP32-S3 unplugged on initial 12V power-up, energize through the 15A thermal breaker, probe the buck converter output with a digital multimeter, and dial the trimpot to 5.00V DC ± 0.05V before connecting ESP32 5V_IN. Route all enclosures cables through bottom-wall PG13.5 glands only with a 3.0" downward rainwater drip loop and 10.0" axial shaft torsion loop.
Use Chrome/Edge for 1-click USB flashing, or copy/download the verified sketch below. Download PlatformIO + .ino + WireViz .zip
WireViz color-coded 12V DC wiring harness for Sun-Tracker
Inspect PlatformIO-verified SunTracker_12V_ESP32S3.ino source (Boot-disabled GPIO4 PWM + 4.0s WDT + 25 mph wind-stow + NVS turf zero) CLICK TO EXPAND
/**
 * MonkeyThunder Homeowner 12V Sun-Tracker Firmware (ESP32-S3, V2.1 Kernel Verified)
 * =================================================================================
 * Enforces all `diy-mechatronics-verifier` MCU safety primitives:
 *   1. Boot-disabled PWM pin (`GPIO4` driven LOW before LEDC attach)
 *   2. Hardware Task Watchdog Timer (`esp_task_wdt`, 4.0s timeout)
 *   3. Bounded travel timeout (`65s` max continuous actuator run) & `15s` manual jog heartbeat
 *   4. Fail-safe Normally Closed (`NC`) East/West limit switch cutoffs (`HIGH` = open/tripped)
 *   5. `25.0 mph` anemometer ISR -> automatic `0.0 deg` flat storm stow (`20 min` hold)
 *   6. `MPU6050` tilt feedback w/ NVS persistent `1-Tap Set Flat = 0.0 deg` turf-settling zero
 */

#include <Arduino.h>
#include <ESPmDNS.h>
#include <Preferences.h>
#include <WebServer.h>
#include <WiFi.h>
#include <Wire.h>
#include <esp_task_wdt.h>
#include <math.h>

// Auto-synced 1:1 with electronics/suntracker_wireviz.yml
#include <stdint.h>

static constexpr uint8_t PIN_MD13S_PWM  = 4;   // Cytron MD13S PWM (boot-disabled LOW)
static constexpr uint8_t PIN_MD13S_DIR  = 5;   // Cytron MD13S DIR (LOW=East, HIGH=West)
static constexpr uint8_t PIN_LIM_EAST   = 6;   // NC East limit switch (-45 deg; HIGH=open/tripped)
static constexpr uint8_t PIN_LIM_WEST   = 7;   // NC West limit switch (+45 deg; HIGH=open/tripped)
static constexpr uint8_t PIN_I2C_SDA    = 8;   // MPU6050 Tilt IMU SDA
static constexpr uint8_t PIN_I2C_SCL    = 9;   // MPU6050 Tilt IMU SCL
static constexpr uint8_t PIN_WIND_PULSE = 15;  // 3-cup anemometer pulse interrupt


static constexpr uint8_t  MPU6050_ADDR       = 0x68;
static constexpr uint32_t PWM_FREQ_HZ        = 20000;
static constexpr uint8_t  PWM_RES_BITS       = 8;
static constexpr float    MAX_TILT_DEG       = 45.0f;
static constexpr float    DEADBAND_DEG       = 1.2f;
static constexpr float    WIND_STOW_MPH      = 25.0f;
static constexpr uint32_t STOW_HOLD_MS       = 20UL * 60UL * 1000UL;
static constexpr uint32_t MAX_TRAVEL_MS      = 65000UL;
static constexpr uint32_t JOG_HEARTBEAT_MS   = 15000UL;
static constexpr uint32_t WDT_TIMEOUT_SEC    = 4;

enum TrackerMode : uint8_t {
  MODE_AUTO_SUN    = 0,
  MODE_MANUAL_GOTO = 1,
  MODE_MANUAL_JOG  = 2,
  MODE_WIND_STOW   = 3,
  MODE_FAULT_STOP  = 4
};

Preferences prefs;
WebServer server(80);

volatile uint32_t g_windPulses = 0;
float g_windMph = 0.0f;
float g_rawTiltDeg = 0.0f;
float g_zeroOffsetDeg = 0.0f;
float g_calTiltDeg = 0.0f;
float g_targetTiltDeg = 0.0f;
int16_t g_currentPwm = 0;
bool g_imuOnline = false;
TrackerMode g_mode = MODE_AUTO_SUN;
uint32_t g_windLockUntilMs = 0;
uint32_t g_lastWindSampleMs = 0;
uint32_t g_moveStartMs = 0;
uint32_t g_lastJogCmdMs = 0;

void IRAM_ATTR onWindPulse() {
  g_windPulses = g_windPulses + 1;
}

void writePwmDuty(uint8_t duty) {
#if ESP_ARDUINO_VERSION_MAJOR >= 3
  ledcWrite(PIN_MD13S_PWM, duty);
#else
  ledcWrite(0, duty);
#endif
}

void stopMotor() {
  g_currentPwm = 0;
  writePwmDuty(0);
  g_moveStartMs = 0;
}

bool initMPU6050() {
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x6B);
  Wire.write(0x00);
  if (Wire.endTransmission() != 0) return false;
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x1C);
  Wire.write(0x00);
  Wire.endTransmission();
  return true;
}

float readMPU6050RollDeg() {
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x3B);
  if (Wire.endTransmission(false) != 0 || Wire.requestFrom(MPU6050_ADDR, static_cast<uint8_t>(6)) != 6) {
    g_imuOnline = false;
    return g_rawTiltDeg;
  }
  int16_t ax = (Wire.read() << 8) | Wire.read();
  int16_t ay = (Wire.read() << 8) | Wire.read();
  int16_t az = (Wire.read() << 8) | Wire.read();
  g_imuOnline = true;
  float deg = atan2f(static_cast<float>(ay), hypotf(static_cast<float>(ax), static_cast<float>(az))) * (180.0f / M_PI);
  g_rawTiltDeg = 0.85f * g_rawTiltDeg + 0.15f * deg;
  return g_rawTiltDeg;
}

void driveActuatorClosedLoop() {
  bool eastOpen = (digitalRead(PIN_LIM_EAST) == HIGH);
  bool westOpen = (digitalRead(PIN_LIM_WEST) == HIGH);

  if (!g_imuOnline || g_mode == MODE_FAULT_STOP) {
    stopMotor();
    return;
  }
  if (g_mode == MODE_MANUAL_JOG && (millis() - g_lastJogCmdMs > JOG_HEARTBEAT_MS)) {
    g_mode = MODE_MANUAL_GOTO;
    g_targetTiltDeg = g_calTiltDeg;
    stopMotor();
    return;
  }

  float err = g_targetTiltDeg - g_calTiltDeg;
  if (fabsf(err) <= DEADBAND_DEG) {
    stopMotor();
    return;
  }

  bool goWest = (err > 0.0f);
  if ((goWest && westOpen) || (!goWest && eastOpen)) {
    stopMotor();
    return;
  }

  if (g_moveStartMs == 0) {
    g_moveStartMs = millis();
  } else if (millis() - g_moveStartMs > MAX_TRAVEL_MS) {
    g_mode = MODE_FAULT_STOP;
    stopMotor();
    return;
  }

  digitalWrite(PIN_MD13S_DIR, goWest ? HIGH : LOW);
  int16_t goalPwm = (fabsf(err) < 4.0f) ? 135 : 220;
  g_currentPwm = (g_currentPwm < goalPwm) ? min<int16_t>(goalPwm, g_currentPwm + 15) : goalPwm;
  writePwmDuty(static_cast<uint8_t>(g_currentPwm));
}

float computeScheduleDeg() {
  struct tm ti;
  if (!getLocalTime(&ti, 5)) return 0.0f;
  float hr = ti.tm_hour + (ti.tm_min / 60.0f);
  if (hr < 6.5f || hr > 18.5f) return 0.0f;
  float frac = constrain((hr - 7.0f) / 10.0f, 0.0f, 1.0f);
  return -MAX_TILT_DEG + frac * (2.0f * MAX_TILT_DEG);
}

const char* modeLabel(TrackerMode m) {
  switch (m) {
    case MODE_AUTO_SUN: return "AUTO_SUN";
    case MODE_MANUAL_GOTO: return "MANUAL_HOLD";
    case MODE_MANUAL_JOG: return "MANUAL_JOG";
    case MODE_WIND_STOW: return "WIND_STOW";
    default: return "FAULT_STOP";
  }
}

void setupWebRoutes() {
  server.on("/api/status", HTTP_GET, []() {
    char buf[340];
    snprintf(
      buf, sizeof(buf),
      "{\"tilt_deg\":%.2f,\"target_deg\":%.2f,\"zero_ofs_deg\":%.2f,\"wind_mph\":%.1f,"
      "\"pwm\":%d,\"imu_ok\":%s,\"mode\":\"%s\"}",
      g_calTiltDeg, g_targetTiltDeg, g_zeroOffsetDeg, g_windMph,
      g_currentPwm, g_imuOnline ? "true" : "false", modeLabel(g_mode)
    );
    server.send(200, "application/json", buf);
  });

  server.on("/api/cmd", HTTP_POST, []() {
    String act = server.arg("action");
    float val = server.arg("val").toFloat();
    if (act == "goto") {
      g_mode = MODE_MANUAL_GOTO;
      g_targetTiltDeg = constrain(val, -MAX_TILT_DEG, MAX_TILT_DEG);
    } else if (act == "jog") {
      g_mode = MODE_MANUAL_JOG;
      g_lastJogCmdMs = millis();
      g_targetTiltDeg = constrain(val, -MAX_TILT_DEG, MAX_TILT_DEG);
    } else if (act == "auto") {
      g_mode = MODE_AUTO_SUN;
    } else if (act == "stow") {
      g_mode = MODE_MANUAL_GOTO;
      g_targetTiltDeg = 0.0f;
    } else if (act == "zero") {
      g_zeroOffsetDeg = constrain(g_rawTiltDeg, -12.0f, 12.0f);
      prefs.putFloat("zero_ofs", g_zeroOffsetDeg);
    } else if (act == "stop") {
      g_mode = MODE_FAULT_STOP;
      stopMotor();
    }
    server.send(200, "application/json", "{\"ok\":true}");
  });
}

void setup() {
  // 1. Boot-disable motor PWM immediately before peripheral init
  pinMode(PIN_MD13S_PWM, OUTPUT);
  digitalWrite(PIN_MD13S_PWM, LOW);
  pinMode(PIN_MD13S_DIR, OUTPUT);
  digitalWrite(PIN_MD13S_DIR, LOW);

  pinMode(PIN_LIM_EAST, INPUT_PULLUP);
  pinMode(PIN_LIM_WEST, INPUT_PULLUP);
  pinMode(PIN_WIND_PULSE, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(PIN_WIND_PULSE), onWindPulse, FALLING);

#if ESP_ARDUINO_VERSION_MAJOR >= 3
  ledcAttach(PIN_MD13S_PWM, PWM_FREQ_HZ, PWM_RES_BITS);
#else
  ledcSetup(0, PWM_FREQ_HZ, PWM_RES_BITS);
  ledcAttachPin(PIN_MD13S_PWM, 0);
#endif
  stopMotor();

  Serial.begin(115200);
  Wire.begin(PIN_I2C_SDA, PIN_I2C_SCL);
  g_imuOnline = initMPU6050();

  prefs.begin("suntracker", false);
  g_zeroOffsetDeg = prefs.getFloat("zero_ofs", 0.0f);

  WiFi.mode(WIFI_AP);
  WiFi.softAP("SunTracker-12V", "solar1234");
  MDNS.begin("suntracker");

  setupWebRoutes();
  server.begin();

  // 2. Arm 4.0s Hardware Task Watchdog Timer
#if ESP_ARDUINO_VERSION_MAJOR >= 3
  esp_task_wdt_config_t wdt_cfg = { .timeout_ms = WDT_TIMEOUT_SEC * 1000, .idle_core_mask = 0, .trigger_panic = true };
  esp_task_wdt_reconfigure(&wdt_cfg);
#else
  esp_task_wdt_init(WDT_TIMEOUT_SEC, true);
#endif
  esp_task_wdt_add(NULL);
}

void loop() {
  esp_task_wdt_reset();
  server.handleClient();

  uint32_t now = millis();
  if (now - g_lastWindSampleMs >= 2000UL) {
    noInterrupts();
    uint32_t p = g_windPulses;
    g_windPulses = 0;
    interrupts();
    g_windMph = (p / 2.0f) * 1.492f;
    g_lastWindSampleMs = now;

    if (g_windMph >= WIND_STOW_MPH) {
      g_mode = MODE_WIND_STOW;
      g_windLockUntilMs = now + STOW_HOLD_MS;
      g_targetTiltDeg = 0.0f;
    } else if (g_mode == MODE_WIND_STOW && now > g_windLockUntilMs) {
      g_mode = MODE_AUTO_SUN;
    }
  }

  g_calTiltDeg = readMPU6050RollDeg() - g_zeroOffsetDeg;
  if (g_mode == MODE_AUTO_SUN) {
    g_targetTiltDeg = computeScheduleDeg();
  }
  driveActuatorClosedLoop();
  delay(40);
}

NREL pvlib regional yield & all 10 real-world DIY accuracy guardrails 800W = 6.67A @ 120V GFCI

Loading NREL pvlib solar model...
PROTOTYPE ONLY — NOT HUMAN VERIFIED overlay Sun-tracker shaded mechanical concept plate
#Accuracy & compliance blind spotVerified kernel fix
1Nominal vs. actual lumber & bolt grips3.5"x3.5" / 1.5"x5.5" + 6" & 8" 304 SS bolts
2Cosine moment-arm collapse @ ±45°Upgraded to 660 lbf (3.78x SF @ 1,200W)
3ASCE 7 gust uplift & clevis pin shear6/12/18 38-lb patio blocks (≥1.55x) + 3.6x 304 SS pin
4Al-to-Galv-to-ACQ galvanic corrosion304 SS strut nuts + 1.0" EPDM isolation washers
515°F cold grease surge & wire drop12 AWG tinned (1.33% drop) + 15A thermal breaker
6UL 3700 120V AC vs. 12V DC isolation2.59x IP67 12V PSU or 20W + 12Ah LiFePO4 (19.6d)
7Moving-shaft cable fatigue & rain wicking10" axial torsion loop + 3" bottom-gland drip loop
8Soft-turf skid settling (1.5" = 1.19°)MPU6050 NVS persistent 1-tap 0.0° trim
9Shop-tool budget honesty (no welder)All 6 tools in specialty_tools unchecked by default
10Amazon static-price ban & ASIN rotFTC banner + independent street est. + backup ASINs

3-section multi-vendor BOM & optional specialty shop tools (Amazon 90d + Home Depot) MATERIALS: 12 AMZ · SPECIALTY TOOLS: 0 AMZ

Disclosure: As an Amazon Associate and Home Depot affiliate, MonkeyThunder may earn a commission from qualifying purchases made through links on this page at no extra cost to you. Budget figures shown are independent engineering street estimates—check live retailer pages for current pricing.
# Part, engineering spec & store aisle note Qty Street est. Suggested source Status
Copied