-2

I'm sorry if this is a weird question. I have this project from my school. Here's my setup:

  1. Seeeduino Stalker v3
  2. UartSBee v.4
  3. RF_2530 or known as CC2530 (maybe)
  4. Arduino Duemilanove
  5. 2-channel relay shield

enter image description here

So on the first image I have the RF2530 attached to my relay shield and also attached to my Arduino.

enter image description here

On my second image, the RF2530 is attached to the UartSBee.

And lastly I have my Seeeduino connected to the UartSBee by using jumper wire:

Seeeduino----------UartSBee

5v-----------------------VCC

TX-----------------------RX

RX-----------------------TX

GND---------------------GND

DTR----------------------DTR

My goal is, the Seeeduino will receive a GPIO pin from another device, for example if the Seeeduino receives pin 4 HIGH, the LED of RELAY1 will turn on, or if the Seeeduino receives pin 4 LOW, the LED of RELAY1 will turn off.

My problem is, if for example the Seeeduino receives pin 4 HIGH, the relay1 LED doesn't turn on.

Here's my code:

const int relay1 = 4;
const int relay2 = 5;

void setup(){
  Serial.begin(57600);
  pinMode(relay1, INPUT);
  pinMode(relay2, INPUT);
}

void loop(){
  digitalRead(relay1);
  digitalRead(relay2);

  if(relay1 == 1) {
    Serial.println("#M9"); //relay1 HIGH,turn on relay 1 LED
  }
  if(relay1 == 0) {
    Serial.println("MA"); // relay1 LOW,turn off relay 1 LED
  }

  if(relay2 == 1) {
    Serial.println("#MB"); //relay2 HIGH,turn on relay 2 LED
  }
  if(relay2 == 0) {
    Serial.println("MC"); //relay2 LOW,turn off relay 2 LED
  }
  return 0;
}

Can someone point out what I'm missing? Any advice would be helpful. Thank you.

dda
  • 6,030
  • 2
  • 25
  • 34

1 Answers1

0

First of all, your if sentences are wrong. Change for this:

if(digitalRead(relay1) == 1) {
    Serial.println("#M9"); //relay1 HIGH,turn on relay 1 LED
  }
  if(digitalRead(relay1) == 0) {
    Serial.println("MA"); // relay1 LOW,turn off relay 1 LED
  }

  if(digitalRead(relay2) == 1) {
    Serial.println("#MB"); //relay2 HIGH,turn on relay 2 LED
  }
  if(digitalRead(relay2) == 0) {
    Serial.println("MC"); //relay2 LOW,turn off relay 2 LED
  }

In the first of your if senteces you are comparing 4==1, at the second 4==0 ...

Zharios
  • 183
  • 1
  • 18