Program running on proteus ..but not in real life

I'm doing a project on dual axis solar tracker

The components I'm using are -

Arduino Uno 4 LDR 2 servo motor Resistor

The stimulation is working fine in proteus for the circuit connections and program...but when I did with real components it was unable to track.

I did the project from this site..

Please reply...Looking forward for replies.

Thank you.

Post. Your. Code.

Use code tags.

Post. Your. Schematic.

edit: I'm curious - why didn't you ask the question over at Destructables?

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

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

int servohLimitHigh = 180;
int servohLimitLow = 65;

// 65 degrees MAX
Servo vertical; // vertical servo
int servov = 45; // 90; // stand vertical servo

int servovLimitHigh = 80;
int servovLimitLow = 15;

// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left - BOTTOM LEFT <— BDG
int ldrrt = 1; //LDR top rigt - BOTTOM RIGHT
int ldrld = 2; //LDR down left - TOP LEFT
int ldrrd = 3; //ldr down rigt - TOP RIGHT

void setup()
// servo connections
// name.attacht(pin);

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 dtime = 10;
int tol = 50;

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

Serial.print(" “);
Serial.print(” “);
Serial.print(” “);
Serial.print(” “);
Serial.print(” “);
Serial.println(” ");

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 > servovLimitHigh)
servov = servovLimitHigh;
else if (avt < avd)
servov= --servov;
if (servov < servovLimitLow)
servov = servovLimitLow;

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 < servohLimitLow)
servoh = servohLimitLow;
else if (avl < avr)
servoh = ++servoh;
if (servoh > servohLimitHigh)
servoh = servohLimitHigh;
else if (avl = avr)
// nothing


 else if (avl = avr)


    servov = ++servov;or     servov++; as normal people spell it.

.but when I did with real components it was unable to track.

Around here, that's almost as bad as saying "it doesn't work". Or writing code without debug prints. Or not sharing the debug print output. Or not using code tags when asked to.

So the problem is with the code..??.

So how it was tracking in proteus..??

Naafi_1: So the problem is with the code..??.

So how it was tracking in proteus..??

How the Hell do I know?

I don't use "proteus", I don't have your hardware sitting in front of me, and I can't see what your sketch is printing.

I have attached the schematic. This is how i have connected my circuit.Both in proteus and in real life.
But i gave not attached the battery in real life.have given 5V suppy and ground from arduino itself.

Rest of the connection are same.

Hope is helps somewhat.

Are you saying you're powering two servos from the Arduino's 5V output? Two real servos, with DC motors in them?

Ya…two real servo…not with metal gear…ones with plastic.

It moves a certain distance…don’t know how much angle…but I guess till…the limit it is set in the program…and then it kind of get jammed and moves back and forth in the same position…

If you visit the ccs compiler (PIC processor) forums, you will notice that one of the top "stickys" is about no more Proteus questions. There are too many cases of Proteus being junk and not correctly emulating the actual hardware - things like missing power, ground, clock etc. are simply ignored giving exactly what you are experiencing "gee it works in Proteus, but not on real hardware". The problem is learning to troubleshoot real hardware. Put in print statements to show intermediate values etc. Double check the power and grounds - verify the processor is even running (put a print statement at the start to tell the name and version number of your sketch etc. so you know it is even alive).

Ya..I also heard proteus is not exactly correctly ...and ya saw pic forum.

Just amateur in this field first project don't know from where I should start searching for errors.

Ok..let me try with the print statement...


A couple of things I typically do for troubleshooting and testing - have a display you can write to if possible (even if it is a remote serial connection to your laptop etc.). Have a pin/bit/LED that you can talk to - use it to blink different information at different places in your code. May not be very fast, but it allows you to see where it is running. I have a bit I like to use at the start of an interrupt routine for example - turn it on on entry and off when done. Quick look with a scope will tell you how often it is going off, how much time is being spent in the ISR etc. Having a bit or two that you can view as a test point is very handy and takes very little extra code.


Good suggestion bro..

Looks like you are good at Arduino programming...

Let me try these things..

Or just connect a terminal emulator (or the serial monitor) and use the print statements you've already got.