Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2016 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d7afa50cd0547949670bce5c258ba94f to your computer and use it in GitHub Desktop.
Save anonymous/d7afa50cd0547949670bce5c258ba94f to your computer and use it in GitHub Desktop.
// snap-read
//
// this is an example of "snap-read" by coltivino maker.
// coltivino@gmail.com
//
// Connections on Arduino:
//
// digital pin 2: connect a relay as normally open (it will be ON when LOW is set).
// The relay may control a depurator or water pump.
//
// analog pin A0: connect the signal of the sensor.
//
// digital pin 12: connect the "+" of the sensor.
//
// GND: connect the GND from the sensor.
//
// The relay "+" and "-" must be connected as necessary, depending on its circuit.
int rel_osm = 2;
int sens_lev_wat = A0;
int lev_wat;
int val_lev_wat;
void setup() {
Serial.begin (9600);
pinMode (12, OUTPUT);
pinMode (rel_osm, OUTPUT);
pinMode (sens_lev_wat, INPUT);
}
void loop(){
digitalWrite(12, HIGH);
lev_wat = analogRead(sens_lev_wat);
val_lev_wat = map(lev_wat, 0, 1023, 0, 100);
if (val_lev_wat < 10)
{
digitalWrite(rel_osm, LOW);
digitalWrite(12, LOW);
}
else
{
digitalWrite(rel_osm,HIGH);
digitalWrite(12, LOW);
}
delay (10000);
Serial.print("Livello dell'acqua: ");
Serial.print(val_lev_wat);
Serial.println(" cm.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment