Problem using 110v to 5 V transformer

Hi all,

I built a simple circuit to activate a relay when a switch is flipped or if it gets the command remotely using the NRF24L01+ It works like a charm when connected to the usb port, it all just works. But then when I use the 110V to 5V transformer to power it, the wireless signal works fine, but the switch is hit and miss. I have pin 3 set as INPUT_PULLUP for now but I have also tried changing it to a regular INPUT and using a pull down resistor but the result is the same. Also worth mention it that I’m using it as an interrupt. I don’t believe code is the issue since it works just fine using the USB power. I have measured the output voltage after the 5V regulator and I get a very steady 5V. I have been trying to make this work for a few day without any luck. I’m fairly sure that I can’t connect it to the computer using the usb when I have it powered using the transformer so I can’t really do much troubleshooting on that front. Any ideas? Thanks,

I insert my code just in case I missed something that might cause this issue. Thanks again,

#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
#include <EEPROM.h>
#include <avr/interrupt.h>

/**** Configure the nrf24l01+ CE and CS pins ****/
RF24 radio(7, 8);
RF24Network network(radio);
RF24Mesh mesh(radio, network);

/**
   User Configuration: nodeID - A unique identifier for each radio. Allows addressing
   to change dynamically with physical changes to the mesh.
   A unique value from 1-255 must be configured for each node.
   This will be stored in EEPROM on AVR devices, so remains persistent between further uploads, loss of power, etc.

 **/

#define nodeType 1

volatile int RelayPIN = 2;  // Pin used to to control the 110 V relay
int SwitchPIN = 3; // Pin to read the state of the physical light switch
int SwitchState = 0; // Variable to store the state of the physical light swtich
int PrevSwitchState = 0; // Variable to remember the position of the switch
volatile int RelayState = 0;  // Variable to record the state of the relay everytime we change it.
char dat[8]; // The code used to communicate with the master node
char recvd[8]; // The variable to store received data from nodes
uint32_t displayTimer = 0;
int nodeID = 2;
String myMessage = "";
volatile static unsigned long last_interrupt_time = 0;

struct payload_t {
  unsigned long ms;
  unsigned long counter;
};

//************* VOID SETUP BEINGS  ***************************************************************************
//**********************************************************************************************************

void setup() {
  sei();
  pinMode(RelayPIN, OUTPUT);
  pinMode(SwitchPIN, INPUT_PULLUP);
  digitalWrite(RelayPIN, HIGH);
  attachInterrupt(digitalPinToInterrupt(SwitchPIN), SwitchActivated, CHANGE);
  RelayState = 1;

  dat[0] = nodeID;
  dat[1] = 1;
  dat[2] = 0;
  dat[3] = 0;
  dat[4] = 0;
  dat[5] = 2;
  dat[6] = 0;
  dat[7] = 0;

  //nodeID = EEPROM.read(5);

  //EEPROM.write(5, 2);


  Serial.begin(115200);
  // EEPROMStatus();  Enable this to read the values of EEPROM memory using the Serial Monitor
  // Set the nodeID
  mesh.setNodeID(nodeID);


  // Connect to the mesh
  Serial.print(F("Node ID = "));
  Serial.println(nodeID);
  Serial.println(F("Connecting to the mesh..."));
  PrevSwitchState = digitalRead(SwitchPIN);

  mesh.begin();
  radio.setPALevel(RF24_PA_MAX);
}
//**********************INTERRUPT SERVICE ROUTINE*****************************************************************
//*****************************************************************************************************************

void SwitchActivated() {
  unsigned long interrupt_time = millis();
  int RelaySt = bitRead(PORTD, RelayPIN);

  if (interrupt_time - last_interrupt_time > 200) {
    if (RelaySt == 0) {
      digitalWrite(RelayPIN, HIGH);

    }
    else {
      digitalWrite(RelayPIN, LOW);

    }
  }
  last_interrupt_time = interrupt_time;
}
//************* VOID LOOP BEGINS ******************************************************************************
//*************************************************************************************************************

