Experiment using the LCD screen

// Include the library for controlling an LCD
#include <LiquidCrystal.h>
// Initialize the LCD connected to specified pins.
LiquidCrystal lcd(11, 12, 2, 3, 4, 5);
// Define custom characters using byte arrays. Each byte represents a row of pixels.
byte smile[8] ={0b00000,0b00000,0b01010,0b00000,0b00000,0b10001,0b01110,0b00000};
byte armsDown[8] ={0b00100,0b01010,0b00100,0b00100,0b01110,0b10101,0b00100,0b01010};
byte armsUp[8] ={0b00100,0b01010,0b00100,0b10101,0b01110,0b00100,0b00100,0b01010};
byte cat[8] ={0b00000,0b00000,0b00000,0b10000,0b10011,0b11111,0b01110,0b01010};
byte girl[8] ={0b00100,0b01010,0b00100,0b11111,0b00100,0b00100,0b01110,0b11111};
byte heart[8] ={0b00000,0b00000,0b00000,0b11011,0b11111,0b11111,0b01110,0b00100};
void setup() {
// Set up the LCD's number of columns and rows.
lcd.begin(16, 2);
// Register the custom characters in the LCD memory.
lcd.createChar(1, smile);
lcd.createChar(3, armsDown);
lcd.createChar(4, armsUp);
lcd.createChar(5, cat);
lcd.createChar(6, girl);
lcd.createChar(7, heart);
}
void loop() {
// Set the initial position of characters
lcd.setCursor(2, 0); // Move cursor to column 2 of the first row.
// Display the 'cat' character
lcd.write(5);
// girl
lcd.write(6);
// Move cursor to the end of the first row.
lcd.setCursor(13, 0);
// Display the "boy" (armsDown).
lcd.write(3);
delay(400);
//the 'smile' across the screen
// Move cursor back near the start.
lcd.setCursor(4, 0);
for (int place = 0; place < 9; place++) {
// Display "smile"
lcd.write(1);
delay(400);
}
//to 'arms up' character and animate a 'heart' back across the screen
// Move cursor to the end of the first row
lcd.setCursor(13, 0);
lcd.write(4); // Display 'arms up'
for (int place = 12; place >= 4; place--) {
// Move the cursor left each loop iteration
lcd.setCursor(place, 0);
lcd.write(7); // heart
delay(400);
}
delay(400); //// Final pause after the loop completes
}


- Setup: Initializes the LCD screen, loads custom-designed characters (smile, arms down/up, cat, girl, heart) into the LCD’s
- Loop:
- Displays the ‘cat’ and ‘girl’ characters side by side at the beginning of the loop.
- Shows the “boy” character at the far right of the first line, using the “armsDown” custom character.
- Animates the “smile” character across nearly the entire first row, showcasing each position.
- Switches to the “arms up” character and then animates the “heart” moving back across the screen to the left.
Date-Time(RTClib.h)


