I think it would be better to use an optocoupler
Try to search the forum, the question is a quite common