Optical Bubble Sensor BE-A 401 (Panasonic)

Hello!

Does anyone have experience with the Optical Bubble Sensor BE-A 401 (Panasonic)? I am trying too use it for an Arduino project but I am confused.

After reading the datasheet I thought that output1 and output2 should be on/off (high/low) type but when I Serial.print them it looks like they are 62 and 67.

Is this normal?

Hi,
Can you please post a link to data/specs of the BE-A 401?
Can you please post a copy of your code?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

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

Hi @morarumaria
To add code please click this link;

The reason for two outputs from the unit will be so it can be used with different manufacturers and models of equipment.
You only need to use one of them.

The output is digital HIGH or LOW, if you have the NPN output model, you must turn on the internal pull up resistors in the Arduino.

What model Arduino are you using?

So only input on one of the outputs.

You can use an analog pin as a digital input.
If you just use A0 then.

pinMode(outPin1, INPUT_PULLUP);   // this sets A0 up as a digital input with pullup resistor connected.

Then you just;

int out1 = digitalRead(outPin1);

That should then give you 1 or 0 as your output.

Tom... :smiley: :+1: :coffee: :australia:

Here is the coded again. I hope I did it right this time :sweat_smile:

//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(500);

if (button == HIGH){                  //if the button is pushed 
  if(out1 == HIGH &&( out2 == LOW)){  //IF BUBBLES ARE DETECTED (from the datasheet)
    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
    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, 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);
}
}

I am using an Arduino Uno Rev3.
Does this line of code turn on the internal pull up resistors?
pinMode(outPin1, INPUT_PULLUP); // this sets A0 up as a digital input with pullup resistor connected.

Thank you!
Maria

Hi,

Yes and turns the pin into a digital input;

Tom... :smiley: :+1: :coffee: :australia:

Thank you very much, @TomGeorge! I will change the code and give it another go.

Maria

I just tried the new code and it seems like it's working :partying_face: :smiling_face_with_three_hearts: