25mccabec
Published

LCD Sensor Displayer

Senses when a breakbeam sensor is broken and displays on an LCD display.

IntermediateFull instructions provided569
LCD Sensor Displayer

Things used in this project

Hardware components

Adafruit Break Beam Sensors
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
IC2 LCD Attachment
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Either one of them.
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Create Online

Story

Read more

Schematics

Wire locations & components

The wire locations and the resistor location.

Code

LCD I2C code

Arduino
This is a code for whenever you break the laser, it displays text. If you want to edit the text, you can go to line 39 & 47 for the broken, & unbroken text that it displays. You can also change the delay it refreshes the text so it doesn't spazz out.
 
// BBeam Sensor Code

#include <OneWire.h> // LCD Wire
#include <LiquidCrystal_I2C.h> // LCD

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display


#define LEDPIN 13

#define SENSORPIN 4

// variables will change:
int sensorState = 0, lastState=0; 4r   // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(LEDPIN, OUTPUT);      
  // initialize the sensor pin as an input:
  pinMode(SENSORPIN, INPUT);     
  digitalWrite(SENSORPIN, HIGH); // turn on the pullup
  
  Serial.begin(9600);
  lcd.init(); 
  lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH
  lcd.begin(16, 2);
}

void loop(){
  // read the state of the pushbutton value:
  sensorState = digitalRead(SENSORPIN);

  // check if the sensor beam is broken
  // if it is, the sensorState is LOW:
  if (sensorState == LOW) {     
    // BB sensor is broken:
    lcd.setCursor(0,0);
    lcd.print("broken text here");
    delay(1000); // delay of how much it loops
  } 
  else {
    // if the sensor beam isn't broken it will be on HIGH:
    // BB sensor isn't broken
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("text here");
    delay(1000); // delay of how much it loops
  }
  
  if (sensorState && !lastState) {
    Serial.println("Unbroken");
  }                                 // the state of the sensors
  if (!sensorState && lastState) {
    Serial.println("Broken"); 
  }
  lastState = sensorState;
}e;
}

Credits

25mccabec

25mccabec

0 projects • 0 followers

Comments