0% found this document useful (0 votes)
22 views

Arduino - Water Level Sensor

The document defines code to read water level from a sensor using analog input pins and a power pin, storing the reading in a variable and printing it to serial output every second.

Uploaded by

Sharran Baktha
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Arduino - Water Level Sensor

The document defines code to read water level from a sensor using analog input pins and a power pin, storing the reading in a variable and printing it to serial output every second.

Uploaded by

Sharran Baktha
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Sensor pins

#define sensorPower 7
#define sensorPin A0

// Value for storing water level


int val = 0;

void setup() {
// Set D7 as an OUTPUT
pinMode(sensorPower, OUTPUT);

// Set to LOW so no power flows through the sensor


digitalWrite(sensorPower, LOW);

Serial.begin(9600);
}

void loop() {
//get the reading from the function below and print it
int level = readSensor();

Serial.print("Water level: ");


Serial.println(level);

delay(1000);
}

//This is a function used to get the reading


int readSensor() {
digitalWrite(sensorPower, HIGH); // Turn the sensor ON
delay(10); // wait 10 milliseconds
val = analogRead(sensorPin); // Read the analog value form sensor
digitalWrite(sensorPower, LOW); // Turn the sensor OFF
return val; // send current reading
}

You might also like