I think it's not possible, even with artificial intelligence. Or at least very very very unlikely to happen. Why? Only 1 reason: when someone makes a coding, he makes backups, code in a way he can still controle the CPU in case of burnout, or in worst case, just reboot/reset it. Everything on a code isn't "intelligence" even if the program learns, and acts as a person. It's only codes, commands, and you simply erase some of them and the device isn't anything anymore. A device won't ever be able to think (at least with the way it's currently made), and the only thing that can pass through its "mind" are numbers. If you want tech to take over us, you'll need something much more complex than some wires than can sit a "on" and "off" state (equals to the "1" and "0" in binary).
Also, I don't think it's possible for this reason: just imagine if you could module a brain like a program. Change the connections, reboot, or even reset it. You would get a brand new person, or a baby in an adult body.
Well that's exactly what you can do to a device or a program. A program becomes hostile? Reboot it! It starts again? Erase its memory, and then change a bit of its code so it won't make the same mistakes.
The only "plausible" way in my opinion is the way of Avengers with Ultron. Only because they didn't code it, theu can't change its code, they can't shut it down, and more especially, it was not a program in the first place, it was an artifact with a consciousness (which doesn't exist, or isn't discovered yet, in our real world).