LCD ERROR FIX, With LDR and Laser 10k Resister

Hi Arduino Legends :wink:

Having issue getting my Ardunio code to be able to respond to my 12x6 LCD. Basically i have 5 Lasers connected to an external 3volt Battery and 5LDRs that are connected to 5 10k resisters but also soldiered on are 5 cables running to analog inputs [A1-A5].

I have attached the schematics/diagram from fritzing to the post along with the code which i have so far in the text.
If any one can give me any help would be appreciated.

Thank you
..............

#include <LiquidCrystal.h>

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int photoRPin = 1;
int minLight;
int maxLight;
int lightLevel;
int adjustedLightLevel;
int oldLightLevel;

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Smoking Kills");
Serial.begin(9600);

//Setup the starting light level limits
lightLevel=analogRead(photoRPin);
minLight=lightLevel-10;
maxLight=lightLevel;
oldLightLevel=lightLevel;

int threshold=50;
lcd.setCursor(0, 0);
if (analogRead(A1)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A2)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A3)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A4)<threshold) lcd.print('0'); else lcd.print('1');
if (analogRead(A5)<threshold) lcd.print('0'); else lcd.print('1');
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

lightLevel=analogRead(photoRPin);
delay(10);

//auto-adjust the minimum and maximum limits in real time
if(minLight>lightLevel){
minLight=lightLevel;
}
if(maxLight<lightLevel){
maxLight=lightLevel;
}

//Map the light level to produce a result between 1 and 28.
adjustedLightLevel = map(lightLevel, (minLight+20), (maxLight-20), 1, 28);
adjustedLightLevel = constrain (adjustedLightLevel, 1,28);

/Only send a new value to the Serial Port if the
adjustedLightLevel value changes.
/
if(oldLightLevel==adjustedLightLevel){
//do nothing if the old value and the new value are the same.
}else{
//Update the oldLightLevel value for the next round
oldLightLevel=adjustedLightLevel;

/Send the adjusted Light level result
to Serial port (processing)
/
Serial.println(adjustedLightLevel);
}
}

TEST_LDR_NM.ino (2.09 KB)

Having issue getting my Ardunio code to be able to respond to my 12x6 LCD.

There seem to be a few things reversed here. I assume that you mean your 16x2 display is not responding to your Arduino code.

I have attached the schematics/diagram from fritzing ...

This shows us how you were attempting to connect things. We need a photo of what you actually did.

If any one can give me any help would be appreciated.

Perhaps you can tell us what you are expecting to see and what you actually do see.

Don

what i expecting to see in the LCD is when you remove the content i.e bar tube from the LDR and the laser, it should respond with a message on the LCD. i would like to know if there is code available to this.

Atm i have my name displayed on the LCD with the codes for "Liquid Crystal". That's what i got so far.

Diagram in text -

[Battery Powers Laser] - Content in between - [LDR] - Connected to an Analog input [i.e A1]. When content is removed, should be shown on LCD. (Like text format saying, A1 Content removed).

So what I think you may be saying is that:

  • your system is essentially working
  • you can display the system status on the serial monitor
  • the LCD is functioning since you can display your name and the milliseconds information
  • you want to display the system status on the LCD
    Basically you send information to the LCD the same way you send information to the serial monitor. You use lcd.print() for the LCD and serial.print() for the serial monitor.

There are however some differences in terms of cursor positioning since lcd.println() won't do what you expect and since the device does not wrap from one line to the next the way you might expect either. You must instead use an lcd.setCursor() command to position the cursor where you want to start and make sure your message fits on the line.

Also you must erase any old information that you don't overwrite. In other words if you replace a long word such as ABCDEFGH with a shorter one such as 12345 the result will be 12345FGH. A simple solution is to make all of your messages the same length. In this case you would pad the 12345 message with three 'spaces' to cover up the FGH.

Don