There is a scene toward the end of Ian McEwan’s new novel, Machines Like Me, when the narrator, Charlie, is pushing his lifelike prototype robot, Adam, in a wheelchair through a demonstration in Trafalgar Square. The demonstrators are protesting about everything under the sun – “poverty, unemployment, housing, healthcare, education, crime, race, gender, climate, opportunity”. The suggestion being presented by McEwan and his narrator, however, is that here, unnoticed in their midst, is the one thing they should be most concerned about: a man-made intelligence greater than their own.

There is a Cassandra tendency in McEwan’s fiction. His domestic dramas routinely play out against a backdrop of threatened doom. Since the portent-laden meditation on war and terrorism, Saturday, in 2005, he has also turned his gimlet attention to climate change in Solar. The opening lines of that novel – “He was running out of time. Everyone was, it was the general condition…” – have sometimes sounded like his fiction’s statement of intent. The New Yorker called his work “the art of unease”.

It was perhaps, I suggested to him one afternoon a couple of weeks ago, therefore only a matter of time before he got around to the looming ethical anxieties of artificial intelligence.

McEwan smiled at this idea and explained that he had been enthralled by the possibility of man-made consciousness for just about as long as he could remember. He was sitting in a low armchair in the corner of the upstairs room of his compact mews house near London’s inns of court (his primary home is a 16th-century Cotswolds manor house). He is 70 years old, still limber and thin and prolific, and among the few English novelists who can make headlines with stray comments on the issues of the day. There was a time when he appeared to approach that “man of letters” role with a studied gravity; these days he seems to wear the mantle more lightly.

McEwan has twitchy antennae as a writer, scanning the news for patterns. In reflecting on the themes of his new novel he mentions the recent Boeing 737 crash in Ethiopia, in which the plane’s software apparently overrode the pilot’s best efforts to keep it airborne. This is a story, he forecasts, that will become an insistent narrative in all areas of our lives. “People are not quite aware yet that when they get in a plane they are flying in a giant brain,” he says. “That brain might believe the plane is stalling – though every last passenger and the pilot can look out of the window and see the plane is not stalling. We are in the process of handing over responsibility for safety, but also for ethical decisions, to machines.”

McEwan has an abiding faith that novels are the best place to examine such ethical dilemmas, though he has little time for conventional science fiction. “There could be an opening of a mental space for novelists to explore this future, not in terms of travelling at 10 times the speed of light in anti-gravity boots, but in actually looking at the human dilemmas of being close up to something that you know to be artificial but which thinks like you. If a machine seems like a human or you can’t tell the difference, then you’d jolly well better start thinking about whether it has responsibilities and rights and all the rest.”

Facebook Twitter Pinterest McEwan in 1976, when First Love, Last Rites was causing a literary stir. Photograph: Tony McGrath/The Observer

The time frame we have for conducting that thinking, McEwan says, can probably be measured in the years that it will take for us to design the batteries that allow such robots as Adam to become autonomous. “My novel is a total fantasy. I look on YouTube at the best robots. There’s a creepy looking bald guy and various poker-faced females, but what you can’t see is the cable snaking into the mains. None of it will happen until we crack the battery problem.”

Before we achieve that, he says, we need to confront the challenges of encoding what it means to be fully human. The drama of his novel, a somewhat predictable love triangle in which one of the trio has an on-off switch, hinges on the question of whether we can teach machines to lie. “Who’s going to write the algorithm for the little white lie that spares the blushes of a friend?” his novel asks at one point. “Or the lie that sends the rapist to prison who’d otherwise go free?”

The tale itself is the familiar McEwan mix of minutely observed psychologies and page-turning plot. The latter is “like a pair of ready-made trousers you slip into,” he says. Though his interest here is in the limits of technology, he is not shy of the oldest stories. “I thought,” he says, with sudden bluntness, “if Charlie has fallen in love with the girl upstairs and a robot comes along who they have chosen to be averagely well endowed, then we are going to be so disappointed if he doesn’t fuck her…”

In this sense, you might say, he is coming at the AI question from the opposite angle to Mary Shelley in Frankenstein. “There the monster is a metaphor for science out of control, but it is ourselves out of control that I am interested in.”