void loop() {

  Wireless();
}

//*************************************************************************************************************
//*************  WIRELESS FUNCTION  ***************************************************************************

void Wireless() {

  //**Prints current status in serial monitor
  SwitchState = digitalRead(SwitchPIN);
  RelayState = bitRead(PORTD, RelayPIN);
  

  mesh.update();
  // Only executes every second ******** Sends status to master node
  if (millis() - displayTimer >= 1000) {

  Serial.print(F("Switch is: "));
  Serial.print(SwitchState);
  Serial.print(F("  Previous Switch is: "));
  Serial.print(PrevSwitchState);
  Serial.print(F("  Relay is: "));
  Serial.println(RelayState);
    
    displayTimer = millis();

    if ( RelayState == 1) {
      dat[4] = 0;
      dat[5] = 2;
    }

    else {
      dat[4] = 0;
      dat[5] = 3;
    }

    // Send an 'S' type message
    if (!mesh.write(&dat, 'S', sizeof(dat))) {

      // If a write fails, check connectivity to the mesh network
      if ( ! mesh.checkConnection() ) {
        //refresh the network address
        Serial.println(F("Renewing Address"));
        mesh.renewAddress();
      } else {
        Serial.println(F("Send fail, Test OK"));
      }
    } else {
      Serial.print(F("Node ID = "));
      Serial.print(nodeID);
      Serial.print(F("  "));
      Serial.print(F("Send OK: ")); Serial.print(Translate());
      Serial.print(F("  Switch is: "));
      Serial.print(digitalRead(SwitchPIN));
      Serial.print(F("  Relay is: "));
      Serial.println(digitalRead(RelayPIN));
    }
  }

  // Checks for new information in the network****** this is done every loop
  while (network.available()) {
    myMessage = "";
    RF24NetworkHeader header;
    network.read(header, &recvd, sizeof(recvd));
    int sizeofmessage = sizeof(recvd);
    Serial.print(F("Received packet: "));
  
    myMessage.concat(recvd);
    Serial.println(myMessage);
    if (millis() - last_interrupt_time > 200) {
      if (myMessage == "P") {
        digitalWrite(RelayPIN, LOW);
        last_interrupt_time = millis();
        Serial.println(F("LED Prendido"));
      }
      else {
        digitalWrite(RelayPIN, HIGH);
        last_interrupt_time = millis();
        Serial.println(F("LED Apagado"));
      }
    }
  }
}


//***************************************************************************************************************************
//*********************  CONVERT STRING TO INT ******************************************************************************
String Translate() {

  String next = "";
  String tr = "";

  for (int i = 0; i < 8; i = i + 1) {

    tr = tr + int(dat[i]);
  }

  return tr;
}
// ************************************************************************************************************************
// *********************** VOID EEPROMStatus*******************************************************************************
// Prints all EEPROM memory values to the serial monitor

void EEPROMStatus() {

  for (int i = 0; i < 255 ; i = i + 1) {
    Serial.print(F("EEPROM Mem # "));
    Serial.print(i);
    Serial.print(F(" : "));
    Serial.println(EEPROM.read(i));
  }

}
// ************************************************************************************************************************
//************************RESET FUNCTION***********************************************************************************
void(* resetFunc) (void) = 0;


//************************CHANGE NODE ID FUNCTION **************************************************************************
//**************************************************************************************************************************
 void ChangeNodeID(int newNode){
  EEPROM.write(5,newNode);
  nodeID = newNode;
  resetFunc();
 }

Your circuit refers it Vcc. Is this Vin or 5v?

If fed into Vin, it then goes into another regulator and the voltage is reduced.

Weedpharma

Two other things spring to mind.

Transformer noise, and antenna interference there of.

If its a wall wart ..the cord may be causing inductance.. creating a magnetic field around your project.

