You will find a transistor will not work as it is a current switching device.
At the moment the digital pin runs straight into the relay and there aren't any apparent issues, so I'm wondering if the 2n2222 is actually necessary.
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16