Arduino Controller using smart phone
Circuit Diagram:
Arduino Source Code
const int redLed=12;
const int greenLed=11;
int state = 0;
//String s;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
Serial.begin(9600); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
if (state==0)
digitalWrite(redLed, LOW);
else if (state==1)
digitalWrite(redLed, HIGH);
if (state==2)
digitalWrite(greenLed, LOW);
else if (state==3)
digitalWrite(greenLed, HIGH);
Serial.println(state); // Send back, to the phone, the String "LED: ON"
}
}
No comments:
Post a Comment