* Example Bluetooth Serial Passthrough Sketch by: date: license: This example sketch converts an RN-42 bluetooth module to communicate at 9600 bps (from 115200), and passes any serial data between Serial Monitor and bluetooth module. */ // eisodos me xonokathsterisi #include int bluetoothTx = 8; // TX-O pin of bluetooth mate, Arduino D8 int bluetoothRx = 9; // RX-I pin of bluetooth mate, Arduino D9 SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); char character; // diabazei ta dedomena apo to bluethooh int laststate = HIGH ; // xrisimopoieitai gia to delay ton 30 sec int countertime =0; // to count time void setup() { Serial.begin(9600); // Begin the serial monitor at 9600bps bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps bluetooth.print("$"); // Print three times individually bluetooth.print("$"); bluetooth.print("$"); // Enter command mode delay(100); // Short delay, wait for the Mate to send back CMD bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity // 115200 can be too fast at times for NewSoftSerial to relay the data reliably bluetooth.begin(9600); // Start bluetooth serial at 9600 // initialize pins outputs pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH); digitalWrite(10, HIGH); } void loop() { if(bluetooth.available()) // If the bluetooth sent any characters { character = bluetooth.read(); Serial.print((char)bluetooth.read()); // Send any characters the bluetooth prints to the serial monitor Serial.write(character); if (character == '1' ) { laststate = LOW ; countertime = 0; digitalWrite(13, HIGH); digitalWrite(12, HIGH); digitalWrite(11, LOW); // digitalWrite(10, LOW); ****************** not activated ********************************** } else { if (character == '0') { laststate = HIGH ; countertime = 0; digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH); digitalWrite(10, HIGH); } } } //******** delay loop ************************** if (laststate == LOW ) { countertime++ ; Serial.println(countertime); delay(200); } if (countertime>=100 && laststate==LOW) // it test the time = 20 sec { laststate= HIGH ; countertime = 0; digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH); digitalWrite(10, HIGH); } //********************* end delay loop ********************************* /* if(Serial.available()) // If stuff was typed in the serial monitor { // Send any characters the Serial monitor prints to the bluetooth bluetooth.print((char)Serial.read()); } // and loop forever and ever! */ } // END PROGRAMM