/* This sketch runs on an Arduino connected to an ATtiny85 running w13_ATtiny85_slave.ino The data received is from a HC-SR04 sensor */ #include String cmd=""; byte distance; // Where the Distance is stored (8 bit unsigned) #define RX 2 #define TX 3 #include SoftwareSerial bluetooth(RX,TX); void setup() { Wire.begin(); Serial.begin(9600); //Initialize Bluetooth Serial Port bluetooth.begin(9600); } void loop(){ //Read data from HC06 while(bluetooth.available()>0){ cmd+=(char)bluetooth.read(); } //Select function with cmd if(cmd!=""){ Serial.print("Command recieved : "); Serial.println(cmd); // We expect ON or OFF from bluetooth if(cmd=="ON"){ Serial.println("Function is on"); }else if(cmd=="OFF"){ Serial.println("Function is off"); }else{ Serial.println("Function is off by default"); } cmd=""; //reset cmd } Wire.requestFrom(7, 1); // The TinyWire library only allows for one byte to be requested at a time while (Wire.available() == 0) ; // Wait until there is data in the I2C buffer distance = Wire.read(); // Read the first (and hopefully only) byte in the I2C buffer //Write sensor data to HC06 bluetooth.print(distance); delay(1000); }