There are a few reasons why code P0340 can get triggered.
It could be due to a bad sensor as you know, it can also be due to faulty wiring for the sensor. It can even be an issue with the intake camshaft.
The best course of action would be to check off possible causes one by one.
I have attached the trouble shooting steps for the code P0340 below.
Go through those steps and it can help you determine the issue.
Please let me know if you have any questions.
Images (Click to enlarge)
Thursday, January 20th, 2022 AT 8:10 PM