4 LDR -2 servo and 18b20 and LCD

dear friends

i am working on a project … but i couldnt i need little help :frowning:

there ll be

4 LDR resistor
one 18B20
2 servos
one LCD

LCD connected one 2-7 digital pins of arduino
LDRs connected A0-A3
Servos connected 9 and 10th pwm pins
18B20 connected 12.pin

i want to make one sun burner with the help of magnifying glass … it should track the sun + and it should send the temprature to the LCD screen and computer …

PLEASE can you check this code … i couldnt get success …

 #include <Servo.h> // include Servo library 

Servo horizontal; // horizontal servo
int servoh = 90;     // stand horizontal servo

Servo vertical;   // vertical servo 
int servov = 90;     // stand vertical servo

// LDR pin connections
//  name  = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top rigt
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down rigt
#include <OneWire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

OneWire  ds(12);  // on pin 12
void setup() {
  
 lcd.begin(16, 2);
// servo connections
// name.attacht(pin);
  horizontal.attach(9,1000,2000); 
  vertical.attach(10,1000,2000);
}

void loop() {
 int lt = analogRead(ldrlt); // top left
  int rt = analogRead(ldrrt); // top right
  int ld = analogRead(ldrld); // down left
  int rd = analogRead(ldrrd); // down rigt
  
  int dtime = analogRead(4)/20; // read potentiometers  
  int tol = analogRead(5)/4;
  
  int avt = (lt + rt) / 2; // average value top
  int avd = (ld + rd) / 2; // average value down
  int avl = (lt + ld) / 2; // average value left
  int avr = (rt + rd) / 2; // average value right

  int dvert = avt - avd; // check the diffirence of up and down
  int dhoriz = avl - avr;// check the diffirence og left and rigt
    
  if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance else change vertical angle
  {
  if (avt > avd)
  {
    servov = ++servov;
     if (servov > 180) 
     { 
      servov = 180;
     }
  }
  else if (avt < avd)
  {
    servov= --servov;
    if (servov < 0)
  {
    servov = 0;
  }
  }
  vertical.write(servov);
  }
  
  if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
  {
  if (avl > avr)
  {
    servoh = --servoh;
    if (servoh < 0)
    {
    servoh = 0;
    }
  }
  else if (avl < avr)
  {
    servoh = ++servoh;
     if (servoh > 180)
     {
     servoh = 180;
     }
  }
  else if (avl = avr)
  {
    // nothing
  }
  horizontal.write(servoh);
  }
   delay(dtime); 
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  if ( !ds.search(addr)) {
   ds.reset_search();
    delay(2500);
    return;
  }
  
  
  for( i = 0; i < 8; i++) {
  
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
  
      return;
  }
  
  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
  
      type_s = 1;
      break;
    case 0x28:
  
      type_s = 0;
      break;
    case 0x22:
 
      type_s = 0;
      break;
    default:
     return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad


  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();

  }

  // convert the data to actual temperature

  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
 lcd.clear();
 lcd.print("SICAKLIK: ");
 lcd.print(celsius);
 lcd.setCursor(0, 1);
 lcd.print("    DERECE      ");
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");
}

Please edit your post and add ... tags around the actual code. Select the code and click the '#' button. That will stop it turning to italics part way through.

Technically this:

else if (avl = avr)

should be

else if (avl == avr)

But you really don't need it at all, you can leave it out as you did in the vertical case.

Some more detail about what it does and how that isn't what you want would help. Use of Serial.print to examine your variables as the sketch executes might help you figure out what's going on too.

i tried this but it didnt work :frowning:

when i use servo and ldr alone it is working .perfect

when i use lcd +servo+ldr s it is also working perfect .. but whenener i use DS18b20 s codes ... it shows temperature but servos are vibrating :frowning:

it is not working ...

it is not working ...

Bullsh*t. It is doing exactly what you told it to do.

If that isn't what you want it to do, you need to tell us what it actually does and how that differs from what you want it to do.

but servos are vibrating

How are the servos powered? How long does it take to get a reading from the DS18s20? Are you interfering with the Servo library's ability to send another signal to the servos?

servos power is from 6 volt liquid battery (powerfull )diffrent then arduinos power .. and in 750ms we can give data ..

as u told i think problem is about library of servo or DS18b20(something interfering ) . but how can i solve it ?

Consider using the DallasTemperature library to read the temperature rather than rolling your own (not that they're likely very different).

as u told i think problem is about library of servo or DS18b20(something interfering ) . but how can i solve it ?

Start by learning to spell. This is a forum, not a text message exchange service.