I just got home with a Brand new S4 and was trying to do all the basic setup with email and wifi and all the goodies. Well, I can not connect to my home wifi at all. When I slide the wifi button to the on position in the setting screen, it stays there for a couple seconds, stays gray, then goes back to the off position. When I try to turn it on the the quick settings, it turns dark green, stays that way for a couple seconds, then turns off again. I have Android version 4.3 on the phone and have an Actiontec MI424WR Gen2 wireless router. Any help will be greatly appreciated. Thank you.
In many cases it is not the phone but the router.
You can try this. Turn off the router count to twenty and plug it back in. See if the router reset will find your phone.
If that does not work, you may need a router firmware update if one is available. If none are available you may need to purchase another newer router or borrow one if a friend has a spare and see if that fixes your issue.
Another thing to do is go to a know public wifi spot like McDonalds or Starbucks or Jiffy Lube etc. and see if the device connects. If it does then it is a home router situation.
At a last resort I would do a phone device reset instructions here.
Then see if that fixes your issue.