How to combine Genuino Starter Kit Project 9 and 15?

I have been working on a project that needs to use optocoupler as the output switch to control a motor, which is quite similar to the given project 09 and 15. any idea about how to change the circuit and combine the code?

Combining sketches can be a challenge... See THIS for some suggestions.

Thanks for the useful link! I am new to arduino system and try to combine thiese two example projects. I am afraid to burn the board if the circuit is connected incorrectly. also not sure where to start on the code.