2.5V output using IR Receiver

Hi,

I am reading some hex code from an IR receiver on a Nano. The output pins are 5,6,7 and 9.

Here is what I am trying to do…each pin of the output should trigger a relay connect via a 1K resistor and a BC548 transistor. There are 4 relays in all which I am using to switch between audio inputs for my hifi setup.

The problem I am facing is that the arduino output reads only 2.5V which is insufficient to drive the relays. Note that the relays are on a separate power supply.

I used the code on this site…http://randomnerdtutorials.com/arduino-ir-remote-control/. However, I have modified the code (as I do not want any blinking etc). I am an absolute noob when it comes to coding, I kept on trying using different variations of the logic till I was able to get the switching action right. I connected LEDs to the 4 pins and they work alright, but the relays do not. The modified code is also attached.

Will be great if I can get some help to sort this out.

ArduinoSwitcher.ino (2.59 KB)

A schematic of the relay connections would probably be useful.

The relay connection is a fairly standard one.

The output from the Arduino goes to the base of a BC548 via a 1k resistor. The transistor then energises the relay.There is no optocoupler or isolator in the path. The relay energises if it receives a +5V signal on the transistor base.

But the problem is that the Arduino is not generating the 5V output.

Unless you try to source too uch current Arduino should be able to drive the pin to the supply voltage. Are you sure the pin is configured as OUTPUT?

This is the code…

/*
Control LED’s with a remote control
Modified by Rui Santos, http://randomnerdtutorialscom
based on IRremote Library - Copyright Ken Shirriff
*/

#include <IRremote.h>

int IR_Recv = 11; //IR Receiver Pin 3
int g_ledPin = 5; //green LED pin 5
int y_ledPin = 6; //yellow LED pin 6
int r_ledPin = 9; //red LED pin 9
int b_ledPin = 7; //blue LED pin 10
int ledPins = {5, 6, 9, 7}; //array with all the LED’s pins
int ledStates = {0, 0, 0, 0}; //this means the LED’s states at first is 0 = LOW
int i = 0; //LED index for the arrays

IRrecv irrecv(IR_Recv);
decode_results results;

//variables to make the LED blink when selected
int ledState = LOW; // ledState to turn the LED on or off

void setup() {
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(g_ledPin, OUTPUT); // sets the digital pin as output
pinMode(y_ledPin, OUTPUT); // sets the digital pin as output
pinMode(r_ledPin, OUTPUT); // sets the digital pin as output
pinMode(b_ledPin, OUTPUT); // sets the digital pin as output
}

void loop() {
//decodes the infrared input
if (irrecv.decode(&results)) {
long int decCode = results.value;
Serial.println(decCode);
//switch case to use the selected remote control button
switch (results.value) {
case 284139615: //when you press the Forward button
//this if/else statement makes sure that LED is ON or OFF before move to the next LED
if (ledStates == 0)
_ digitalWrite(ledPins*, LOW);_
_
else*_
_ digitalWrite(ledPins*, HIGH);
Serial.println(“Next LED”);
//makes sure that when we reach the last LED it goes to the first LED again*
* if (i >= 3)
i = -1;
i += 1;
break;
case 284098815: //when you press the Reverse button*
* //this if/else statement makes sure that LED is ON or OFF before move to the previous LED*
if (ledStates == 0)
digitalWrite(ledPins*, LOW);
else*

digitalWrite(ledPins*, HIGH);
Serial.println(“Previous LED”);
//makes sure that when we reach the first LED it goes to the last LED*

* if (i <= 0)
i = 4;
i -= 1;
break;
default:
Serial.println(“Waiting”);
}
irrecv.resume(); // Receives the next value from the button you press*

* }
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else*

* ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPins, ledState);
}
}*

I am not an expert in this, so any help to identify where I am going wrong will very helpful._

Use code tags to post code. Probably you are quickly switching the output on and off and it looks like 2.5V output.

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
We need to see your circuit diagram.

Have you got the gnd of the Arduino and the gnd of the power supply for the relay connected together?

Can you measure the voltage on the Arduino output with the DMM in AC rather than DC mode?
Have you written some simple code that turns the relays on one at a time to check your hardware?

Tom... :slight_smile:

Sorry everyone for not reading the posting rules.

