How To calculate resistor value

Hi all,

I have small problem, i’m no electronics engineer and i want to calculate (if needed, I don’t realy know)
a resistor value for a schematic.

I received a schematic for a circuit containing some photocells that work on 12volt, they are NPN Normaly Open photocells, i have photocells that are 5volts.

Both type of photocells give a low signal (0 volt) when the beam is broken and a high (aprox 5volt) when there is no obstruction in front of the beams.

in the schematic (see below) i received, my friend uses a BC557 PNP transistor and a few resistors to:

  1. change the signal from LOW to HIGH if the beam is broken
  2. go from a 12v signal to a 5v signal when the beam is obstructed by anything

my question is :
how can I adapt the circuit so it works with my configuration of 5volt NPN NO photocells.

I see a 2k2 resistor, a 1k and a 4k7 resistor on his circuit.

can someone explain what these resistors do (i thought they are some kind of voltage devider, to go from 12v to 5v, but i’m not sure of that)

I also see a resistor going from the 5volt feed to the 2k2 resistor, and then one 4k7 resistor from one of the pins of the BC557 to the GND connection, and a wire to go to the PIN of the arduino

I’m eager to learn some new stuff on electronics, so i would greatly appreciate some tips & tricks or even some schematic of how to deal with this issue

another question is, how can i recognize the appropriate pins on this type of transistor? E B C?


Please post a link to the product page or data sheet for your "photocells" (there are many types).

You should not need anything other than a single resistor to use a "photocell" with an Arduino.

Hi jremington,

this is the product number, they're from
my version is specially made to give (and work on 5 volts) - it's a 3 wire type, that gives a 0volts on activation (LOW)
I need to change the LOW (0 volts) signal to a HIGH (5 volts) signal to work correct with my friends code i received...
DC 10-30V

link to manufacturer


It is much easier to change the code so that it works with a LOW instead of HIGH, than to add external circuitry.

Please read "How to use this forum" and then post the code properly, using code tags.

Hi jremington,

it is not that simple by just changing the code, there are multiple library's involved (user made library's - typically for the tasks, designed for the sensors)

my simple question was how to calculate, if needed, the resistor value's for this schematic...

i much appreciate your input, but why invent "the wheel" allover again, and learn nothing about some basic electronics, and just do it by code...

i have a similar system of my own making, but it lacks some features that my friends system has, i did my thing with LOW's instead of HIGH's, but the new code is much more complicated and designed to be more "errorproof"


@YvesD, do not cross-post.

@YvesD, do not hijack.

OK !
sorry :-[

is it hijacking if the subject is “Using PNP transistors” ??


is it hijacking if the subject is "Using PNP transistors" ??

Your question is roughly equivalent to, "Is it hijacking if the subject is Arduino Uno?"

The answer should now be self evident.

OK Coding Badly,

sorry in that case, seen that you removed the cross-posting, thanks for that (did not know how to remove it myself :frowning: )

is my question for the "resistor value's" at the right forum then (general electronics) ?
or should i look for a more specific forum??



did not know how to remove it myself

Users are not allowed to delete posts & topics, only moderators can do that. Generally just spam that sneaks thru, or crosspost/duplicate posts.
Not deleting prevents situations where an entire discussion is lost (I don't want my time researching an answer that might benefit others as well deleted because you got your answer for example), or the original post is lost and all that remains is answers discussing a non-existent question that look off.

it is not that simple by just changing the code

I simply DO NOT believe that. The sensor is either ON or OFF. Why would anyone need "multiple libraries" to read it?

The schematic appears to have been created by someone who does not know what he/she is doing, and the circuit's purpose is unclear.

I simply DO NOT believe that. The sensor is either ON or OFF. Why would anyone need "multiple libraries" to read it?

You're right about the photocells being ON or OFF, the library is made to handle the events that are invoked by an ISR reading a HIGH state of the sensor (in fact a LOW state being switched to a HIGH state by the hardware in the schematic)
The ISR is set to work on both sides ( on CHANGE) so the whole set of library's should be remodelled to work with the LOW state (if a object passes the beam)
there are multiple library's working on a detected HIGH state's of PINS 2 & 3.

If i would like to change all of these files, i'm on my way for months (i'm not a programmer expert in C++ 11, in fact i'm not a professional programmer at all :slight_smile: )

On the other side, my friend is a professional programmer, and has had backup from senior programmers in his compagny, and tips & tricks from electronic engineers... i don't have friends in that range of enginering :frowning:

I like trying to "learn things" a lot, even if it's difficult for me :slight_smile:

so my initial question on this general electronics" forum was how to calculate resistor value's for using a BC557 PNP transistor in the mentioned schematic, it works perfectly for my friends code and hardware (hardware that is on a 12v basis for the photocells, where my identical type of photocells are on just 5 volts)
His photocells give a zero voltage when the beam is broken, and a 12 volts on the output line if nothing is in front, mine give 5 volts when nothing is in front, that's initialy the only difference...

If your sensor outputs 5 V then all you need to do is change how the sensor state is read and then interpreted.

Wherever you see a line that is reading the sensor, for example:

SensorState = digitalRead(SensorPin);

add a “!” as follows.

SensorState = !digitalRead(SensorPin);

That change inverts the logic.

It should be obvious what to do in this case:

 if (digitalRead(SensorPin) == HIGH) {

Hi All,

in attachment, the mentioned library’s (and the .ino file)

there are other library’s invoked in the project, but at this stage they are not relevant (LCD & Lights library)

I tried with placing some " ! "'s in the racehandler.cpp, but didn’t get it to work.

my friend has no time at this moment to help me out, and he lives not nextdoor to me also :frowning:


FlyballETS-Software.ino (11.9 KB)

RaceHandler.cpp (30.8 KB)

RaceHandler.h (2.44 KB)