Final code for arduino fixed.