That latter interest is the thread that runs through all of McEwan’s fiction from those early, disturbing stories of incest and paedophilia and psychosis in First Love, Last Rites through the tragic deceptions of Atonement, which has now sold six million copies. The warring parties in McEwan’s imagination are rationality and its discontents. You feel just a little of that conflict about him in person. He is a generous and entirely measured talker, who gives a sense of having long overcome an inbuilt reserve. His work ethic – one that has produced 15 novels, half a dozen screenplays – is in tension with a commitment to a certain playfulness. Diary entries of his youth seem telling. He joined the hippy trail to Iran and Afghanistan in the early 1970s and even in 1976 he was recording how “we eat psilocybe mushrooms, canoe, swim naked in the electric-cold water, take saunas, play volleyball, drink wine and talk about Jimmy Carter and Ezra Pound.” Elsewhere, however, he recalled of such hedonism, that: “On the road I often dreamed of being back under undistracting grey skies, writing fiction. After six months I was desperate to get to work.”

Facebook Twitter Pinterest James McAvoy and Keira Knightley in the film version of Atonement. The book has sold six million copies.

The action of the current novel is set not in some virtual future, but in a reimagined fragment of that personal past. Charlie, a vague alter ego of the novelist and his robot companion, Adam, occupy a house in south London in the early 1980s, just as McEwan did, prior to his first marriage. The technological anomaly of Adam is explained in the novel by the fact that Alan Turing, the mastermind behind the breaking of the enigma code, had not taken his own life in 1954, but lived into his 70s to fulfil his dream to create the first human-like brain.

There were other contemporary parallels with that period that drew McEwan to it. He admits that he would not know quite where to start in writing a novel about our current polarised moment (“there are too many constituencies to consider”) but this book gave him a licence to examine a decade whose political dramas seem much like our own. Thus the book makes reference to the battle for the soul of the Labour party between the Trotskyite comrades of Tony Benn and the centrist followers of Denis Healey. It also imagines the fallout of a Falklands war that had been a humiliating defeat rather than a flag-waving victory.

“The great thing about having an altered reality is that you can’t get anything wrong,” McEwan says. “Though I have become a merchant of fake news, I’m afraid, for probably an entire American audience and almost anyone else under 40.”

The more McEwan reimagined that era, the more he felt that its history was being replayed as farce. “When the Falklands happened I was very much against the whole enterprise, and everyone I knew – with the exception of Christopher Hitchens – felt the same,” he recalls. “Yet every poll I read said 80 or 90% were in favour of the invasion. I realised what a bubble I lived in then as now. I have so few friends or acquaintances that are in favour of Brexit.”

McEwan embarked on his novel a couple of months after the European referendum. I wonder how much of the general atmosphere of malaise he felt had filtered into it?

He says that if it has, it is mostly subconscious. “Sometimes, I wake in the morning wondering what is bearing in on me, and then I remember,” he says. “Brexit does seem to me a national tragedy… the great lie of the Brexiters, their magic dust, was to persuade 37% of the electorate that the EU, not the UK, was in charge of immigration, and they succeeded.”

On the day we meet the news is full of familiar accusations of betrayal from the Tory right. The novelist in him wants to get inside and understand the mindset of the European Research Group, he suggests, but he hasn’t quite the heart. “I am never sure what these people love about England,” he says. “I only hear what they hate. You don’t hear them eulogising folk music or Gardeners’ Question Time or anything, do you? What do they love?”

Facebook Twitter Pinterest McEwan with fellow Booker prize shortlist finalists in 2007. Photograph: Alastair Grant/AP

As he explains this, I’m reminded of a couple of profiles of McEwan I have read that have described him as Britain’s “national novelist”. I’d never really thought of him in that way but it seems true to the extent that he has a sure feel for the deep roots of our neuroses. The unconsummated wedding night in On Chesil Beach for example, captured all that Larkinesque weirdness about sex that was never quite expelled from the middle classes by the promiscuous 1960s.

