I'm happy that you have asked me to assist you with your child and hope that you can benefit from my many years of helping parents like you.
I see you are offline so I'll wait until chat times out to see if you return.
Let me first tell you that heart pain is almost unheard of in children since that is due to a lack of oxygen in the heart muscle from coronary artery disease, which of course is unlikely in someone his age. Lung pain can occur, called pleurisy, when a pneumonia exists and there is inflammation between the lung and the chest wall lining. Unless he has had a chest infection this also is unlikely.
This leaves the most common cause of chest pain in children, which is called costochondritis, a chest wall pain due to inflammation of the joint where the rib attaches to the breast bone (sternum), or less often, where the rib attaches to the spine.
All of us have this pain from time to time but it is far more common in young people. While painful for a few seconds at a time, with both breathing and movement sometimes, it is harmless but scary for kids and their parents.
I see you are back!
Sometimes we see costochondritis occur following a viral infection, especially a chest cold, and after trauma, such as a blow to the chest, or weight lifting, but most of the time there is no known injury or infection and it is more like a transient arthritis of that joint. Commonly it occurs along the left side of the sternum so everyone assumes it is from the heart but the pain can be duplicated often by pressing on the junction of the rib and sternum and that is diagnostic, along with the history.
All that you need to do is give him ibuprofen, perhaps 200 mg every 8 hours, for a few days and this will usually make it go away. It may come and go, much like growing pains do in the legs, and if the ibuprofen does not help he should be seen by his doctor.
I see you are typing an answer so I'll keep relocking on this chat conversation as the site times out every 5 minutes.
I pressed on the junction. He said that it hurts but not the same kind of pain. The pain that he usually feels is more inside.
That is OK as you probably are not pressing like I would directly on the joint. Again there are very limited possibilities for the pain and with it being intermittent costochondritis is most likely. To support my diagnosis here is a link for you to take a look at about this very common problem:
The pain is not constant, just few seconds. Does he still need to take ibuprofen? Could it go away without ibuprofen and how long it could take?
That is exactly how it is supposed to happen and yes, ibuprofen is necessary to stop it, just as it works with other inflammation. The only way to calm it down is a few days on ibuprofen (3-5) to get him over it.