Re: Help on coding please

Hi
Having trouble figuring this out, any one could help me. :fearful: :disappointed_relieved:
Its a project for college and i am trying to get the LDR’s and the Laser to respond when moving an tube item away from the LDR and the reading (responses) to be show on the LCD.

This is my code below and the Diagram which i have created. (attached) PNG

#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);
 } 
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

What's the problem?

Looking at your schematic absolutely NOTHING is paying any attention to your LDRs. They simply conduct more or less current.

They are paying attention, they have been soldiered together to connect them.

I need help from someone to show me the code of how moving the object from the laser and ldr would display on the lcd from each of the A1 - A5.

OK So what did one LDR say to the other. Sounds like a joke to me :)

MI320: I need help from someone to show me the code of how moving the object from the laser and ldr would display on the lcd from each of the A1 - A5.

Produce a proper schematic with a pencil and paper rather than a fancy pseudo photo. Then post a photo of the pencil drawing. Don't worry if the drawing is crude, as long as it is clear.

...R

Your mapping function looks dicey.

As a starting point, just print out the values you get from the LDRs every say 100ms. This will let you know if you’ve got the electronics and the interface correct, before complicating it with maths.

MI320: They are paying attention, they have been soldiered together to connect them.

Not in the schematic you've shown in the original post. In that schematic, all the LDRs are connected to ground and to 5V but none of them are connected to any pin on the Arduino that could read them.

The LDR's which pin do they need to be connected to on the Arduino?