I can't connect a controller to my PS4

Someone I know gave me their PS4, and I haven't been able to connect the controller they gave me (dualshock 4). I followed the instructions onscreen by connecting it to the console using a cord and then hitting the playstation button, but the light turns off after a few seconds and then nothing happens. Anyone got an idea of what to do?

Edit: Got it to work using a beats headphones charger I found