Media playback is unsupported on your device Media caption The Ayrton Senna Foundation is helping millions of students in Brazil

Twenty-three years after his death, former Formula 1 world champion Ayrton Senna's name is almost as valuable as when he was alive - and it is making a difference in his home country of Brazil.

It is Friday afternoon and children around the age of 12 are gathered in the computer lab of a public school in Itatiba, a small town an hour away from Sao Paulo.

Class time is already over for the week, but these students have chosen to stay in school for extracurricular activities.

They are learning Scratch, a piece of software developed by MIT experts that aims to teach kids how to code.

Most public schools in Brazil don't have computer coding in their curriculum. In fact, most schools are struggling to get kids to learn the basics, such as maths and Portuguese, as Brazil ranks among the worst countries in the world in school exams.

Image caption The coding class is courtesy of the Ayrton Senna Foundation

Students and staff in Itatiba have little interest in Formula 1. But much of what is going on in the classroom is part of the legacy of legendary driver Ayrton Senna, killed in a tragic accident during the San Marino Grand Prix on 1 May 1994.

Senna family affair

The coding class is a project run by the Ayrton Senna Foundation, a non-governmental organisation (NGO) that was founded by Ayrton's sister Viviane a few months after his death.

Most of the money for the Foundation comes from managing Senna's brand and legacy.

Ayrton Senna is still one of the most valuable sporting brands in the world.

Image copyright Getty Images Image caption Senna is still a beloved figure in Brazil

In the past five years, the foundation drew in about 1bn Brazilian reais (£250m; $320m) for the NGO.

And it's all a family affair. While Viviane is the CEO of the foundation, her daughter Bianca is head of branding.

The foundation uses the money it raises to fund ambitious educational projects, which are today its core business.

"Usually companies have a philanthropic arm that helps society with social projects. We are the other way around. We are the only NGO I know that has a sports branding company inside it," says Bianca.

Still a draw

Ayrton Senna is still a goldmine in terms of marketing.

Image copyright Juan Guerra/Instituto Ayrton Senna Image caption "We're an NGO with a sports branding company inside it," says Ayrton's niece Bianca Senna

The strongest markets for Senna products are Brazil, the UK and Italy.

Research conducted in 2015 by the Boston Consulting Group suggests Senna is in the same league as tennis superstar Roger Federer and basketball legend Michael Jordan in terms of product endorsement potential.

Another survey of Brazilian athletes who competed in last year's Rio Olympics - many of them too young to have seen Senna race - ranked him as their biggest source of inspiration, above past and present idols such as Neymar and Pele.

The foundation does its best to fully explore the marketing potential, licensing hundreds of products with Senna's face and name on it.

It caters for two groups of consumers. The first are Formula 1 fans who buy products such as books, DVDs, helmets and collectible souvenirs.

Image caption The foundation licenses hundreds of Ayrton Senna-themed items, like these action figures

And then there are products for the general public who may not necessarily enjoy racing, but like Senna for his charisma and values. These include toys and comic books for children and a food line of ketchup, mustard and mayonnaise.

Peerless brand

Marketing specialist Marcos Machado, from TopBrands Consultancy, says Senna's tragic death while at the top of his game crystallised his image in the eyes of the public as a winner.

Most sports stars eventually lose their appeal when they get older and retire. Some devalue their own brands by getting involved in scandals - think Ryan Lochte and Tiger Woods.

"If you consider Senna as a brand, I don't think he has many competitors," says Machado.

Ayrton Senna's career

Image copyright Getty Images

World champion three times - in 1988, 1990 and 1991

161 grand prix starts

41 wins

65 pole positions

First race - 1984 Brazilian GP

First win - 1985 Portugese GP

Last win - 1993 Australian GP

Last race - 1994 San Marino GP

F1's greatest drivers: Ayrton Senna

One of the brand's strengths is that virtually all money from licensing goes to charity, not profit.

Education is the foundation's core business. Over the past two decades, it has become one of the biggest NGOs in Brazil, helping 1.9 million children and training 60,000 teachers per year.

Image caption Senna's name is also used for a range of foodstuffs including mustard, mayonnaise and ketchup

It invests heavily in research to come up with what Viviane Senna calls "vaccines" - smart solutions that can be applied to many schools with low costs.

Social and emotional skills

Last year it achieved one of its greatest successes in Colegio Chico Anysio, a public school in Rio de Janeiro with students from low-income families.

The institute revamped the curriculum, training students in social and emotional skills such as resilience, discipline and determination, instead of focusing solely on traditional subjects, such as maths and languages. It even came up with special metrics to identify these skills.

And in the national students' exam, Colegio Chico Anysio was ranked the fifth best school for its income level.

Image copyright Ivan Franchet/Instituto Ayrton Senna Image caption The foundation aims for low-cost solutions that can work in many schools, says Viviane Senna

This year the institute is applying its "vaccine" to 20 other schools in the south of Brazil.

Its work does not come without criticism, though.

Teachers' unions complain that social and emotional skills are personal traits - not skills to be measured - and that the foundation sees schools and teachers too much as enterprises.

Viviane Senna disagrees.

"If someone from the 19th Century travelled to our time, he wouldn't see any difference in classrooms. But the rest of the world has been through a technological and scientific revolution.

"And it's not just about bringing tablets and mobiles into students' hands. It's about giving them social and emotional skills to face our world."

Uphill struggle

Despite some successes, Brazil's level of education has been slipping recently in the Programme for International Student Assessment (Pisa) global rankings.

Brazil has 50 million children in school, aged between six and 16. Only one in five end up graduating from high school. All others are lost along the way.

Image caption Keeping interest in Ayrton Senna's name is likely to get harder as the years go by

The future is fraught with challenges for the foundation. All the work it does with schools needs to be approved by state and city governments, but public finances are collapsing in Brazil thanks to the recession.

On the branding front, it must keep the interest in Senna's name alive, a task that is likely to get harder as years go by.

"The foundation has done outstanding work. And interest in Senna can be sustained, but not forever," says Mr Machado.

"We have to be realistic. One day, Senna is going to be more of a distant memory than a real idol for young generations. You can keep his name alive, but not forever."

On the racetrack, Ayrton Senna made a name for himself as a driver who could do things that seemed impossible. The foundation that now carries his name is trying to live up to that legacy.