Jithin Thulase
Published © GPL3+

Enable Alexa Control to your Ceiling Fan

Control the speed of your ceiling fan using Alexa and interface device.

IntermediateFull instructions provided3 hours2,920
Enable Alexa Control to your Ceiling Fan

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Relay (generic)
either a 5V relay so that you can directly interface with arduino or a relay interface board would be enough
×1
Fan Regulator
you can use anytype, as ong as you can find terminal to supply power to the same. I would suggest older type regulators which used resistive blocks to reduce voltage supplied
×1

Software apps and online services

Arduino IDE
Arduino IDE
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
Ngrok

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Connection Schematics

this is how you connect the devices together
Testing 2 bttdudidef

Code

arduino sketch

Arduino
upload this code to your arduino and connect it to you raspberry pi server
int Fan[] = {13,12,11,10,9,8}; 
int n=0;
void reset();
void set(char);

void setup() { 
// put your setup code here, to run once: 
for(int i=0;i<6;i++)
{
 pinMode(Fan[i], OUTPUT); 
}
 Serial.begin(9600); 
} 

void loop() { 
 char x;
if (Serial.available())
{
 x=Serial.read();
 reset();
 set(x);
}
}
 
void reset()
{
 for(int i=0;i<6;i++)
 {
 digitalWrite(Fan[i], LOW); 
}
}

void set(char x)
{
 switch (x)
 {
   case '1':
     n=1;
     break;
   case '+':
     n++;
     break;
   case '-':
     n--;
     break;
   case '0':
     n=0;
     break;
 }
 digitalWrite(Fan[n],HIGH);
} 

Python Server code

Python
un this code in your spython after ngrok is setup so as to receive data
from flask import Flask
from flask_ask import Ask, statement
import requests
import json
import serial ser = serial.Serial("/dev/ttyAMA0",9600)
app = Flask(__name__)
ask = Ask(app, '/')
@ask.launch
@ask.intent("FanOn")
def on():    
    ser.write(b'1')    
    return statement("Ceiling Fan turned on.")
@ask.intent("FanOff")
def off():    
    ser.write(b'0')    
    return statement("Ceiling Fan turned off.")
@ask.intent("FanLevelUp")
def up():    
    ser.write(b'+')    
    return statement("Ceiling Fan speed up.")
@ask.intent("FanLevelDown")
def down():    
    ser.write(b'-')    
    return statement("Ceiling Fan speed down.")
if __name__ == "__main__":
    app.run(debug=True)

Credits

Jithin Thulase

Jithin Thulase

1 project • 0 followers
Thanks to Rajesh.

Comments