char val; // Data received from the serial port int ledPin = 13; // Set the pin to digital I/O 13 int fanPin = 5; boolean ledState = LOW; //to toggle our LED int sensorValue; int sensorLow = 1023; // variable to calibrate high value int sensorHigh = 0; char s; char r; String in; void setup() { pinMode(ledPin, OUTPUT); pinMode(fanPin, OUTPUT); //initialize serial communications at a 9600 baud rate Serial.begin(9600); establishContact(); // send a byte to establish contact until receiver responds digitalWrite(ledPin, HIGH); while (millis() < 5000) { // record the maximum sensor value sensorValue = analogRead(A3); if (sensorValue > sensorHigh) { sensorHigh = sensorValue; } // record the minimum sensor value if (sensorValue < sensorLow) { sensorLow = sensorValue; } } digitalWrite(ledPin, LOW); } void loop() { sensorValue = analogRead(A3); if (Serial.available()) { // If data is available to read, val = Serial.read(); if (val == '7' || val == '8') { s = val; } else if (val == '0' || val == '1') { r = val; } else { } } else { Serial.println(sensorValue); //send back a hello world } if (s == '7') { // If 1 was received digitalWrite(ledPin, HIGH); // turn the LED on } else { digitalWrite(ledPin, LOW); // otherwise turn it off } if (r == '0') { // If 1 was received digitalWrite(fanPin, HIGH); // turn the LED on } else { digitalWrite(fanPin, LOW); // otherwise turn it off } delay(50); } void establishContact() { while (Serial.available() <= 0) { Serial.println("A"); // send a capital A delay(300); } }