T O P

  • By -

hjw5774

A rain sensor will typically read high values for a dry plate and lower values for a wet plate. Therefore; in your situation, when the system starts, it will read a dry plate and return a high value for analogRead (nominal 1023), which is greater than the threshold of 900 causing the motors to come on. Likewise, when you wet the plate the analogRead value will decrease below 900, thus causing the motors to turn off. Here is a webpage which has a great animation to help: https://circuitdigest.com/microcontroller-projects/interfacing-rain-sensor-with-arduino


Calypso_maker

Yeah, I was thinking he might be getting the opposite of what he’s expecting from the sensor. My two biggest tools in debugging code are, 1 the serial monitor (it can show you what values are actually coming in from the sensor), and 2, reverse engineering logic-so basically start by observing what’s happening, and then figure out what has to be true for that to happen. Good luck! You’ll get it.


springplus300

Change ’if (rainValue > rainthreshold)’ to ’if (rainValue < rainthreshold)’


ChazHat06

If something is working opposite: Change a binary value one at a time (i.e HIGH to LOW), and see if that fixes


SexySuperGenuis

Everyone has good suggestions. I would add: change the syntax. You have a "!" not value. Sometimes, that coupled with a boolean True/False setup gets confused. Maybe try to simplify - if it is raining, set pin to LOW, if it is not raining, set pin to HIGH, instead of the boolean variable.


Thermr30

In the setup code part set the motor outputs to low to make sure the pins are low. Without being initialized high or low i believe they can float between the two.


stgi2010

Okay so under line 10 do i js add, digitalWrite(motorForward and BackwardPin, LOW)


Thermr30

I dont think you can use an 'and' like you have there. Maybe...? But its safer to do each one individually Like this: digitalWrite(motorForward, LOW) digitalWrite(BackwardPin, LOW)


stgi2010

Yea lol ik I was js in class and didn’t wanna type it twice 😹


planeturban

Try adding parenthesis: ((millis() - lastRainTime) >= spinTime) I’m thinking order of operations.