Agree with Forest Morgan that you are not obligated to talk to law enforcement other than identify self. Also, not sure why the officer entered upon your property. Fortunately sounds as though no arrest.
You always have the right to walk away or ask the officer to leave unless/until you are subject to an investigative detention/arrest. However, this line is not clearly drawn and, in most cases, the ambiguity favors the law enforcement officer. In addition, unless this is a nightly occurrance or you are charged/arrested for something, there is really no remedy.
As a general rule, if you are approached by law enforcement and you do not wish to continue the conversation, you should orally inform the officer clearly and unequivocally that you do not wish to engage in further conversation. You may even inquire if the officer is either investigating an incident. If not, then you may feel free to return inside of your home.
During a consensual encounter, the officer may ask for your identification and pat you down for their safety.
It is NEVER in your best interest to argue or physically resist the officer, nor would be wise to attempt to leave if the officer informs you that you are subject to an investigation or arrest. If you are arrested illegally, a good defense attorney can assist you.
From the facts set forth, this is what is termed a "mere encounter" between police officer and citizen. While it requires no particular justification for its initiation by the officer, it permissibly lasts only so long as the citizen permits its continuation. While your presence on your own property at the time makes the additional investigative steps more intrusive, the "mere encounter" scenario could occur anywhere. Providing a police officer with basic biographical information (name, address, and identification) is always a wise response to avoid escalation of an encounter, NO other information or cooperation is required and should be withheld unless you are CERTAIN that there is no risk involved in providing more. You are not required to consent to a search of your person, vehicle, or house; and your are not required to answer questions about ANYTHING if you so choose. In your specific situation it would have been perfectly appropriate for you to have politely declined any further interaction and ask that he/she leave. Since you do not reveal that anything of significance came of this encounter, I can't comment further. If criminal charges resulted from the incident, you should obtain the services of a qualified criminal defense attorney without delay.
Sounds like the copy is suspicious of someone sitting in the front yard at midnight, probably in an area of known drug activity or past break-ins. You should actually be pleased the cops are checking to see that someone sitting in your front yard at that time has permission and is not a "lookout" for some hoodlum doing something illegal inside. If you were armed, there would be even more cause for concern. You have a choice in these situations, tell the copy to get lost unless he has a warrant and make him mad and likely watch you more closely in the future or cooperate and demonstrate you have nothing to hide. Most people choose to cooperate and are pleased the cop is watching their property. If you are a woman and the cop is male, then the pat down request is totally out of line unless there is more to this [and there always is, it seems] and you should report him to his supervisor.
I am not your lawyer and you are not my client. Free advice here is without recourse and any reliance thereupon is at your sole risk. This is done without compensation as a free public service. I am licensed in IL, MO, TX and I am a Reg. Pat. Atty. so advice in any other jurisdiction is strictly general advice and should be confirmed with an attorney licensed in that jurisdiction.
While I agree with the answers given (you are free to walk away; you may be required to identify yourself in certain circumstances), I think it is perfectly permissible to identify yourself as the homeowner, and then require the officer to remove himself from your premises.
This answer is not a substitute for consulting with and retaining the services of an attorney for your legal needs. By providing this answer, I am not entering into an attorney client relationship with you.