/* Session 2 — Core agricultural sensors (Arduino Uno — Tinkercad Circuits version) Tinkercad has no DHT22, so we use: TMP36 (air temperature) on A0, Soil Moisture Sensor on A1, Photoresistor (LDR) with a 10kΩ voltage divider on A2. Real hardware version: s02_sensors_esp32 */ const int TMP36_PIN = A0; const int SOIL_PIN = A1; const int LDR_PIN = A2; // Manual 2-point calibration (session 2 lab): read the sensor in dry soil and in saturated soil int SOIL_DRY = 0; // Tinkercad soil sensor: 0 = dry ... ~876 = wet (real capacitive sensors are inverted!) int SOIL_WET = 876; void setup() { Serial.begin(9600); Serial.println(F("temp_c,soil_raw,soil_pct,light_raw,light_pct")); // CSV header -> paste into Excel } void loop() { // TMP36: 10 mV/°C with 500 mV offset -> T = (V - 0.5) * 100 float v = analogRead(TMP36_PIN) * 5.0 / 1023.0; float tempC = (v - 0.5) * 100.0; int soilRaw = analogRead(SOIL_PIN); float soilPct = constrain((soilRaw - SOIL_DRY) * 100.0 / (SOIL_WET - SOIL_DRY), 0, 100); // LDR divider: more light -> lower LDR resistance -> higher voltage on A2 (LDR to 5V, 10k to GND) int lightRaw = analogRead(LDR_PIN); float lightPct = lightRaw * 100.0 / 1023.0; Serial.print(tempC, 1); Serial.print(','); Serial.print(soilRaw); Serial.print(','); Serial.print(soilPct, 0); Serial.print(','); Serial.print(lightRaw); Serial.print(','); Serial.println(lightPct, 0); if (soilPct < 30) Serial.println(F("# soil is dry -> irrigation recommended")); delay(2000); }