Aokiji_Master
Forum Veteran
wiring diagram of rain sensor vcc gnd do ao to arduinio uno
Sure! Here's an example code that uses both a sound sensor and a rain sensor to control a servo motor:additonal rain sensor to this code
#include <Servo.h>
const int soundPin = A0; // sound sensor pin
const int rainPin = A1; // rain sensor pin
const int servoPin = 9; // servo motor pin
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(servoPin);
}
void loop() {
int soundValue = analogRead(soundPin); // read sound sensor value
int rainValue = analogRead(rainPin); // read rain sensor value
Serial.print("Sound: ");
Serial.print(soundValue);
Serial.print(" | Rain: ");
Serial.println(rainValue);
// if sound is detected and it's not raining, move the servo
if (soundValue > 500 && rainValue > 500) {
myServo.write(90); // move servo to 90 degrees
delay(1000); // wait for 1 second
}
// if no sound is detected or it's raining, stop the servo
else {
myServo.write(0); // move servo to 0 degree
delay(100); // wait for 0.1 second
}
}
soundPin
variable is used to set the analog pin that the sound sensor is connected to. The rainPin
variable is used to set the analog pin that the rain sensor is connected to. The servoPin
variable is used to set the digital pin that the servo motor is connected to.setup()
function, the serial monitor is started and the servo motor is attached to the servoPin
.loop()
function, both the sound sensor value and rain sensor value are read using the analogRead()
function and stored in the soundValue
and rainValue
variables. If the soundValue
is greater than 500 and the rainValue
is greater than 500, which means sound is detected and it's not raining, the servo motor is moved to 90 degrees using the write()
function. If no sound is detected or it's raining, the servo motor is stopped by moving it to 0 degree. The delay()
function is used to wait for a short time before checking the sensor values again.tapos na paps heheAno gusto mo maachieve ts? Sa rainsensor pwede mo gamitin yung code ng button since magbibigay lang naman sya ng value from 0 to 1
Ayy late hahahha goodluck ts.tapos na paps hehe
maalam kapa ba paps sa pag program?Ayy late hahahha goodluck ts.
Konti lang sir pero try natin.maalam kapa ba paps sa pag program?
meesage kita sirKonti lang sir pero try natin.