Can you power it from a 9 volt battery ..clear of the computer usb port and the 110ac source.?

There is no common ground between your regulator and radio and the Arduino.

When I can't use the USB for debug prints I use an LCD. Post a schematic of the part of the circuit you are having trouble with.

Grumpy_Mike: There is no common ground between your regulator and radio and the Arduino.

Even better, the 7833 even has no GND...

septillion: Even better, the 7833 even has no GND...

I thought that was included in my statement but yes. That regulator can't possibly work and could damage the radio module wired like this. Surprised so many people missed that. Mind you the OP might say is is a mistake in the diagram but he wired it up correctly, we have heard that many times before.

Hi, thanks for your feedback and ideas. As said by Grumpy_Mike I just made a mistake in transcribing the diagram from paper to the computer (sorry I was tired and frustrated with this). This project works just fine using wireless, is just the switch that is giving me trouble... I'll try the 9V battery and see what happens. The transformer is one of the cheap 5V step down transformers sold on ebay.

I'll also get an LCD to see what's happening or I just realized that since the wireless is working I can send some info through it.

Thanks, will let you know what happens.

Do you know what a fail free way it to make the circuit digital? A photo ;) (Unless you decide to take it with a potato ::) )

If the transformer is really a step down converter, why draw it as a transformer? And why use a diode bridge? And worst, why use a 7805?

You keep referring to it as a "110v to 5v transformer" - most wall warts are actually stepdown transformers with a rectifier and regulator, but be aware that there are also wall warts that are simply step down transformers and the output is AC. There are also a whole selection of ones with DC output that are NOT regulated as well as some that do provide a regulated output. They are NOT interchangeable and hooking up a simple step down transformer (AC) to something that expects DC will let the magic smoke out.

I don't think anyone has asked him to measure the "transformer" output with NO LOAD yet. We need to know the output voltage with NOTHING connected to it.

but the switch is hit and miss...

...I don't believe code is the issue since it works just fine using the USB power.

If you think it's hardware you can test the hardware by writing a little test program that turns-on the pin-13 LED when the switch is on.

And if that works, you can try a similar little test program using an interrupt.

In your real program, you can add a little Blink LED loop (maybe blink the LED 3 times, etc.) at the beginning of your interrupt routine to check if you are ever getting there.

I've never used interrupts and I don't understand what you're trying to do, but the CHANGE mode with a switch seems odd to me.

Sorry for the confusion, I’m using the step down converter shown in the attached picture. It already provides regulated 5 VDC. I have measured it and it reads 4.98 V when connected to absolutely nothing and when I connect it to the circuit I still ready around 4.95 V. The 3.3 Volt regulator is actually a AMS1117-3.3 in a SOT-223 package. I use the interrupt with a change mode because the state of the relay can be changed either via wireless using the serial monitor or the switch. So when the switch is activated I just need to relay to change state, it doesn’t matter if the switch is up or down. This is supposed to be a remote control for pretty much any small 110 volt appliance and instead of using batteries I want to power it using the 110 volts from the outlet.

I’ll try to make a video and post it in YouTube to demonstrate the issue.

Thanks,

Interrupt isn't necessary for that but okay.

Although a picture can tell more then a 1000 words it's not telling us that much atm. All I can guess it's indeed a AC-DC switch mode converter. So it already output's 5VDC. So get rid of the diode bridge and 7805 and try again.

Hi,

I built the same circuit again using an arduino nano this time and the problem persists. In this new circuit I connect the 5V output of that step down converter directly to the 5V pin (and negative to gnd) of the nano and I'm using the onboard 3.3 V regulator to power the wireless module instead of the external 3.3 V regulator. The same thing happens: connected to USB it all works but connected to the external supply it works sometimes. Looking at the video I see a pattern I didn't see before, the switch works when moved in one direction but not the other.... it is only when the switch opens the connection to ground that the relay changes direction....

