Fan wiring – unable to get ceiling fan work with switch

ceiling-fanwiring

Trying to install ceiling fan. There are 3 wire (black, red, white and ground). Both black and red are hot. The green one in the picture is from fan mount. The bare wire is the ground coming from the junction box.
enter image description here

When I connect ceiling fan's black to black and fan's white to white the fan starts once breaker is turned on.

There is one switch I assumed is for the fan and it has both black and red are hot. But it is not controlling the fan.

enter image description here

How should I connect the fan so I can operate it with switch?

Best Answer

You'll want to hook your fan white wire to the ceiling white wire. Then hook your fan black wire to the ceiling red wire. Hook your green wire to the bare copper ground wire from the ceiling. Wire nut the unused black wire from the ceiling. Verify that the existing junction box is rated for a ceiling fan. It should be stated inside the junction box.