Characters Special

I can’t get my custom character to work. What can I do to fix this?
this is my code…

#include <LiquidCrystal.h>

byte warning[8] =

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int button_pin = 6;
int trigger_pin = 7;
int echo_pin = 9;
int buzzer_pin = 10;
int time;
int distance;

void setup () {
 lcd.begin(16, 2);
 lcd.createChar(warning, 8);
 pinMode(button_pin, INPUT_PULLUP);
 pinMode(trigger_pin, OUTPUT);
 pinMode(echo_pin, INPUT);
 pinMode(buzzer_pin, OUTPUT);
 lcd.print("  ...ARMING...");

void loop () {
 digitalWrite(trigger_pin, HIGH);
 digitalWrite(trigger_pin, LOW);
 time = pulseIn(echo_pin, HIGH);
 distance = (time * 0.034) / 2;
 if (distance >= 10) {
   lcd.print("NICHOLAS IT IS");
   lcd.print("TIME TO WAKE UP!");
   do {
     digitalWrite(buzzer_pin, HIGH);
   } while (digitalRead(button_pin) == HIGH);
   } else {
 if (digitalRead(button_pin) == LOW) {
   digitalWrite(buzzer_pin, LOW);
   lcd.print("  !!!WARNING!!!");
   lcd.print("   !!!ARMED!!!");

You have provided no information that lets us help you. Does not work is a worthless description of a problem. What does the code actually do? How is that different from what you want it to do?



Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

The parameters to this method
lcd.createChar(warning, 8);are wrong.
Here is the Arduino reference page

Another thing to keep in mind is that there is a "feature" (I call it a bug) in the createChar() code in the LIquidCrystal library.
The issue is that the code puts the LCD into CGRAM mode to send the custom character bytes to the LCD but then leaves it in CGRAM mode. It does not put the LCD back into DDRAM mode before returning.
This means that any further attempts to write characters to the display will write the data to the CGRAM an not to the display, which is essentially corrupting the CGRAM with garbage custom characters.

You have two options

  • work around it by doing a clear() or setCursor() after calling createChar()
  • use the hd44780 library and hd44780_pinIO class which does not have this issue.

--- bill