Introduction: Desktop Organisor With LCD

**Being Edited**

For the HKU arduino project I decided to make a desktop organisor featuring LCD screen that displays inspiration quotes to pick you up when you rotate your potmeter!

I'll be covering the arduino technical stuff mostly, as long you got something like a wooden box to hide your Arduino and LCD in your personal oganisor could take on any desirable form.

The things you'll need

  • *arduino uno
  • pot meter
  • *male prottyping wires
  • *LCD module !With SD card reader! (I got arduino tft LCD)
  • *micro SD card
  • *wood (I recycled old mini drawers and used some spare wooden parts, make sure you can at least form a little box to hide your arduino in!

Step 1: Setting Up the Potmeter on Arduino

connect your pot meter as shown in the picture

to get the pot meter to work start

You'll need to start of with some variables on the top of your sketch before the setup:

code:

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to

int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out)

In picture 2 I show how the potmeter is mapped in the void loop

code:

// read the analog in value:

sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); String stuffToPrint = String(outputValue); // change the analog out value:

stuffToPrint.toCharArray(printout,9); // static text myScreen.setTextSize(1);

Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue);

delay(50);

this maps the analog data from the potmeter to a range of 0 to 255, we'll use this range to control our lcd slideshow

If you need help setting up the potmeter; I used the code from this helpful tutorial, the pins are the exact same and will work with the LCD setup in the next steps.

http://www.toptechboy.com/arduino/lesson-11-arduin...

Step 2: Setting Up the LCD

Set up the pins like in the example above.

When done correctly your screen will light up white.

If you need extra help or want to use some example code to test your display you can see the official tutorial for this module and it's code examples here https://www.arduino.cc/en/Guide/TFT

we will be partially using the "drawing image from SD card" in the next step.

Step 3: Setting Up the Slideshow

Now that we have the Potmeter and LCD set up we can set up a "slideshow" using the potmeter's mapped values

Using the range of 0 to 255 we can indicate a certain range in which we can trigger the arduino to display some content on the LCD.

First example as shown in image:

if (outputValue < 51){ //range one
if (rangeOne == true){ rangeTwo = true; myScreen.setRotation(90); myScreen.background(0,0,0); myScreen.stroke(255,255,255); myScreen.text("Hi there wonderful,",10,50); myScreen.text("rotate the pin > to",10,60); myScreen.text("get encouragement.",10,70); rangeOne = false;

If the potmeter turns to a range lower than 51, the screen with display (in portrait mode = rotatio 90) some text.

To be able to display an image make sure your SD CS pin is defined correctly, or the arduino will fail to initialize the SD (so make sure to check your wires!!)

If you want to check your LCD's pins you can refer to the official guide uner "connecting the screen" https://www.arduino.cc/en/Guide/TFT

I defined my SD CS pin as 4 now because I mixed up my wires, for example! - I'm happy to share that little oopsie because it will save you a lot of time searching the web for the "Failed to initialize" error. To which on some forums it's said the fix is to have a certain model of SD card. So check your wiring first before buying new SD cards!!

Step 4: Full Code Example

#include

#include // Hardware-specific library #include

#define SD_CS 4 #define CS 10 #define DC 9 #define RESET 8

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to

int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) bool rangeOne = true; bool rangeTwo = true; bool rangeThree = true; bool rangeFour = true; bool rangeFive = true;

TFT myScreen = TFT(CS, DC, RESET);

PImage image; const char printout[9];

void setup(){ Serial.begin(9600); myScreen.begin(); // try to access the SD card Serial.print("Initializing SD card..."); if (!SD.begin(SD_CS)) { Serial.println("failed!"); return; } Serial.println("OK!");

// initialize and clear the GLCD screen myScreen.begin(); myScreen.background(255, 255, 255);

} void loop(){ // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); String stuffToPrint = String(outputValue); // change the analog out value:

stuffToPrint.toCharArray(printout,9); // static text myScreen.setTextSize(1);

Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue);

delay(50);

if (outputValue < 51){ //range one if (rangeOne == true){ rangeTwo = true; myScreen.setRotation(90); myScreen.background(0,0,0); myScreen.stroke(255,255,255); myScreen.text("Hi there wonderful,",10,50); myScreen.text("rotate the pin > to",10,60); myScreen.text("get encouragement.",10,70); rangeOne = false; } } if(outputValue > 52 && outputValue < 101){ //range two if (rangeTwo == true){ rangeOne = true; rangeThree = true; myScreen.setRotation(90); myScreen.background(255,255,255); // clear the screen image = myScreen.loadImage("quote1.bmp"); //write the image on screen myScreen.image(image, 0, 0); myScreen.stroke(255,255,255); myScreen.text("You are",12,50); myScreen.text("much stronger",10,60); myScreen.text("than you think.",9,70); rangeTwo = false; } // check if the image loaded properly if (image.isValid() != true) { Serial.println("error while loading arduino.bmp"); } } if(outputValue > 102 && outputValue < 153){ //range Three if (rangeThree == true){ rangeTwo = true; rangeFour = true; myScreen.setRotation(90); myScreen.background(0,0,0); myScreen.stroke(255,255,255); myScreen.text("Are you enjoying",10,50); myScreen.text("your day",10,60); myScreen.text("so far?",10,70); rangeThree = false; } } if(outputValue > 154 && outputValue < 205){ //range four if (rangeFour == true){ rangeThree = true; rangeFive = true; myScreen.setRotation(90); myScreen.background(255,255,255); // clear the screen image = myScreen.loadImage("quote2.bmp"); //write the image on screen myScreen.image(image, 0, 0); myScreen.stroke(255,255,255); myScreen.text("I'm so proud",10,50); myScreen.text("of you!",10,60); rangeFour = false; } }

if(outputValue > 206 && outputValue < 255){ //range five if (rangeFive == true){ rangeFour = true; myScreen.setRotation(90); myScreen.background(0,0,0); myScreen.stroke(255,255,255); myScreen.text("Do you like",10,50); myScreen.text("where you put",10,60); myScreen.text("your pencils?",10,70); rangeFive = false; } } }