r/AskElectronics • • 7d ago

Omron E6B2 Encoder + External Power Supply: why did I fry my Arduino UNO?

I have a Chinese Omron E6B2-CWZ6C NPN open-collector rotary encoder. Although the datasheet specifies a supply voltage range of 5–24 VDC, in reality, the encoder only starts working at around 5.5 V. So I uesed an external 5.5 V power supply connected to the brown (+) and blue (GND) wires, with pull-up resistors (2k Ohm) on the A (black), B (white), and Z (orange) signal outputs.

When measuring the signals with an oscilloscope (no arduino connected and manually rotating the encoder), I get a square wave ranging from 0 V to approximately 3.5 V (the probe/measurement points are indicated by the red circles in the tinkercad image near the resistence).
However, when I connected the outputs to Arduino pins D2 (A), D3 (B), and D4 (Z), I measured up to 10 V. I assumed the voltage was higher because the power supply and the Arduino did not share a common ground. I decided to connect the Arduino GND to the power supply GND, which ended up frying my Arduino ...

How can I interface the Omron encoder with an Arduino using an external power supply? And why did I fry my Arduino?

I'm a beginner any help would be greatly appreciated

1 Upvotes

37 comments sorted by

2

u/NBC-Hotline-1975 7d ago edited 7d ago

I see three obvious problems.

  1. You need a common ground between the encoder ground and the Arduino ground.
  2. Your three resistors as shown are pull-DOWN to the encoder ground. This makes no sense. You do NOT need pull-down resistors at all.
  3. The three resistors should be wired as pull-UP to the Arduino logic voltage (NOT to the encoder supply voltage).

1

u/Dabaduck 7d ago

As I already mentioned in the post and in the other comments, I ALREADY connected the Arduino GND and the power supply GND together, but this caused the wire to burn out and damaged the Arduino. Perhaps, as someone suggested in another comment, this was due to a ground loop generating 11.82 VDC between the two GND connections.

I'm going to try again using a single power supply, but I would like to know whether the circuit is correct. When you mention pull-up resistors, do you mean connections like the ones shown in this picture (ignore voltages and resistors values)?

1

u/NBC-Hotline-1975 6d ago

Yes, that wiring looks correct now.

You should be able to connect the negative leads from both power supplies together. You can try this BEFORE the Arduino and the encoder are connected. If you can't connect the power supply negative leads together, without sparks or heat, then something is wrong with one (or both) of the power supplies, and you need to remedy that before you proceed. You should in fact be able to test the circuit using an actual 9v battery, as you have shown.

1

u/Dabaduck 6d ago

Thanks for your reply. Just one last question: why should pull-up resistors be used instead of pull-down resistors in this case? With the pull-down configuration, I could still see a square wave on the oscilloscope. Was the signal simply inverted?

1

u/NBC-Hotline-1975 6d ago

The encoders have NPN open collector outputs. So the output will be either open or 0.2 volts (essentially "zero" logic level). If you want a logical "one" level, you need to pull the output up to Vcc.

1

u/Dabaduck 6d ago

Okay, I understand what you mean now, but then how come I was able to see a square wave on the oscilloscope?

When the main circuit activated the base, the collector and emitter were connected, allowing current to flow towards the blue wire (GND).

When the transistor was OFF, was the voltage I was measuring actually coming from the lower branch of the internal circuit, passing through the Zener diode (?), and eventually reaching my oscilloscope ? (The pull-down in the figure near "black white orange" label is added by me)

Technically, apart from getting an inverted signal, would that configuration have worked?

Sorry for bombarding you with questions, but I'd really like to take this opportunity to understand how it works and learn something new.

1

u/NBC-Hotline-1975 6d ago edited 6d ago

You may have been seeing leakage through the output transistor. You may have just seen capacitive leakage within the encoder. Did you have the encoder shield grounded? Remember an oscilloscope usually has 1 Mohm input impedance. Where was the scope ground connected?

No, that configuration would not have worked. Even if you had the two grounds connected (which is an absolute requirement) it would not have worked. Without a pullup resistor, the voltage at the arduino input would not have been high enough to register as a solid "high" level.

Consider the output transistor as a switch. If it's on, then the output is essentially at ground. If it's off, the output is at an indeterminate state. The arduino doesn't want to see an indeterminate state ... it wants to see either ground or Vcc. The only way it can see Vcc is if you have a pull-up resistor.

1

u/Dabaduck 6d ago

The shield was not connected to GND (floating), while the oscilloscope probe's ground clip was connected to the external power supply's GND (same GND of the encoder).

As I mentioned in another comment where I posted the code, the Arduino was actually able to detect the encoder pulses (I think) correctly: the count increased when I manually rotated the encoder in one direction and decreased when I rotated it in the opposite direction.