To answer your questions - yes, the two grounds are connected together.

Secondly, the picture posted by Tom is the way the circuits are connected. For example, pin 5 of the Nano connects to a 1k resistor which connects to the base of the transistor BC548.

The code is included below…

/*
   Control LED's with a remote control
   Modified by Rui Santos, http://randomnerdtutorialscom
   based on IRremote Library - Copyright Ken Shirriff
*/

#include <IRremote.h>

int IR_Recv = 11;   //IR Receiver Pin 3
int g_ledPin = 5;  //green LED pin 5
int y_ledPin = 6;  //yellow LED pin 6
int r_ledPin = 9;  //red LED pin 9
int b_ledPin = 7; //blue LED pin 10
int ledPins[] = {5, 6, 9, 7};  //array with all the LED's pins
int ledStates[] = {0, 0, 0, 0}; //this means the LED's states at first is 0 = LOW
int i = 0; //LED index for the arrays

IRrecv irrecv(IR_Recv);
decode_results results;

//variables to make the LED blink when selected
int ledState = LOW;             // ledState to turn the LED on or off

void setup() {
  Serial.begin(9600);  //starts serial communication
  irrecv.enableIRIn(); // Starts the receiver
  pinMode(g_ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(y_ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(r_ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(b_ledPin, OUTPUT);      // sets the digital pin as output
}

void loop() {
  //decodes the infrared input
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    Serial.println(decCode);
    //switch case to use the selected remote control button
    switch (results.value) {
      case 284139615: //when you press the Forward button
        //this if/else statement makes sure that LED is ON or OFF before move to the next LED
        if (ledStates == 0)
          digitalWrite(ledPins, LOW);
        else
          digitalWrite(ledPins, HIGH);
        Serial.println("Next LED");
        //makes sure that when we reach the last LED it goes to the first LED again
        if (i >= 3)
          i = -1;
        i += 1;
        break;

      case 284098815: //when you press the Reverse button
        //this if/else statement makes sure that LED is ON or OFF before move to the previous LED
        if (ledStates == 0)
          digitalWrite(ledPins, LOW);
        else
          digitalWrite(ledPins, HIGH);
        Serial.println("Previous LED");
        //makes sure that when we reach the first LED it goes to the last LED
        if (i <= 0)
          i = 4;
        i -= 1;
        break;

      default:
        Serial.println("Waiting");
    }
    irrecv.resume(); // Receives the next value from the button you press
  }
  {
    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(ledPins, ledState);
  }
}

Hi, Have you measured the output with the DMM in AC mode?

Tom.... :)

I don't know what

if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    // set the LED with the ledState of the variable:
    digitalWrite(ledPins, ledState);

does but I am quite sure it is not what you meant. You cannot work with arrays this way.

digitalWrite(ledPins, ledState); should be digitalWrite(ledPin[pin#], ledState); to do one output at a time. Put the code in a loop if you want to do more than 1.

Hello Tom,

I measured the output with a DMM in AC mode. It reads 4.4V. What does this mean ?

Thanks.

Hi, It means your code is not turning the output ON continuously, it is being turned ON and OFF very quickly, too fast for the relay to operate, so you have some code problems.

Did you try a simple code to check that the relays do operate correctly, write a bit of code that turns the outputd On and OFF every 2Seconds, you should see/hear the relays clicking at that rate.

Tom... :)

Thanks Tom.

I will try what you have recommended tonight. I do not know anything about coding but will give it a try.

I have a very basic requirement. I have a Sparkfun remote. Essentially, what I want to do is when I press either the Forward or Reverse key, 4 designated pins of the Arduino should toggle through `HIGH'. Which means if say I have pins 5,6,7,9 configured as output, then on pressing Forward, pin 5 should be HIGH (and all other pins should be LOW) and stay HIGH, when I press FORWARD again, pin 6 should go HIGH (and all other pins should be LOW), so on and so forth.

I read up on a lot of code and circuits with 4 relays or 4 LEDs etc, but in all cases, the code programs 4 specific keys to do this on the remote. Each key allows a specific output to go HIGH or LOW.

Since I will be using the Arduino to switch between audio inputs, I cannot even accidentally have two outputs as HIGH simultaneously.

If there is anyone who can help with some code for this, it will be great. Sorry if I am asking for a bit too much !