McEwan was in some ways born to that role of national psychologist. His father, Major David McEwan, was a hard-drinking spit-and-polish NCO, and he grew up in Aldershot and on various army bases in the dregs of empire. His earliest recollections, he has said, are of “weekday idylls with my mother interrupted at weekends by the loud appearance of my father, when our tiny prefabricated bungalow would fill with his cigarette smoke”. Their marriage, in which frustration became violence, began in unspoken tragedy.

McEwan’s mother had met David McEwan in 1941. Her first husband, Ernest Wort, was serving in the forces abroad and in 1942 she and David conceived a child who was put up for adoption in a small ad in the Reading Mercury that was a short story in itself: “Wanted, Home for Baby Boy, age 1 month; complete surrender.” Wort was killed in action in 1944, and McEwan’s parents subsequently married. His mother’s two children from her first marriage were unwanted by McEwan’s father. One was sent to live with his paternal grandmother, the other was enrolled at a boarding school for soldiers’ orphans. When McEwan was born, he was treated as an only child. He only discovered and met the brother who had been given up for adoption, Dave Sharp, a bricklayer, in 2002.

Does such a family history furnish a keener than average desire to make sense of the world? Certainly you could read McEwan’s work in that way. Does he see his parents’ relationship as the trigger of his fiction?

I think about my parents’ marriage a lot,” he says. “Discovering I had a brother I didn’t know about made me really re-examine and understand differently, especially my mother, the sadness that I think I knew hung over her, which now I begin to understand.”

Facebook Twitter Pinterest With David Sharp, the brother he only discovered he had in 2002. Photograph: Rex

Is he aware, looking back, of confronting that history subconsciously in different ways – the books, from The Child in Time onwards, are full of relationships on the rocks and missing children?

“No, I don’t think I have ever gone that near it really,” he says. “It is quite a painful thought. Just the way that a war rips up private lives, throws everything into a turmoil that is mostly unrecorded among people who don’t write things down.”

The war persisted in his childhood long after it ended; great events shadowed his home life in the way that history seeps through the cracks of his novels.

“In 1956, we were in Libya,” he says, by way of example. “My mother had gone home for some family reason and because of the Suez crisis all army families were considered vulnerable to attack by Arab nationalists, so we were herded into camps. Actually it was one of the most blissful 10 days of my life. School stopped. I would occasionally see my father, who was then a captain, with a revolver strapped to his side in the distance, and us kids just ran free among the machine-gun nests and the barbed wire. Very heaven it was.”

I wonder what his old man made of his writing?

“He was torn between pleasure that I seemed to have my face in the papers occasionally, and utter horror at the contents of the first book or two.”

In this McEwan shared a background with those friends, all born in the four years after the war, who later became the headline acts of literary London alongside him. Julian Barnes’s parents also never read his books (“too much below-stairs language”), while Kingsley Amis infamously never got beyond the first few pages of any of Martin’s novels. Christopher Hitchens called his father, a naval hero in the war, simply “the commander”.

In some ways the friendship that group developed in the 1970s and 80s seems to have provided the camaraderie they had missed in childhood. I wonder if he believes that they would have achieved all that they have as writers and public figures without each other’s support?

Facebook Twitter Pinterest With his old friend Martin Amis. Photograph: Bruce Adams/Daily Mail

“Oh yeah, I think so,” he says. “We sat around then as we do now, and if we talked about literature it was only to celebrate things we liked. Mostly we just had a lot of fun.” The other day he says, he was coming back from Clapham in an Uber. “It took exactly the same route I used to drive my crappy little car to go and see Martin in the 1970s when he was living off Queensway. My car had an open top and I remembered exactly how I used to love in summer to zoom down the tram tunnel at the far end of Waterloo bridge, with the wind in my hair – when I had a lot of hair.”

In a rare short story in the New Yorker a couple of years ago, My Purple-Scented Novel, McEwan told a fable of authorial jealousy; a failing writer steals the manuscript of a successful and brilliant friend and passes it off as his own, destroying the rival’s reputation in the process. Halfway through, he noted, archly, how the idea came from a story he had read about Martin Amis drinking one evening “with another novelist, the one (memory fails me) with the Scottish name and the English attitude. I heard that the two friends entertained themselves by dreaming up all the ways one writer might ruin the life of another.”

