Introduction: Interactive Lamp for Your Night Time Routine

Do you agree that the common goal of human life is happiness? Here I will explain how to make a furniture that will make your life happier. The key to happiness is appreciating what happened to you every day. This night lamp will help you to end your days full of gratitude and happiness. As you enter into your bed room the sensor catch you and turn on the light. The lamp prevent you from turning off your light until you publish one blog post about something you are grateful for. The lamp has a phone charging station for you to simple place your phone on the lamp that is next to your bed.

Step 1: Materials

What you need

  • Breadboard
  • PIR Motion Sensor
  • Qi Wireless Charging Module
  • Universal Qi Wireless Charging Transmitter
  • 5V 2A (2000mA) switching power supply - UL Listed
  • breadboard
  • Powerswitch tail
  • Adafruit HUZZAH ESP8266 Breakout
  • FTDI Serial TTL-232 USB Cable
  • USB Cable
  • Plastic sheet
  • Heating gun
  • Cell phone
  • Computer
  • IFTTT ID
  • Adafruit.io ID
  • Cell Phone Cover

Step 2: Connect Huzzah to Adafruit to IFTTT

1. Solder the Huzzah

https://learn.adafruit.com/adafruit-huzzah-esp8266...

2. Huzzah to Adafruit.io

https://learn.adafruit.com/adafruit-io-basics-digi...

3. Setup IFTTT to connect to Adafruit.io (see the picture)

Make A IFTTT ID

Create a recipe: If Blogger then Adafruit

Insert the feed you made at the Adafruit.io

4. Write codes (You need to customize Wifi and Adafruit information)

/***************************************************

Adafruit MQTT Library ESP8266 Example

Must use ESP8266 Arduino from:

https://github.com/esp8266/Arduino

Works great with Adafruit's Huzzah ESP board:

----> https://www.adafruit.com/product/2471

Adafruit invests time and resources providing this open source code,

please support Adafruit and open-source hardware by purchasing

products from Adafruit!

Written by Tony DiCola for Adafruit Industries.

Adafruit IO example additions by Todd Treece.

MIT license, all text above must be included in any redistribution

****************************************************/

#include

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

// function prototypes

void connect(void);

/****************************** Pins ******************************************/

#define LAMP 12 // power switch tail

/************************* WiFi Access Point *********************************/

#define WLAN_SSID “Wifi Name"

#define WLAN_PASS “Wifi Passwords"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883

#define AIO_USERNAME “Your Adafruit.io User Name”

#define AIO_KEY “Copy the Key from Adafruit.io"

/************ Global State (you don't need to change this!) ******************

/ Create an ESP8266 WiFiClient class to connect to the MQTT server.

WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.

// This is required for using the Adafruit MQTT library.

const char MQTT_SERVER[] PROGMEM = AIO_SERVER;

// Set a unique MQTT client ID using the AIO key + the date and time the sketch

// was compiled (so this should be unique across multiple devices for a user,

// alternatively you can manually set this to a GUID or other random value).

const char MQTT_CLIENTID[] PROGMEM = __TIME__ AIO_USERNAME;

const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;

const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************

/ Setup a feed called 'lamp' for subscribing to changes.

// Notice MQTT paths for AIO follow the form: /feeds/

const char LAMP_FEED[] PROGMEM = AIO_USERNAME "/feeds/lamp";

Adafruit_MQTT_Subscribe lamp = Adafruit_MQTT_Subscribe(&mqtt, LAMP_FEED);

/*************************** Sketch Code ************************************/

void setup() {

// set power switch tail pin as an output

pinMode(LAMP, OUTPUT);

Serial.begin(115200);

Serial.println(F("Adafruit IO Example"));

// Connect to WiFi access point.

Serial.println(); Serial.println();

delay(10);

Serial.print(F("Connecting to "));

Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(F("."));

}

Serial.println();

Serial.println(F("WiFi connected"));

