The water pump's ability to pump water has significantly decreased, which led to the decision to purchase new water pumps to attach to both sides of the sprinkler mechanism. This will make both sides of the house have equal water flow. In addition, in order to make our project "presentable" (not leak every time we activate the sprinkler), we decided to re-design the baseplate on top to a floating island design.
The original code failed for some reason. The wiring was correct. There was something about the code. I tried to get only the photoresistor working yet still failed.
we updated the code and switch the sensor
#include <Servo.h> // Include the Servo library
// Define the pin connected to the photoresistor
const int photoPin = A0; // Photoresistor (Adafruit 161) connected to analog pin A0
// Define the pin for the servo motor
const int servoPin = 9; // Servo motor connected to pin 9
// Define the threshold value to detect light
int lightThreshold = 900; // Example threshold
// Define the threshold to detect if the sensor is disconnected
const int disconnectedThreshold = 5; // Adjust if necessary
// Create a Servo object
Servo myServo;
// Variable to track light detection state
bool isLightDetected = false; // Track if light level is currently above threshold
void setup() {
// Start serial communication
Serial.begin(9600);
while (!Serial) {
; // Wait for the serial port to connect (necessary for native USB port boards)
}
// Attach the servo to pin 9
myServo.attach(servoPin);
// Initialize the servo to its resting position (0 degrees)
myServo.write(0); // Start at 0 degrees
// Print a startup message
Serial.println("Photoresistor (Adafruit 161) with Servo Example Initialized");
}
void loop() {
// Read the analog value from the photoresistor (range 0 to 1023)
int sensorValue = analogRead(photoPin);
// Print the sensor value to the serial monitor
Serial.print("Photoresistor Value: ");
Serial.println(sensorValue);
// Check if the sensor is disconnected
if (sensorValue < disconnectedThreshold) {
Serial.println("Warning: Sensor Disconnected! Moving Servo to Safe Position (70°).");
myServo.write(70); // Move to a neutral position to avoid false readings
return; // Skip further processing to prevent incorrect behavior
}
// Check if the sensor value exceeds the threshold (light detected)
if (sensorValue > lightThreshold) {
if (!isLightDetected) {
// Light newly detected, move the servo to 0 degrees
Serial.println("Light Detected");
myServo.write(0); // Move servo to 0 degrees
isLightDetected = true; // Mark that light is detected
}
} else {
// Light is below threshold
if (isLightDetected) {
Serial.println("Light Below Threshold");
myServo.write(70); // Move servo to 70 degrees
isLightDetected = false; // Reset the detection state
}
}
// Longer delay to observe changes more clearly (1 second)
delay(1000);
}
Today, we created a new version of the house that better mimics the bark of the Giant Sequoia tree (and its ability to collect water). In addition, we created a sketch for our biomimicry slide.
int moisture = 0;
void setup() {
// Initialize the moisture sensor power pin (use pin 2 for power)
pinMode(2, OUTPUT); // Pin to power the moisture sensor
pinMode(A1, INPUT); // Pin to read the moisture sensor value (A1)
// Initialize the LED pins
pinMode(8, OUTPUT); // LED 1
pinMode(9, OUTPUT); // LED 2
pinMode(10, OUTPUT); // LED 3
pinMode(11, OUTPUT); // LED 4
pinMode(12, OUTPUT); // LED 5
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Apply power to the soil moisture sensor (pin 2)
digitalWrite(2, HIGH);
delay(10); // Wait for 10 milliseconds for the sensor to stabilize
// Read the moisture sensor value (from A1)
moisture = analogRead(A1);
digitalWrite(2, LOW); // Turn off the sensor to avoid corrosion
// Print the moisture level to the serial monitor
Serial.println(moisture);
// Turn off all LEDs initially
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
// Determine which LED to turn on based on moisture level
if (moisture < 200) {
digitalWrite(12, HIGH); // Very dry soil (LED 5)
} else if (moisture < 400) {
digitalWrite(11, HIGH); // Dry soil (LED 4)
} else if (moisture < 600) {
digitalWrite(10, HIGH); // Moist soil (LED 3)
} else if (moisture < 800) {
digitalWrite(9, HIGH); // Wet soil (LED 2)
} else {
digitalWrite(8, HIGH); // Very wet soil (LED 1)
}
// Wait for 100 milliseconds before taking another reading
delay(100);
}