// Include Wire library and RTC library
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup ()
{
Serial.begin(9600);
// Initiate the Wire library
Wire.begin();
// Initialize the interaction
rtc.begin();
// Check if the RTC is running, and if not,
// set it up with the current date and time.
if (! rtc.isrunning()) {
// Print an error message if the RTC is not running.
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
// the current date and time from the RTC
DateTime now = rtc.now();
char dt[10]; // a character array to hold the date string
char tm[10]; // a character array to hold the time string
// Format the date as DD/MM/YY and store it in 'dt'
sprintf(dt, "%02d/%02d/%02d",
now.year(),now.month(),now.day());
// Format the time as HH:MM:SS and store it in 'tm'.
sprintf(tm, "%02d:%02d:%02d",
now.hour(),now.minute(),now.second());
Serial.print(dt);
Serial.print(" ");
Serial.print(tm);
Serial.println();
delay(1000);
}

- Libraries and Initialization:
Wire.h
andRTClib.h
- An
RTC_DS1307
object is created
- Setup Function:
- Serial communication is started to allow data output to the serial monitor.
- The I2C bus is initiated, and communication with the RTC module begins.
- It checks if the RTC is running. If it isn’t, the RTC is set to the compile time of the sketch, ensuring the clock starts with a correct time setting.
- Loop Function:
- The current date and time are retrieved from the RTC.
- Two character arrays are prepared to format and store the date and time as strings.
- The date (
dt
) is formatted as “DD/MM/YY” and the time (tm
) as “HH:MM:SS”. - These formatted strings are printed to the serial monitor. This happens every second, providing a continuous readout of the current date and time.
Interactive information screen “Weather Station”

#include <LiquidCrystal.h>
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 rtc;
LiquidCrystal lcd(11, 12, 2, 3, 4, 5);
byte BoltDrive[8] = {
0b00000, 0b01110, 0b10001,
0b11111, 0b10101, 0b01110,
0b00000, 0b00000 };
byte BoltFood[8] = {
0b00110, 0b00100, 0b11111,
0b10001, 0b11111, 0b11111,
0b11111, 0b11111 };
byte BoltTaxi[8] = {
0b11100, 0b01010, 0b01101,
0b01111, 0b00101, 0b10110,
0b01010, 0b10110 };
byte BoltWheels[8] = {
0b00110, 0b01001, 0b01001,
0b00110, 0b01100, 0b10010,
0b10010, 0b01100 };
byte weatherIcon[8] = {
0b00011, 0b00110, 0b01100,
0b11111, 0b11111, 0b00011,
0b00110, 0b01100 };
char* advertisementMessages[] = {
"Bolt Food ", "Bolt Drive ",
"Bolt Taxi ", "Bolt 2-Wheels "
};
int tempPin = A0;
int adIndex = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
lcd.begin(16, 2); // 16 columns x 2 rows
lcd.createChar(0, BoltDrive);
lcd.createChar(1, BoltFood);
lcd.createChar(2, BoltTaxi);
lcd.createChar(3, BoltWheels);
lcd.createChar(4, weatherIcon);
if (!rtc.isrunning()) {
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop() {
DateTime now = rtc.now();
char firstRow[20];
sprintf(firstRow, "%02d/%02d/%02d %02d:%02d",
now.day(), now.month(), now.year() % 100,
now.hour(), now.minute());
lcd.setCursor(0, 0);
lcd.print(firstRow);
if (millis() / 5000 % 2 == 0) {
int tempValue = analogRead(tempPin);
float voltage = tempValue * (5.0 / 1023.0);
float temperature = (voltage - 0.5) * 100.0;
char message[20];
if (temperature < 0) {
strcpy(message, "Very Cold ");
} else if (temperature < 10) {
strcpy(message, "Cold ");
} else if (temperature < 20) {
strcpy(message, "Mild ");
} else if (temperature < 30) {
strcpy(message, "Warm ");
} else if (temperature < 35) {
strcpy(message, "Hot ");
} else {
strcpy(message, "Very Hot ");
}
lcd.setCursor(0, 1);
lcd.print(message);
lcd.setCursor(14, 1);
lcd.write(byte(4)); // weather icon
} else {
lcd.setCursor(0, 1);
lcd.print(advertisementMessages[adIndex % 4]);
lcd.setCursor(14, 1);
lcd.write(byte(adIndex % 4)); // advertisement icon
adIndex++;
}
delay(3000);
}


- Libraries and Initialization:
LiquidCrystal.h
,Wire.h
andRTClib.h
- An
RTC_DS1307
object is created- PINs:
LiquidCrystal lcd(11, 12, 2, 3, 4, 5)
-
tempPin
- Characters:
BoltDrive,
BoltFood,
BoltTaxi,
BoltWheels,
weatherIcon
- PINs:
AdvertisementMessages
for charactersadIndex
: advertisement index
- Setup function: is used to initialize variables, pin modes, start using libraries, and other setup needs.
rtc.begin()
: Initializes the Real-Time Clock module.lcd.begin(16, 2)
: Sets up the LCD’s number of columns and rows- Creating Custom Characters for LCD: these lines define custom characters (icons) that can be displayed on the LCD. Custom characters are stored in the LCD’s memory and are addressed by an index (the first parameter in
createChar
). The arrays likeBoltDrive
contain byte patterns that define the pixel arrangement for each custom character.lcd.createChar(0, BoltDrive);
lcd.createChar(1, BoltFood);
lcd.createChar(2, BoltTaxi);
lcd.createChar(3, BoltWheels);
lcd.createChar(4, weatherIcon);
- Check and Set RTC Time: block checks if the RTC module is currently running.
__DATE__
and__TIME__
: provide the current date and time at the moment of sketch compilation.
- Loop function:
- the Current Time:
DateTime now = rtc.now();
- Formatting the Time for Display: the date format is
DD/MM/YY
and the time format isHH:MM
. if (millis() / 5000 % 2 == 0):
This uses themillis()
function, which returns the number of milliseconds. This value is divided by 5000 (5 sec), and if the result is even, the code within the if statement is executed.- Reading and Displaying Temperature
- The Temperature Message: Based on the temperature value, a corresponding message is chosen
- Updating the LCD for Weather: updates the second row of the LCD with the temperature message and displays a weather icon.
- Displaying Advertisements: in the else block, an advertisement message and a corresponding icon are displayed,
adIndex
is used to cycle through different messages and icons, incrementing each cycle to rotate through the advertisements - Delay: a 3-second pause before the next iteration of the loop
- the Current Time:


