In this work, a novel electronic lock that can encode and decode optical signals, modulated using Morse code conventions, was developed to build a smart home security system based on the Internet of Things (IoT). There are five topics of interest in this research: (1) optical Morse code encoder; (2) optical Morse code decoder; (3) ambient light sensor circuit; (4) fuzzy controller; (5) cloud monitoring system. We take advantage of the light-emitting components as the encoder, which are readily available in hand-held mobile devices (e.g., Smart phones) and photoresistors and a microcontroller as the decoder. By Wi-Fi transferring, even without a personal computer, real-time information about this lock can be uploaded to the cloud service platform, and helps users to ensure home safety on the remote monitoring system. By using the ambient light sensor and fuzzy controller in this novel optical Morse code-based electronic lock, experimental results show that the reliability of this system is much improved from 65% to 100%. That means that it is highly resistant to different illumination conditions in the work environment, and therefore all functions, including coding, emitting, receiving, decoding, uploading and cloud monitoring, can work well. Furthermore, besides the convenience and cost reduction, by incorporating traditional keys into smart phones, as a consumer electronics, our proposed system is suitable for users of all ages because of a user-friendly operation interface.