Internet of things (IoT)-based solar tracker [Automation problem]

I have this project that I am trying to recreate and the automation is not working,… in the arduino ide serial monitor shows manual mode even though it is in automation mode. here is the code.

void loop()
{
  topr= analogRead(A2);       
  topl= analogRead(A3);         
  botl= analogRead(A4);      
  botr= analogRead(A5);        
  Vout=(analogRead(A1) * 5.0) / 1023;
  analogVoltage = analogRead(voltageinputPIN); //reads analog voltage of incoming sensor
  Serial.println(" Manual-mode");
  Cayenne.loop();
  
  if
  (digitalRead(3)==HIGH){
    Serial.println(" Automatic-mode");
    servoh = servo_x.read();
    servov = servo_z.read();
    int avgtop = (topr + topl) / 2;     
    int avgbot = (botr + botl) / 2;   
    int avgright = (topr  + botr) / 2;   
    int avgleft = (topl + botl) / 2;    
    int diffhori=  avgtop - avgbot;      
    int diffverti= avgleft - avgright;    
    int offset =20;// set the correction offset value
    
    /*tracking according to horizontal axis*/ 
    if (abs(diffhori) <= threshold_value)
    {
     servo_x.write(servoh);            //stop the servo up-down
    }else {
       if (diffhori > threshold_value)
          { Serial.println(" x -  2 ");
          servo_x.write(servoh -2);    //Clockwise rotation CW
          if (servoh > servohLimitHigh)
          {
           servoh = servohLimitHigh;
          }
          delay(10);
          }else {
           servo_x.write(servoh +2);   //CCW
           if (servoh < servohLimitLow)
           {
           servoh = servohLimitLow;
           }
           delay(10);
           }
      }     
    /*tracking according to vertical axis*/ 
    if (abs(diffverti) <= threshold_value)
    {     
     servo_z.write(servov);       //stop the  servo left-right
    }else{
       if (diffverti > threshold_value)
       {
       servo_z.write(servov -2);  //CW
       if (servov > servovLimitHigh)
       { 
       servov = servovLimitHigh;
       }
       delay(10);
       }else{ 
        servo_z.write(servov +2);  //CCW
        if (servov < servovLimitLow) 
        {
        servov = servovLimitLow;
        }
        delay(10);
        }
     }
  }
}

this will always be printed as it is in the main loop.
you can check what actually is the state of pin 3 by printing in the serial monitor.

  Serial.println(" Manual-mode");
  Serial.println(digitalRead(3));
1 Like

How do i print it in the serial monitor?