Though there was no doubt plenty of competitive energy in their real-life friendships, there was always enough success to go around to make envy just a parlour game. McEwan’s was perhaps the least flamboyant talent of that circle, but it has proved the most commercial and perhaps enduring; since the triumphs of Atonement, his novels have been turned seamlessly into films. Two opened in the last year – On Chesil Beach and The Children Act. He is currently working on adapting Sweet Tooth, his story of 1970s espionage, for Working Title.

Does he still go to his desk with the same excitement as when he was starting out?

“I’m a great believer in turning up still,” he says. “No forgiving yourself because you are tired. I try to get there before 10, not too early.” His office is “a nice big converted barn” if he is at the house he and his second wife, Annalena McAfee, share in Gloucestershire, or here at the kitchen table if he is in London. There are still those magical writing days, he says, when “you forget you exist and you surface an hour later and you have 400 words you were not expecting to write”. He has never learned how to summon those moments to order. “But turning up is certainly the first condition. Work until lunchtime, listen to World at One, have a sandwich. Walk the dog. We have a very active sheepdog.”

Long before Fitbits and 10,000-step regimes, McEwan was an evangelist for walking as the most useful creative habit, one that has taken him from the Chilterns and the Lake District to the Himalayas and the Dolomites. His eyes light up when he talks me through the 10-mile hike he has planned for the following day on the North Downs with his regular companion Ray Dolan, director of neuroimaging at the Wellcome Trust. They both see it as a way to discover healthy neural pathways.

“It is more or less the case that when I have done a big walk and it is really satisfying, something is cleared out of my mind,” he says. “Particularly if the walk has had just a little edge of danger. If Ray and I were doing day walks on mountain ridges, particularly when we were younger, almost deliberately we would stay up a little too long and have to come down mountain streams in the pitch dark, with head torches, because we had lost the path.”

Facebook Twitter Pinterest With his wife, Annalena McAfee, at a literary festival in Italy. Photograph: Rex

Entering his eighth decade he hasn’t lost his taste for that whiff of adventure, either in his walking or his writing.

“The fact is I was heartbroken when I turned 18,” he says, when I ask him how he feels about his age. “My mother said to me once when I was in my 20s: “You know I would give anything to be 45 again.” I obviously burst out laughing. Now I understand. I played a good game of squash when I was 45. I had my life all sorted out.”

From the outside, squash game aside, that remains the case. “What goes?” he asks himself. “The pleasures of conversation don’t fade. The degree to which I get depressed by the news doesn’t fade. Sometimes there are pleasurable events that I don’t look forward to as intensely as I used to, but when I get there, it’s a different story. I have always taken the idea of holidays very seriously and my two grown-up sons have that too, which I love. We often holiday together, something I never did with my parents.”

We talk a little more about how each generation reacts to the experience of the previous. McEwan’s charmed life suggests that it is not enough to agree with Larkin that “man hands on misery to man”.

“For my parents’ generation the men especially had looked into the abyss. Afterwards they just wanted to be mowing the lawn or polishing the car,” he says. “They had no problem with ordinariness that for us growing up with peace and prosperity was hard to fathom.” One positive result, McEwan says, “was that parliament was only full of people who had served in the war, so it was usefully risk-averse.”

It is, he says, a shame we don’t have a little more of that character among our politicians now. He returns to our original theme, of the risks presented by the advances of technology and the apparently reckless inadequacy of our current politics to deal with them, or much else. “We are at the beginning of artificial intelligence and assuming civilisation holds together it is going to have a massive effect on employment. Already various forms of nationalism are blaming immigrants for changes that are the result of automation…”

He doesn’t see change coming, but then he knows, too, that prophets are rarely on the money: “There is that rule about imagined futures: things are never quite as bad as pessimists say and never quite as good as optimists hope.”

• Machines Like Me is published by Vintage (£18.99). To order a copy go to guardianbookshop.com or call 0330 333 6846. Free UK p&p over £15, online orders only. Phone orders min p&p of £1.99

• Ian McEwan reflects on his life in writing at the Royal Festival Hall, London, 15 April, 7.30pm