From 2ea4a033e37877ef7001cf8c242d579799692385 Mon Sep 17 00:00:00 2001 From: Charlotte Vandenbulcke <ch.vandenbulcke@gmail.com> Date: Wed, 17 Apr 2024 10:08:58 +0200 Subject: [PATCH] adding missing code for water sensor on week11 page --- public/assignments/week11.html | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/public/assignments/week11.html b/public/assignments/week11.html index e5796f8..867442a 100644 --- a/public/assignments/week11.html +++ b/public/assignments/week11.html @@ -234,7 +234,36 @@ <pre> <code> - + /* + * Created by ArduinoGetStarted.com + * + * This example code is in the public domain + * + * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-water-sensor + */ + + #define POWER_PIN 14 + #define SIGNAL_PIN A0 + + int value = 0; // variable to store the sensor value + + void setup() { + Serial.begin(9600); + pinMode(POWER_PIN, OUTPUT); // configure D7 pin as an OUTPUT + digitalWrite(POWER_PIN, LOW); // turn the sensor OFF + } + + void loop() { + digitalWrite(POWER_PIN, HIGH); // turn the sensor ON + delay(10); // wait 10 milliseconds + value = analogRead(SIGNAL_PIN); // read the analog value from sensor + digitalWrite(POWER_PIN, LOW); // turn the sensor OFF + + Serial.print("Sensor value: "); + Serial.println(value); + + delay(1000); + } </code> </pre> -- GitLab