Hello guys,
This week on Bluetooth Unleashed...
We are done with the control unit! A few small things are pending for now and GUI is complete now.
One big thing we've been waiting for...
Unleashing the power of Bluetooth....
Although I had multiple options with Bluetooth to be used on the Arduino side (choices were HM11, Ti CC2650, nRF51822)
but I found a lot of HC-05 laying around (once we used to add this to everything) so thought of putting them to use.
Initially there was a lot of trouble with serial port emulation over Bluetooth, it was discoverable, got paired but it always ended up a connection failure.. and finally
something happened
Blueman bluetooth manager and pyserial made life easy, a few clicks and everything was smooth.
and this time I brought the Arduino Micro into the scene and everything worked like a charm.
A set of charterers and a switch case on the arduino side will controll the GPIOs
The completed Arduino code:
#include <TroykaDHT.h> #include <SoftwareSerial.h> #define ROOM_SUM 11 #define ROOM_CIT 12 #define HUMIDIFIER 2 #define FAN 4 #define LIGHT 5 #define BRX 9 #define BTX 10 #define LIGHT_SENSE A0 void off_all() { digitalWrite(HUMIDIFIER,LOW); digitalWrite(FAN,HIGH); digitalWrite(LIGHT,HIGH); } void freshner (int fresh) { digitalWrite(fresh,HIGH); delay(750); digitalWrite(fresh,LOW); } DHT dht(8, DHT11); SoftwareSerial btserial(BRX, BTX); int hum; float temperature; char bdata; void setup() { pinMode(HUMIDIFIER, OUTPUT); pinMode(ROOM_SUM, OUTPUT); pinMode(ROOM_CIT, OUTPUT); pinMode(FAN, OUTPUT); pinMode(LIGHT, OUTPUT); digitalWrite(FAN,HIGH); digitalWrite(LIGHT,HIGH); btserial.begin(9600); dht.begin(); } void loop() { dht.read(); delay(100); hum = dht.getHumidity(); temperature = dht.getTemperatureC(); int lux; if (btserial.available()){ bdata=btserial.read(); Serial.println(bdata); switch(bdata){ case 'a' : //Auto off_all(); lux = analogRead(LIGHT_SENSE); if (lux < 100) { digitalWrite(LIGHT,LOW); } break; case 'b': //ANGER digitalWrite(LIGHT,HIGH); if (hum<80) { digitalWrite(HUMIDIFIER,HIGH); } if (temperature>26) { digitalWrite(FAN,LOW); } freshner(ROOM_CIT); //delay(480000); break; case 'c': //SAD digitalWrite(LIGHT,HIGH); if (hum<60) { digitalWrite(HUMIDIFIER,HIGH); } if (temperature>26) { digitalWrite(FAN,LOW); } freshner(ROOM_SUM); //delay(480000); break; case 'd': //JOY digitalWrite(LIGHT,HIGH); if (hum<60) { digitalWrite(HUMIDIFIER,HIGH); } if (temperature>26) { digitalWrite(FAN,LOW); } freshner(ROOM_CIT); //delay(480000); break; case 'e': //MANUAL off_all(); break; case 'f': digitalWrite(LIGHT,HIGH); break; case 'g': digitalWrite(LIGHT,LOW); break; case 'h': digitalWrite(FAN,HIGH); break; case 'i': digitalWrite(FAN,LOW); break; case 'j': digitalWrite(HUMIDIFIER,LOW); break; case 'k': digitalWrite(HUMIDIFIER,HIGH); break; case 'l': freshner(ROOM_SUM); break; case 'm': freshner(ROOM_CIT); break; default: break; } } }
to be continued....