// ============================================ // Barduino Motor Control via Phototransistor // Motor ON when dark, Motor OFF when light // ============================================ // --- Pin Definitions --- const int MOTOR_PIN = 1; // GPIO01 -> IRF520 signal pin const int PHOTOTRANSISTOR = 3; // GPIO03 -> Built-in phototransistor on Barduino // --- Threshold --- // Analog value range is 0 to 4095. // A higher reading = more light detected. // Adjust this value based on your environment. // Open the Serial Monitor at 115200 baud to see live readings! const int LIGHT_THRESHOLD = 150; void setup() { pinMode(MOTOR_PIN, OUTPUT); // Set motor pin as output digitalWrite(MOTOR_PIN, LOW); // Make sure motor starts OFF Serial.begin(115200); // Start Serial Monitor for debugging Serial.println("Barduino Motor + Phototransistor Ready!"); } void loop() { // Read the phototransistor (0 = dark, 4095 = very bright) int lightLevel = analogRead(PHOTOTRANSISTOR); // Print the reading to Serial Monitor so you can find the right threshold Serial.print("Light level: "); Serial.println(lightLevel); // Control the motor based on light level if (lightLevel > LIGHT_THRESHOLD) { // It's LIGHT -> turn motor OFF digitalWrite(MOTOR_PIN, LOW); Serial.println("Light detected -> Motor OFF"); } else { // It's DARK -> turn motor ON analogWriteFrequency(MOTOR_PIN, 20); analogWrite(MOTOR_PIN, 25); Serial.println("Dark detected -> Motor ON"); } delay(100); // Small pause to avoid flooding the Serial Monitor }