aggiunta parte rele
This commit is contained in:
parent
2ec1d8e75e
commit
05efd8bba1
1 changed files with 55 additions and 0 deletions
55
arduino/rele/rele.ino
Normal file
55
arduino/rele/rele.ino
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <SoftwareSerial.h>
|
||||
#define RELAY1 8
|
||||
|
||||
SoftwareSerial mySerial(4, 2); // RX, TX
|
||||
|
||||
String command = ""; // Stores response of the HC-06 Bluetooth device
|
||||
char blueToothVal; //value sent over via bluetooth
|
||||
|
||||
|
||||
void setup() {
|
||||
// Open serial communications:
|
||||
Serial.begin(9600);
|
||||
Serial.println("Type AT commands!");
|
||||
|
||||
// The HC-06 defaults to 9600 according to the datasheet.
|
||||
mySerial.begin(9600);
|
||||
pinMode(13,OUTPUT);
|
||||
pinMode(RELAY1, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Read device output if available.
|
||||
//if (mySerial.available()) {
|
||||
// while(mySerial.available()) { // While there is more to be read, keep reading.
|
||||
// command += (char)mySerial.read();
|
||||
// }
|
||||
|
||||
// Serial.println(command);
|
||||
// command = ""; // No repeats
|
||||
//
|
||||
//}
|
||||
|
||||
// Read user input if available.
|
||||
if (mySerial.available()){
|
||||
//delay(10); // The delay is necessary to get this working!
|
||||
//mySerial.write(Serial.read());
|
||||
blueToothVal=(char)mySerial.read(); //read it
|
||||
}
|
||||
if (blueToothVal=='n')
|
||||
{//if value from bluetooth serial is n
|
||||
digitalWrite(13,HIGH); //switch on LED
|
||||
digitalWrite(RELAY1,LOW);
|
||||
mySerial.write('n');
|
||||
blueToothVal=' ';
|
||||
}
|
||||
else if (blueToothVal=='f')
|
||||
{//if value from bluetooth serial is n
|
||||
digitalWrite(13,LOW); //turn off LED
|
||||
digitalWrite(RELAY1,HIGH);
|
||||
|
||||
mySerial.write('f');
|
||||
blueToothVal=' ';
|
||||
}
|
||||
delay(1000);
|
||||
}
|
Loading…
Reference in a new issue