Sorry for the poor explanation. What happens is that when I have the arduino connected to my computer via usb cord it works fine but when I try to use a 9v battery to power it via vin it does the same (wrong) thing every time. When it is connected to the computer via usb, it works.