With the oscilloscope, I was measuring a clean square wave of around 10 V when the Arduino was connected, whereas the signal was around 3.5 V when the Arduino was disconnected (like in the picture of the post).

I therefore assumed that the voltage 10v could have damaged the arduino's input and that difference was caused by the grounds not being shared. So I tried connecting the two GNDs together, but that ended up burning the wire and frying the Arduino (lol).

However, in a way, the original configuration was actually working that is why asked you what I was seeing on the scope

1

u/NBC-Hotline-1975 6d ago

Do you now understand what was wrong?

Do you want me to repeat everything I have already said?

1

u/Dabaduck 6d ago

I appreciate your time, but calm down I was not being rude. Knowing which circuit is correct is not the same as knowing how to explain why an incorrect circuit appears to work. I understand that you mean the oscilloscope was showing a clean waveform, but that doesn't necessarily mean there was enough current. The fact remains that the Arduino was detecting it consistently, and it's very unlikely that what I was seeing was just leakage current or noise...

→ More replies

1

u/SoManyDeads 7d ago edited 7d ago

How are you powering the arduino? Is it plugged into the wall?
Judging by how you set up the drawing, I believe this to be what you have done. You may have two separate power sources but the grounds can be completely different can make things be very bad. You can try something similar and make a simple votage divider from 5.5 -> 3.5 to power the Arduino. This should give a common supply and perhaps fix the issue.

1

u/Dabaduck 7d ago

Thanks for the reply.
I powered the Arduino via USB. So, assuming I power the Arduino through the Vin and GND pins using the same external power supply, should the circuit shown above work?

1

u/SoManyDeads 7d ago edited 7d ago

I don't see why not, as long as the GPIO pins are configured correctly. You may have to program the board first, then move over the cabling to be sure everything is working. But this should at least deal with the issue of too much voltage at certain locations.

It's been a while since I have used two different power supplies in the same system, but you may be able to just connect the gnd pin to the negative rail on the breadboard and that may work as well. For testing purposes I would suggest removing the connections to the arduino GPIO though.

Edit: The main issue is that the ground reference points are floating in relation to one another in the original setup.

Also make sure what voltage Vin requests as that will impact a voltage divider for config 1. It looks to be 7-12 volts which may be an issue, there is a different uno which has lower requirements so verify with the documentation.
https://docs.arduino.cc/learn/electronics/power-pins/#vin-pin

1

u/Dabaduck 7d ago

This is the code I tried before connecting the common GND. The program seemed to work correctly, but I measured approximately 10 V on the oscilloscope with the oscilloscope's ground clip on the external power supply GND. After that i tried to connect the Arduino GND to the external power supply GND on the breadboard,as you said, but the Arduino board stopped working.

Could the problem have been caused by the voltage difference between the two power supplies (USB and external power supply), or was there something wrong with my wiring? I'll order another Arduino and try again using a voltage divider and a unified power supply. However, before connecting everything again, I'd like to make sure that the rest of my circuit and wiring are correct.
I'm not an expert, but I'll try to read your link and see if I might have created a ground loop.

#include <Arduino.h>


#define ENCODER_CHANNEL_A 2
#define ENCODER_CHANNEL_B 3
#define INDEX_PULSE 4


volatile long position = 0;


void channelAInterrupt() {
  if (digitalRead(ENCODER_CHANNEL_B) == HIGH)
    position++;
  else
    position--;
}


void channelBInterrupt() {
  if (digitalRead(ENCODER_CHANNEL_A) == HIGH)
    position--;
  else
    position++;
}


void setup() {
  Serial.begin(115200);


  pinMode(ENCODER_CHANNEL_A, INPUT);
  pinMode(ENCODER_CHANNEL_B, INPUT);
  pinMode(INDEX_PULSE, INPUT);


  attachInterrupt(digitalPinToInterrupt(ENCODER_CHANNEL_A), channelAInterrupt, RISING);
  attachInterrupt(digitalPinToInterrupt(ENCODER_CHANNEL_B), channelBInterrupt, RISING);
}


void loop() {


  static bool previousIndexState = HIGH;
  bool currentIndexState = digitalRead(INDEX_PULSE);


  if (previousIndexState == HIGH && currentIndexState == LOW) {
    Serial.print("Index pulse - Position: ");
    Serial.println(position);
  }


  previousIndexState = currentIndexState;


  static unsigned long lastTimestamp = 0;


  if (millis() - lastTimestamp >= 200) {
    lastTimestamp = millis();


    noInterrupts();
    long currentPosition = position;
    interrupts();


    Serial.print("Position: ");
    Serial.println(currentPosition);
  }
}

