Hi, Tom!
I am so sorry for my late response, I thought the post didn't go through as I am a new member and I did not think to check again. I will not make that mistake again!
Here is the data sheet of the BE-A 401 sensor.
And here is a copy of my code:
//Library definition
#include <Wire.h> // Used for LCD
#include <LiquidCrystal_I2C.h> //Used for LCD
int buttonPin = 2; //the button is connected to pin 2
int greenLEDpin = 3; //the green LED is connected to pin 3
int redLEDpin = 4; //the red LED is connected to pin 4
int yellowLEDpin = 5; //the yellow LED is connected to pin 5
int outPin1 = A0; //output1 of bubble sensor;
int outPin2 = A1; //output2 of bubble sensor;
int button = 0; //variable for the value of the button
int buzzer = 9; //buzzer to arduino pin 9
LiquidCrystal_I2C lcd (0x27, 16, 2); //declaring the lcd
void setup() {
lcd.begin (); //opening the lcd
lcd.backlight(); //start backlight on the lcd
pinMode (buttonPin,INPUT ); //declare button pin as input
pinMode (redLEDpin,OUTPUT); //declare red LED pin as output
pinMode (greenLEDpin,OUTPUT); //declare green LED pin as output
pinMode (yellowLEDpin, OUTPUT); //declare yellow LED pin as output
pinMode (buzzer, OUTPUT); //declare buzzer pin as output
Serial.begin (9600);
}
void loop() {
button = digitalRead(buttonPin); //read value of the button
int out1 = analogRead(outPin1); //read value of output1 of bubble sensor
int out2 = analogRead(outPin2); //read value of output2 of bubble sensor
delay (500); //delay needed between collecting the values and using them
Serial.print ("\n output 1:");
Serial.print(out1);
Serial.print("\n output 2:");
Serial.print (out2);
delay(5000);
if (button == HIGH){ //if the button is pushed
if(out1 == HIGH &&( out2 == LOW)){ //IF BUBBLES ARE DETECTED (from the datasheet)
tone(buzzer, 1250); //piezo capsule sends 1.2 KHz sound signal
delay(500); //sound is on for 0.5 sec
noTone(buzzer); //sound stops
delay(50); //sound is off for 0.25 sec
digitalWrite (greenLEDpin, LOW); //green LED is off
digitalWrite (redLEDpin, HIGH); //red LED is on
digitalWrite (yellowLEDpin, LOW); //yellow pin is off
lcd.clear (); //make sure there is nothing on the lcd
lcd.print("Bubbles have"); //print from (0,0)
lcd.setCursor (0,1); //move the cursor to (0,1)
lcd.print("been detected."); //print the rest of the text
delay (500);
}
else{ //IF BUBBLES ARE NOT DETECTED
digitalWrite (greenLEDpin, HIGH); //green LED is on
digitalWrite (redLEDpin, LOW); //red LED is off
digitalWrite (yellowLEDpin, LOW); //yellow LED is off
lcd.clear (); //make sure there is nothing on the lcd
lcd.print("NO bubbles have"); //print from (0,0)
lcd.setCursor (0,1); //move cursor to (0,1)
lcd.print("been detected."); //print the rest of the text
delay (500);}
}
else{ //if the button is not pushed (waiting for measurement)
digitalWrite (greenLEDpin, LOW); //green LED is off
digitalWrite (redLEDpin, LOW); //red LED is off
digitalWrite (yellowLEDpin, HIGH); //yellow LED id on
lcd.clear (); //make sure there is nothing on the lcd
lcd.print(" Waiting"); //print from (0,0)
delay (500);
}
}
Thank you!
Maria