I code for a hobby so I dont know a lot but I am trying to get a servo motor to move 90-100 when a raindrop sensor gets wet. No matter what I put for an angle the thing moves to the same spot or doesnt move at all.
Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
Hola,
- Connect correctly to your arduino, (Vcc to pin 5v of arduino, gnd to gnd arduino and D0 to pin 5 of the arduino), a rain sensor similar to this: LINK
- Properly connect, (Vcc to pin 5v of arduino, gnd to gnd arduino and signal to pin 9 of the arduino), a servo similar to this one. LINK
- Load the servo library into the arduino IDE.
- Compile and run the following sketch:
#include <Servo.h>
const int rain_sensor = 5;
const int servo = 9;
Servo myservo;
void setup() {
myservo.attach(servo);
pinMode(rain_sensor, INPUT);
}
void loop() {
if (digitalRead (rain_sensor) == HIGH){myservo.write(100);}
else {myservo.write(90);}
}
Greetings
Sorry for the late reply. Been a busy week. Ill be on more often, I really didnt expect that quick of replies. Thanks guys. I'm on my phone so hopefully this works, I took a pic of the wiring. I will describe it along with list the parts and models below.
I'm using the following:
mg996r servo motor
Raindrop sensor
D1 mini board
ESP8266 ESP-01
So i am using the d1 mini but thought of treting the esp-01 if even possible. Maybe it would save money and not be hard to design my own board and combine the raindrop board and wifi board with no more connections then needed. Maybe only if I buy 100? Just an idea.
So I have the servo power and ground to the 5v pwr and gnd and the orange wire goes to d8. The orange wire Folsom the 3v3 goes to the vc on the raindrop board along with the ground to ground. I have DO from that board going to A0 on the D1 mini. I found the advice online and it worked for me. Maybe its because my coding is messed up? Do i need the DO to a D pin or maybe take the AO from the raindrop sensor to the A0 on the d1?
Lastly the raindrop sensor is connected to its board but unsure if it matters which goes to which since theres no logo on the sensor but I have the ground plugged into the side with the "FC-37" lettering. The power and ground from the board is wired to a USB and wall plug at 5v 2amp
I'll try other suggestions here soon
Not able to see the complete wiring.
Servos require their own external power supply.
The GND of this supply needs to connect to the GND ton the controller.
.
The power supply was going to be 2 amps and 5v. Would this not power both? Ive seen robots with many servos and one big plug in the back. How do achieve that?
Posting more pics but I also described it because thats probably going to be the easiest way from my phone here. If you have any questions on the description lmk but I tried explaining it as simple as possible
I should also add, the reason I'm doing this with a wifi board is because eventually I need to hook it up so assistant services can command it through voice. I had all this coded nearly a year ago but cant find the code and have to start from scratch. Just wish I had a strong memory.
.
Yes, that supply will be good for both.
Are the pics better or do you have any question on the description? Any help would be appreciated, thanks!
Personally, I always start with a schematic.
Next simple code is written to prove connections to all the I/O.
Individually at first, then as a combined sketch.
Then commit to a final schematic.
Then write the final (12 versions ) of software.
Pictures (good images) always helps us to give the best help.
myservo.attach(15);
Your servo looks like it is connected to D8 not D15.
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
Sorey that must have been an older code. Its in d8 and coded that way. I do need a time delay for mosture sensing. Few seconds for prototyping but will be 30-240 minutes. If the power supply is sufficient
I am not familiar with that Arduino board, if the output pins are 0 to 3.3v logic levels, this might not be enough for the servo input to work properly.
If you have an UNO, try your code on it to see if you have better success with the servo.
Does the raindrop sensor look right? Thats my main concern since there is lack of markings and ive found conflicting info. It would just make sense to go from analog to analog or digital to digital. And if they criss cross then which way should I have it crossed. Maybe this doesnt matter?
Also, do you code the sensors sensitivity or do you adjust it via the screw on the board throat connects the sensor and main board?
My understanding of the sensor board is there are two outputs.
One is D0 and the second is A0
The D0 should give a HIGH or LOW signal to the Arduino.
The potentiometer on the PCB is used to set the point where the switching takes place when moisture is applied to the detector.
This adjustment might be non repeatable, i.e. a trigger setting doesn’t necessarily mean a certain level has been reached; just responds the fact moisture is present.
The A0 output is most likely not going to give any satisfactory results when connected to an analog input on the Arduino.
Im trying to make it so you can code the sensitivity. The potentiometer will be enclosed in the housing. Is there a way to do away with it and just run the sensor to the d1 mini and code the sensitivity or "the point it switches"(assuming that you mean from dry to wet and would mean the sensitivity)? If not what would be my best routing of the wires to sense rain but not need access to the potentiometer since it will be enclosed.
Or is my only option to leave the potentiometer exposed and only manual manipulate it? Even if i need another sensor setup, let me know my options. Thanks!
With inexpensive sensors like this the best you will get is wet vs dry, nothing in between.
In the past I’ve set the potentiometer on a PCB, then measured the resistance between the outer to middle terminals.
Removed the potentiometer and used fixed resistors to replace the pot.
Are the resistors you used basically like a static pot? So you put the resistor that corresponds with your desired "sensitivity"
Like this image of a boost converter pot replacement: