Skip to content

Commit b347dd0

Browse files
committed
rain sensor added
1 parent ef241a5 commit b347dd0

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

Diff for: Rain Detection Sensor with Arduino/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Sensor pins pin D6 LED output, pin A0 analog Input
2+
#define ledPin 6
3+
#define sensorPin A0
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
pinMode(ledPin, OUTPUT);
8+
digitalWrite(ledPin, LOW);
9+
}
10+
11+
void loop() {
12+
Serial.print("Analog output: ");
13+
Serial.println(readSensor());
14+
delay(500);
15+
}
16+
17+
// This function returns the analog data to calling function
18+
int readSensor() {
19+
int sensorValue = analogRead(sensorPin); // Read the analog value from sensor
20+
int outputValue = map(sensorValue, 0, 1023, 255, 0); // map the 10-bit data to 8-bit data
21+
analogWrite(ledPin, outputValue); // generate PWM signal
22+
return outputValue; // Return analog rain value
23+
}
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)