Hello! I am using a CQrobot Liquid Level Sensor SKU: CQRSENYW002
With this water level sensor I am trying to get a DC motor to turn on when it detects no water and then turn off when it does detect water. I have already gotten the water level sensor to detect water levels on its own, and I have been able to turn the DC motor on with code, but getting them to work together has been tricky. I only first got into Arduino a month ago with my class, so I'm not very knowledgeable. With this setup my water level sensor is always reading as 0 even when in water. (In the image imagine the sensor there as the water level sensor) Some kind help would be very appreciated!
int speedPin = 5;
int inputPin = 7;
int mSpeed = 255;
int sensorVal;
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(speedPin, OUTPUT);
sensorVal=digitalRead(inputPin);
}
void loop() {
Serial.println(sensorVal);
if (sensorVal==LOW);
{digitalWrite(speedPin, mSpeed); //motor will run when water level sensor does not detect water
}
if(sensorVal==HIGH); {
digitalWrite(speedPin, LOW);
} }
Not a good idea to run motor from Arduino 5V pin. What is the value of your base resistor? Should be 270 ~ 470. Does the sensor work if the motor is not connected?
int speedPin = 5;
int inputPin = 7;``
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(speedPin, OUTPUT);
}
void loop() {
digitalWrite(speedPin, digitalRead(inputPin)); //motor will run when water level
}
Hi,
A picture of your project, a circuit and final code will help make this thread cpmplete.
Not a fritzy like in post #1, a hand drawn circuit with component labels and pin names would be helpful.
Most 9V batteries have very limited current ability, less than most small motors.
Motors tend to pull lots of currents, from 100mA up with no load, and stall current peaks measured in amps. Beginners often underestimate how much current and power motors need to do things - typical 9V batteries usually struggle and overheat trying to power a motor and their voltage may drop to a few volts as a result.