Nicolo_Brizio
Published © GPL3+

Servo Motor and Water Sensor

How to realize a servo and water sensor function using simple raw materials.

EasyFull instructions provided531
Servo Motor and Water Sensor

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Grove - Water Sensor
Seeed Grove - Water Sensor
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Buzzer
Buzzer
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

case

wiring

Code

code

Arduino
#include <Servo.h>

Servo myservo;  
int potpin = A1;  
int val;
const int waterSens = A0; //define water sensor to pin A0
const int buzzer = 8; //define speaker to pin 8
int SensorValue; //create sensor data variable

void setup() 
{
  pinMode(buzzer, OUTPUT);//set speaker as an output
  pinMode(waterSens, INPUT); //set water sensor as an input   
  myservo.attach(9);          
}

void loop() 
{
  
  int sensorValue = analogRead(waterSens);//read the water sensor value

if (sensorValue <= 250) 
{     
    tone(buzzer, 660 ,100);  
delay ( 150);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 510 ,100);  
delay ( 100);  
tone(buzzer, 660 ,100);  
delay ( 300);  
tone(buzzer, 770 ,100);  
delay ( 550);  
tone(buzzer, 380 ,100);  
delay ( 575);  
  
tone(buzzer, 510 ,100);  
delay ( 450);  
tone(buzzer, 380 ,100);  
delay ( 400);  
tone(buzzer, 320 ,100);  
delay ( 500);  
tone(buzzer, 440 ,100);  
delay ( 300);  
tone(buzzer, 480 ,80);  
delay ( 330);  
tone(buzzer, 450 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 200);  
tone(buzzer, 660 ,80);  
delay ( 200);  
tone(buzzer, 760 ,50);  
delay ( 150);  
tone(buzzer, 860 ,100);  
delay ( 300);  
tone(buzzer, 700 ,80);  
delay ( 150);  
tone(buzzer, 760 ,50);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 300);  
tone(buzzer, 520 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 150);  
tone(buzzer, 480 ,80);  
delay ( 500);  
  
tone(buzzer, 510 ,100);  
delay ( 450);  
tone(buzzer, 380 ,100);  
delay ( 400);  
tone(buzzer, 320 ,100);  
delay ( 500);  
tone(buzzer, 440 ,100);  
delay ( 300);  
tone(buzzer, 480 ,80);  
delay ( 330);  
tone(buzzer, 450 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 200);  
tone(buzzer, 660 ,80);  
delay ( 200);  
tone(buzzer, 760 ,50);  
delay ( 150);  
tone(buzzer, 860 ,100);  
delay ( 300);  
tone(buzzer, 700 ,80);  
delay ( 150);  
tone(buzzer, 760 ,50);  
delay ( 350);  
tone(buzzer, 660 ,80);  
delay ( 300);  
tone(buzzer, 520 ,80);  
delay ( 150);  
tone(buzzer, 580 ,80);  
delay ( 150);  
tone(buzzer, 480 ,80);  
delay ( 500);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 220);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,200);  
delay ( 300);  
  
tone(buzzer, 1020 ,80);  
delay ( 300);  
tone(buzzer, 1020 ,80);  
delay ( 150);  
tone(buzzer, 1020 ,80);  
delay ( 300);  
  
tone(buzzer, 380 ,100);  
delay ( 300);  
tone(buzzer, 500 ,100);  
delay ( 300);  
  
tone(buzzer, 760 ,100);  
delay ( 100);  
tone(buzzer, 720 ,100);  
delay ( 150);  
tone(buzzer, 680 ,100);  
delay ( 150);  
tone(buzzer, 620 ,150);  
delay ( 300);  
  
tone(buzzer, 650 ,150);  
delay ( 300);  
tone(buzzer, 380 ,100);  
delay ( 150);  
tone(buzzer, 430 ,100);  
delay ( 150);  
  
tone(buzzer, 500 ,100);  
delay ( 300);  
tone(buzzer, 430 ,100);  
delay ( 150);  
tone(buzzer, 500 ,100);  
delay ( 100);  
tone(buzzer, 570 ,100);  
delay ( 420);  
  
tone(buzzer, 585 ,100);  
delay ( 450);  
  
tone(buzzer, 550 ,100);  
delay ( 420);  
  
tone(buzzer, 500 ,100);  
delay ( 360);  


 } //if the sensor senses water then play an alarm
 {
  val = analogRead(potpin);            
  val = map(val, 0, 1023, 0, 360);     
  myservo.write(val);                  
  delay(15);                         
}

}

Credits

Nicolo_Brizio

Nicolo_Brizio

1 project • 0 followers

Comments

Add projectSign up / Login