Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created December 5, 2020 04:23
Show Gist options
  • Save buildcircuit/a08a942ecb05e3d3cfc839a436b11be4 to your computer and use it in GitHub Desktop.
Save buildcircuit/a08a942ecb05e3d3cfc839a436b11be4 to your computer and use it in GitHub Desktop.
Test 6 ports RF module
/****RF SWITCH WITH ARDUINO*/
// The 4 output ports of RF module are connected to A0-A3
//When the Analog pins receive the signal from the RF module, the Arduino activates the corresponding pin.
//For example, when A0 receives a signal, it will turn on Arduino Pin number D2
int sensorPin0 = A0;
int Pin0 = 2; // pin D2
int sensorValue0 = 0;
int sensorPin1 = A1;
int Pin1 = 4; // pin D4
int sensorValue1 = 0;
int sensorPin2 = A2;
int Pin2 = 6; //D6
int sensorValue2 = 0;
int sensorPin3 = A3;
int Pin3 = 8; //D8
int sensorValue3 = 0;
int sensorPin4 = A4;
int Pin4 = 10; //D10
int sensorValue4 = 0;
int sensorPin5 = A5;
int Pin5 = 12; //D12
int sensorValue5 = 0;
void setup() {
Serial.begin(38400);
pinMode(Pin0, OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin5, OUTPUT);
digitalWrite(Pin0, LOW);
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
digitalWrite(Pin5, LOW);
}
void loop() {
sensorValue0 = analogRead(sensorPin0);
if (sensorValue0>=500)
{
digitalWrite(Pin0, HIGH);
Serial.println(sensorValue0);
delay(100);
digitalWrite(Pin0, LOW);
}
else
{
digitalWrite(Pin0, LOW);
Serial.print("Value0:");
Serial.println(sensorValue0);
}
/**********************************************/
sensorValue1 = analogRead(sensorPin1);
if (sensorValue1>=500)
{
digitalWrite(Pin1, HIGH);
Serial.println(sensorValue1);
delay(150);
digitalWrite(Pin1, LOW);
}
else
{
digitalWrite(Pin1, LOW);
Serial.print("Value1:");
Serial.println(sensorValue1);
}
/***********************************************/
sensorValue2 = analogRead(sensorPin2);
if (sensorValue2>=500)
{
digitalWrite(Pin2, HIGH);
Serial.println(sensorValue2);
delay(100);
}
else
{
digitalWrite(Pin2, LOW);
Serial.print("Value2:");
Serial.println(sensorValue2);
}
/***********************************************/
sensorValue3 = analogRead(sensorPin3);
if (sensorValue3>=500)
{
digitalWrite(Pin3, HIGH);
Serial.println(sensorValue3);
delay(100);
}
else
{
digitalWrite(Pin3, LOW);
Serial.print("Value3:");
Serial.println(sensorValue3);
}
/***********************************************/
sensorValue4 = analogRead(sensorPin4);
if (sensorValue4>=500)
{
digitalWrite(Pin4, HIGH);
Serial.println(sensorValue4);
delay(100);
}
else
{
digitalWrite(Pin4, LOW);
Serial.print("Value4:");
Serial.println(sensorValue4);
}
/***********************************************/
sensorValue5 = analogRead(sensorPin5);
if (sensorValue5>=500)
{
digitalWrite(Pin5, HIGH);
Serial.println(sensorValue5);
delay(100);
}
else
{
digitalWrite(Pin5, LOW);
Serial.print("Value5:");
Serial.println(sensorValue5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment