Introduction: Simple IoT Auto Light With Motion Sensor and Cayenne

Hi there, I'm newbie with code and microcontroler unit, but I want to make my life easier.

In this case I want to turn on light automatically when I'm entering a room, and when I leave the room I can turn off using my cellphone.

The simple app for me is Cayenne.

With less code, I can do many things to build IoT devices.

Step 1: Bill of Materials

This the tools needed to do this project.

Hardware Required :

1. NodeMCU ESP-12E

2. PIR Sensor

3. 1 CH Relay Module

4. Jumper Cable

Software Required :

1. Arduino IDE

2. Cayenne for iOS/Android/Web Browser

Step 2: Connecting NodeMcu to Sensor and Relay

NodeMCU_______Sensor__________Relay

VIN_____________ Not connected____VCC (+)

3.3V____________ +_______________Not connected

GND____________-________________GND

D2______________OUT_____________ Not connected

D1______________Not connected____ Signal

Step 3: Upload Code to Microcontroller

In this step we will program the NodeMCU with Arduino IDE.

You need to open PIR_LIGHT.ino, edit your Cayenne token, SSID, password, and then connect your NodeMCU with USB Cable to your computer and upload the code to NodeMCU. Now your NodeMCU is online, but litlle step again to setting up Cayenne Dashboard

Step 4: Setting Up Cayenne

Do this step on Cayenne :


  • Add Motion Sensor widget from Cayenne Dashboard, and select Virtual Pin 12.
  • Add Relay widget from Cayenne Dashboard, and select Virtual Pin 12, Invert Logic
  • Add triggers and set if Motion Sensor detected then Relay turn on.