1

u/SoManyDeads 7d ago

Program pins seem to be setup correctly in the code.

I will try and explain why two power supplies could be a problem in a different way. You have a 5.5V source going into OMRON and a 7-12V source going into the Arduino.

The pins on the arduino are expecting a MAX of 3.5V with respect to it's own ground, but it is being supplied by 3.5V from the external power supply. When it translates that voltage to it's own reference the result will be consistently wrong. To fix the expected voltage issue a common to tie the grounds together to provide a common relation between the two sources. This can throw in control issues though as was reference about grounding loops as below. I am not sure if you will encounter this as your sources would be not that far off from one another, but hey I can be wrong.

The only suggestion I would have for attempt 2 would be to make sure that only one power source is connected at a single time.

I would do things for the setup in stages to confirm operation, first would be to set up the Arduino with the Vin powering it from external supply. Then the voltage divider for the 5.5v to power the OMRON. Then setup the omron outputs so the oscilloscope can read the expected outputs, then connect it to the inputs. That should minimize the possibility of damaging anything.

A second thought would be using the power from the Vin pin and voltage dividing that to be used by the omron. Not sure how critical using that specific external power supply is.

1

u/Dabaduck 7d ago edited 7d ago

I think you are on the right way. I measured the potential difference between the Arduino's GND (it's half-dead, as I can't upload code to it anymore), powered via USB, and the external power supply's GND, and got a reading of 11.82 V.

I think I may have actually created a short circuit due to a ground loop (?) .

What I can't quite wrap my head around, now that I've been thinking about it, is why different devices should share the same common reference point in the first place? In my case, this would imply that both the GND of my PC's USB port and the GND of the external power supply are connected to the mains neutral right? (but it's clearly not)

Edit: Maybe both the PC and the external power supply use galvanically isolated switching power supplies, and therefore they do not share the same ground reference

1

u/NBC-Hotline-1975 7d ago

"this would imply that both the GND of my PC's USB port and the GND of the external power supply are connected to the mains neutral right?"

Wrong! Nothing on the low voltage side should be connected to the mains neutral. However, depending on the design of the power supply, it might be connected to the mains ground. And if it's a switching supply, and is NOT intentionally connected to ground, then capacitive coupling might put it at any arbitrary voltage relative to ground. So if you have two random supplies, the first supply negative might be negative, the same, or positive, relative to the second supply negative. So when using separate supplies (as your circuit does) you MUST tie the grounds together. Also, without a common ground, there is no way for the encoder output current to find its way back to the Arduino.

1

u/Dabaduck 7d ago

Again, I connected the two GNDs together, but this caused the wire connecting them to burn out and damaged the Arduino.

1

u/NBC-Hotline-1975 6d ago

Then one (or both) of the supplies has a problem, and/or is not suitable for use with this circuit. You should be able to connect the negative terminal of the two supplies together ... without arduino, without encoder, without anything else ... and have no problems. If you connect just the supply negative terminals together, and there is a spark,or heat, or any current, then something is defective.

Perhaps a better solution would be to use a single supply e.g. 9 volts (for the sake of the encoder), and use a series linear regulator to reduce that to a lower voltage for the arduino.

I am also curious why you say the encoder doesn't work correctly until you reach at least 5.5 volts. The specifications clearly say it will work with 5.0 volts.

1

u/Dabaduck 6d ago

Sorry, I missed this comment. I tried connecting the encoder to the Arduino using its own power supply (a setup I saw on YouTube), but it didn't work. In the AliExpress reviews, I noticed that many people said it needed a voltage higher than 5V, and sure enough, that worked for at least seeing something on the scope.

→ More replies

1

u/SoManyDeads 7d ago

Voltages are a potential difference between two points. For example a battery can be simplified to the idea of a very slowly discharging capacitor. It's voltage is a reference between the positive and negative terminals. wall power is with reference to it's terminals as well. The issue can be what you are connecting. Two batteries will probably never be an issue with their grounds connected, and this is normally what I have seen used in the past for what I have used. Wall power that is being translated can carry more issues as it might already be with reference to something, and connecting two different sources could cause issues as they are referenced to something static, unlike a batter where it references itself. I think that is most likely what happened here but I am not sure what your other source is.

Some controllers could use a Vref/Common for outputs to isolate itself, but I am not sure if the arduino has that option available.

2

u/SoManyDeads 7d ago

Additional information about grounding multiple power supplies.
https://ps-electro.com/a-practical-guide-to-preventing-ground-loops/

1

u/nixiebunny 7d ago

You forgot to connect encoder Gnd to Arduino Gnd. This is essential.