Tell us about yourself!
Ooops!! You are so right! We have an error in our example, it should read: (A) instead of if(soilMoisture.read() > 400) use if(soilMoisture.read() < 600). (B) also: Serial.println("High moisture detected"); should be changed to: Serial.println("Low moisture detected"); We're sorryyy! and will fix the guide accordingly. Thanks for letting us know.
The transistor amplifies the signal coming out of the Arduino, to get louder sounds from the speaker.The diode is a "fly-back" diode, meant to protect the circuit from reverse currents, but in most cases this diode will not be necessary with piezo speakers, but more important with regular (coil) speakers.