You make no mention of your iPad model - this being significant as different iPad models support one, or possibly two, of the available versions of the Apple Pencil.
Here is Apple's definitive compatibility list for Apple Pencil and iPad:
Apple Pencil compatibility - Apple Support
Each Apple Pencil can only be used with the iPad model with which it is compatible; Pencils are otherwise not interchangeable.
A USB-C Pencil can magnetically attach to iPad models that feature a USB-C port, but can only be charged using a wired USB-C connection with the host iPad or Power Adapter.
The second generation Pencil - and new Apple Pencil Pro - attach magnetically with and wirelessly charge from the compatible iPad Air and iPad Pro. The new Pencil Pro is only compatible with the new 2024 iPad Air M2 and Pro M4 models.
These support pages may be helpful with pairing and use of the Pencil with your iPad:
Connect Apple Pencil with your iPad - Apple Support
Charge your Apple Pencil and check the battery - Apple Support
If you continue to experience difficulties, here is one of the better troubleshooting guides:
https://appletoolbox.com/apple-pencil-not-working-heres-our-troubleshooting-guide/
Be aware that if your Pencil has been set-aside for an extended period, unused and uncharged, the Pencil battery may have been damaged through deep discharge. In common with all Li-ion batteries, they must always have some level of charge.
The tiny internal Li-ion battery is susceptible to permanent/irreversible damage through being left discharged for long periods. Even some “new” pencils can exhibit signs of failure out-of-the-box if they are “old stock”.
It is essential that if you have an Apple Pencil that you charge it regularly - whether used or not - so as to protect the battery from deep-discharge. Do not allow a pencil to remain in low-charge state for any period of time - as the internal battery will fail, rendering the Pencil useless. Setting aside an unused Pencil, for extended periods, is a recipe for premature death of the Pencil battery.
If the Pencil Battery has failed, the only remedy is to replace the Pencil. If the battery has failed and your pencil is within its one-year warranty, you should look to having it replaced by your retailer or at an Apple Store.
Gentle warming of the Pencil (such as placing on a hot water radiator), prior to attempting charging of the Pencil, can sometimes resurrect a dead Pencil battery.