Easy way to controller relays with Easy Remote and simple sketch.
Easy Remote +Arduino+Relays+Bluetooth
on app I used Raw Code Layout Button 1 =off, Buton 2 = on
sketch.Here
/*
simple relay on/off
*/
char val; // variable to receive data from the serial port
int ledpin = 2; // relay connected to pin 2
void setup()
{
pinMode(ledpin = 2, OUTPUT); // pin 2 as OUTPUT
Serial.begin(9600); // start serial communication at 9600bps
}
void loop()
{
if( Serial.available() ) // if data is available to read
{
;
}
val = Serial.read(); // read it and store it in 'val'
if( val == '1' ) // if '1' was received led 2 is switched off
{
digitalWrite(ledpin = 2, LOW); // turn Off pin 2
}
if( val == '2' ) // if '2' was received led 2 on
{
digitalWrite(ledpin = 2, HIGH); // turn ON pin 2
}
}
No comments:
Post a Comment