Serial.println(F("IP address: "));

Serial.println(WiFi.localIP());

// listen for events on the lamp feed

mqtt.subscribe(&lamp);

// connect to adafruit io

connect();

}

void loop() {

Adafruit_MQTT_Subscribe *subscription;

// ping adafruit io a few times to make sure we remain connected

if(! mqtt.ping(3)) {

// reconnect to adafruit io

if(! mqtt.connected())

connect();

}

// this is our 'wait for incoming subscription packets' busy subloop

while (subscription = mqtt.readSubscription(1000)) {

// we only care about the lamp events

if (subscription == &lamp) {

// convert mqtt ascii payload to int

char *value = (char *)lamp.lastread;

Serial.print(F("Received: "));

Serial.println(value);

int current = atoi(value);

// write the current state to the power switch tail

digitalWrite(LAMP, current == 1 ? HIGH : LOW);

}

}

}

// connect to adafruit io via MQTT

void connect() {

Serial.print(F("Connecting to Adafruit IO... "));

int8_t ret;

while ((ret = mqtt.connect()) != 0) {

switch (ret) {

case 1: Serial.println(F("Wrong protocol")); break;

case 2: Serial.println(F("ID rejected")); break;

case 3: Serial.println(F("Server unavail")); break;

case 4: Serial.println(F("Bad user/pass")); break;

case 5: Serial.println(F("Not authed")); break;

case 6: Serial.println(F("Failed to subscribe")); break;

default: Serial.println(F("Connection failed")); break;

}

if(ret >= 0)

mqtt.disconnect();

Serial.println(F("Retrying connection..."));

delay(5000);

}

Serial.println(F("Adafruit IO Connected!"));

}

Step 3: Install PIR Motion Sensor

1. Plug a microcontroller

PIR’s the red cable is + voltage power, black cable is - ground power and yellow is the signal out. Just make sure you plug the cable in as shown above! If you get it backwards you won't damage the PIR but it won't work.

2. Cables to the breadboard

Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin. In this example we'll use pin 2.

The code is very simple, and is basically just keeps track of whether the input to pin 2 is high or low. It also tracks the state of the pin, so that it prints out a message when motion has started and stopped.

3. Write codes (This will be used in the step 4)

/*

* PIR sensor tester

*/

int inputPin = 2; // choose the input pin (for PIR sensor)

int pirState = LOW; // we start, assuming no motion detected

int val = 0; // variable for reading the pin status

void setup() {

pinMode(ledPin, OUTPUT); // declare LED as output

pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);

}

void loop(){

val = digitalRead(inputPin); // read input value

Serial.println(val);

if (val == HIGH) { // check if the input is HIGH

digitalWrite(ledPin, HIGH); // turn LED ON

if (pirState == LOW) {

// we have just turned on

Serial.println("Motion detected!");

// We only want to print on the output change, not state

pirState = HIGH;

}

} else {

digitalWrite(ledPin, LOW); // turn LED OFF

if (pirState == HIGH){

// we have just turned of

Serial.println("Motion ended!");

// We only want to print on the output change, not state

pirState = LOW;

}

}

}

Step 4: Blend the Codes

Copy the code from the step 3 and break down to paste into the code from step 2.

Step 5: Make the Lamp

You can use the lamp that use already have.

My lamp is made out of 2 sheets of acrylic boards.

1, draw a out line of your lamp and the charging station in illustrator.

2, laser cut them.

3, Use heating gun to bend.

Step 6: Attach Phone Wireless Phone Charger

Assemble 3 items below (I bought them from Adafruit)

  • Qi Wireless Charging Module - 20mm - Lightning Connector

https://www.adafruit.com/products/2677

  • Universal Qi Wireless Charging Transmitter

https://www.adafruit.com/product/2162

  • USB cable - 6" A/MiniB

https://www.adafruit.com/products/899

Tech Contest

Participated in the
Tech Contest