Arduino_Genuino
Published

Displaying messages sent from IoT-Cloud on an LCD

This project will show you how to set up an Arduino IoT cloud dashboard to send messages to a Liquid Crystal Display (LCD).

IntermediateFull instructions provided1 hour6,568
Displaying messages sent from IoT-Cloud on an LCD

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
Or another IoT cloud comatible board
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Story

Read more

Code

IoTLCD

Arduino
Upload this sketch from the IoT Cloud
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/d5666fa2-1687-4538-a1d7-90f746998d23
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String lcdText;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <LiquidCrystal.h> //Import the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define contra 9 //Define the pin that controls the contrast of the screen
#define bri 10 //Define the pin the controls the brightness of the screen
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
lcd.begin(16, 2); //Tell the LCD that it is a 16x2 LCD
pinMode(contra, OUTPUT); //set pin 9 to OUTPUT
pinMode(bri, OUTPUT); //Set pin 10 to OUTPUT
//pinMode-ing OUTPUT makes the specified pin output power
digitalWrite(contra, LOW); /*outputs no power to the contrast pin.
this lets you see the words*/
analogWrite(bri, 255); //Outputs full power to the screen brightness LED
lcd.print("Send text!");
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since LcdText is READ_WRITE variable, onLcdTextChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLcdTextChange()  {
// Add your code here to act upon LcdText change
String firstLine;
String secondLine;
if(lcdText.length()< 15){
firstLine = lcdText;
} else if (lcdText.length() < 29){
firstLine = lcdText.substring(0, 15);
secondLine = lcdText.substring(15, 29);
} else{
firstLine = "Message too long";
}
Serial.println(lcdText);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(firstLine);
lcd.setCursor(0,1);
lcd.print(secondLine);
}

Credits

Arduino_Genuino

Arduino_Genuino

91 projects • 11340 followers

Comments