/* * Sofware Serial test code for Bluetooth module * This code reads incomming data and sends it back over the Software serial line. * Next it turns the internal LED on when the received data is 1. * It turns the LED off when the received data is not 1. * This code is based on the work of Cody Bradly at http://www.ernstc.dk/arduino/tinycom.html * and on the SoftwareSerialExample Tom Igoe * * Date 2019-04-24 * Author Joey van der Bie * */ #include const int RX = 0; const int TX = 1; SoftwareSerial mySerial(RX, TX); int received = 0; const int LED_PIN = 7; void setup() { pinMode(RX, INPUT); pinMode(TX, OUTPUT); mySerial.begin(9600); // declare the LED pin as an OUTPUT: pinMode(LED_PIN, OUTPUT); } void loop() { if ( mySerial.available() ) { received = mySerial.parseInt(); mySerial.println(received); if(received == 1){ //turn LED on digitalWrite(LED_PIN, HIGH); }else { // turn LED off digitalWrite(LED_PIN, LOW); } } // delay(10); }