I'm trying out a servo motor for the first time. I want it to turn 0 degree when 'on' is entered and 90 degree when 'off' is entered. But it shows random stuff in the serial monitor and sometimes it just stops working. I don't know whether it's a problem with the code or with the servo. I'm providing a 5V power supply from the arduino UNO.
Don't forget to connect the GND of the external supply to the GND of the Uno so that there is a common point of reference for the servo control signal
As an aside, it is an unfortunate fact that a Uno can provide enough current to drive a servo, but only under very limited circumstances. The Uno is not designed to be used as a power supply