当前位置:网站首页>Arduino+ water level sensor +led display + buzzer alarm

Arduino+ water level sensor +led display + buzzer alarm

2022-07-06 13:19:00 Lunan wind

Experiment preparation :

        arduino mega2560(uno、Nano And other models )

        led( yellow 、 green 、 red )

         resistance x3( This time I choose 680Ω resistance 1/4w Metal film resistance , avoid led When the lamp is burnt out, pay attention to the resistance value is not too small )

         Buzzer ( Here I use active high-level trigger )

         Water level sensor ( as follows )

water sensor

  Wiring ( The latter can be wired according to the provider )

Experimental procedure

#define water_sensorspin A1
#define led_yellow 2     
#define led_green 3
#define led_red 4
#define buzzpin 7
float ad_value=0;   // Depth analog value  
float deepcm=0;     // Actual depth 


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led_yellow,OUTPUT);    // Set pin status 
  pinMode(led_green,OUTPUT);
  pinMode(led_red,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  ad_value=analogRead(water_sensorspin);         //A1 The pin gets the analog value and assigns the variable 
  Serial.println("Water level monitoring ready");
  delay(20);
  Serial.println(ad_value);               // Print and observe the change of analog value 
  deepcm=(ad_value/702)*4;                // Measured , At the deepest point, the analog value is about 702, Measure the depth 4cm
  Serial.print(" At this time, the depth of water is :");
  Serial.print(deepcm);
  Serial.println("cm");
  if(deepcm<1.5)          // The water level is lower than 1.5cm when 
  {
   delay(20);
   digitalWrite(led_yellow,HIGH);
   digitalWrite(led_green,LOW);
   digitalWrite(led_red,LOW);
   digitalWrite(buzzpin,LOW);
   }
   else if(deepcm<3)
   {
   delay(20);
   digitalWrite(led_yellow,LOW);
   digitalWrite(led_green,HIGH);
   digitalWrite(led_red,LOW);
   digitalWrite(buzzpin,LOW);
    }
    else if(deepcm>3)
    {
   delay(20);
   digitalWrite(led_yellow,LOW);
   digitalWrite(led_green,LOW);
   digitalWrite(led_red,HIGH);
   digitalWrite(buzzpin,HIGH);
   Serial.println(" The water level is too high , Be careful !");
     }
   delay(2000);        // The delay jam is slightly longer , The serial port refresh is too fast to see 
   
}

Experimental phenomena

  The water level sensor is inserted into the water ( Note that the maximum depth should not exceed 4cm)

  When the depth is shallow

 

 

Moderate depth

  When the depth is deep

video

The water level led Show

Buzzer alarm

Basics :led Lighten up , Buzzer alarm

Add other displays to the sensor access

原网站

版权声明
本文为[Lunan wind]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060916074854.html