See in the video https://youtu.be/ddGZygiTrh4

I did measure output voltages and mentioned them in my previous post, the are very close the 5V (4.98 and 4.9).

As far the module being regulated, I just went by the description of the seller.

Step Down Module Condition: New With temperature protection, over current protection and short circuit protection, high and low voltage isolation, AC85 ~ 265 v wide voltage input, ac/dc current , 431 precision voltage stability DC5V output Input voltage: AC 85 ~ 265 v 50/60 hz or DC 100~ 370 v Imput current: 0.0273A(AC110V) 0.014A(AC220V) Input Inrush Current: 20A Output voltage: DC 5V (+ / - 0.2 V) Output current 700 mA Power 3.5 W Operating temperature -20~60 Relative humidity 40-90%RH Output 5V, min current 0a, max current 700mA, peak current: 800mA, output range: 4.8~5.2v, ripple wave: 60mV Output power:0-4W(DC current) Output efficiency: 80% Switch machine overshoot: MAX 10% Output voltage rise time: MAX 100MS Output over voltage: 4.8-5.2V, recovery:Lock, restart after recovery Output over power protection: yes,recovery:Lock, restart after recovery Short-circuit protection: yes, automatic recovery after problem solved Temperature protection: yes,recovery:Lock, restart after recovery Overcurrent protection: yes,recovery:Lock, restart after recovery Size: 3 x 2 x1.8cm

But then when I use the 110V to 5V transformer to power it, the wireless signal works fine, but the switch is hit and miss. I have pin 3 set as INPUT_PULLUP for now but I have also tried changing it to a regular INPUT and using a pull down resistor but the result is the same. Also worth mention it that I’m using it as an interrupt. I don’t believe code is the issue since it works just fine using the USB power. I have measured the output voltage after the 5V regulator and I get a very steady 5V. I have been trying to make this work for a few day without any luck. I’m fairly sure that I can’t connect it to the computer using the usb when I have it powered using the transformer so I can’t really do much troubleshooting on that front. Any ideas? Thanks,

Please clarify whether or not you have tested the relay without software to verify that the hardware is fine. We need to know if this post is simply requesting software help or if you have a hardware issue.
Your ac/dc converter is a switchmode regulated converter. I don’t know if your code is ok but we can rule it out if you manually turn on the relay using a jumper.
Please post a link for the relay.

Yes, i have tested the hardware, the relay works fine. Here is a link for the ebay page where I got it.

Link for the Relay

Also everything (including the relay)works just as it is supposed to when connected to the usb power. So most likely not a software issue.

When I connect it to the wall using the step down converter most everything works fine. I can communicate with the Arduino using the NRF2401+ and the relay activates using that part of the program. The only problem is with the switch and only when I use the stepdown converter.

I made a small video showing it.

Video

If I need to measure something specific please let me know and I'll get it done.

Thanks all,

you need to post a drawing or explain how your switch is wired. What components comprise the "switch" part of the circuit. I'm afraid the video doesn't tell us anything you haven't already told us. On the forum we often use closeup photos of a circuit if needed but the most useful thing is a hand drawn schematic of the relevant part of the circuit.

Not a problem. Here is a diagram of the connections. I tried with connectors and then used a proto shield and soldered the connections to see if that made a difference but it didn’t. Since I had two of everything, I built a second unit to discard hardware issues. The only difference is that the first one is using Arduino pro mini and the second one Arduino nano.

They both behave the same.

S/W is not my area of expertise but that being said, if you are testing it with the 5V ac/dc adaptor, which by the way , is universally referred to as a 'wall wart' , I would comment out ALL serial prints because you have no serial connection. Also, I don't see any switch debouncing either hardware or software. Also, I would not use a toggle switch for a push button application . Take a look at this.. If you are unable to resolve this issue I would suggest adding an LCD solely for the purpose of reading debug serial prints to figure out what is happening.