Hi! I'm doing my final project for college and I started to have some problems and hope someone can help me. My task is to build "smart room", control LEDs, Light bulb, get temperature on request, and
possibly electronic door lock everything controlled trough bluetooth and smart phone (android). So with LED shield I managed to put LEDs in function (with 3 sliders in app R,G,B) so I moved on controlling light bulb with relay module and that is where all stopped. I guess it's because of analog/digital data collision.
I'm doing app in "MitAppInventor 2".
Is it even possible to do something like it's imagined?
CODE:
#include <SoftwareSerial.h>
int bluetoothTx = 0;
int bluetoothRx = 1;
int val=0;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(3,OUTPUT); // Crvena LED
pinMode(5,OUTPUT); // Zelena LED
pinMode(6,OUTPUT); // Plava LED
pinMode(8,OUTPUT); // Bulb - relay
digitalWrite(3,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()>= 2 )
{
unsigned int color1 = bluetooth.read();
unsigned int color2 = bluetooth.read();
unsigned int color = (color2 *256) + color1;
Serial.println(color);
if (color >= 1000 && color <1255){
int blue = color;
blue = map(blue, 1000,1255,0,255);
analogWrite(6,blue);
Serial.println(blue);
delay(10);
}
if (color >=2000 && color <2255){
int green = color;
green = map(green,2000,2255,0,255);
analogWrite(5,green);
Serial.println(green);
delay(10);
}
if (color >=3000 && color < 3255){
int red = color;
red = map(red, 3000, 3255,0,255);
analogWrite(3,red);
Serial.println(red);
delay(10);
}
// LIGHT BULB
if (color == 4002){
digitalWrite(8,LOW);
delay(10);
}
if (color == 4001){
digitalWrite(8,HIGH);
delay(10);
}
}
}
--EDIT-- I use bluetooth module HC-06 and arduino UNO