Hi,
I've got a problem with my Mega three Mega Boards.
I want to use a ULN2003A to switch some relays.
The ULN is working perfect, I tested with 5V at the input pins of the ULN.
The current is 1.6mA
If I connect the pin53 etc. to the ULN and set digitalwrite high I can measure 1V.
If I disconnect the Mega and measure again I see 4.8V.
So the ULN works and the Mega can switch to 4,8V high.
But why is the voltage dropping when they are connected?
1,6mA ist not a too high current for the Mega.
Any idea?
Please show a schematic. Either CAD or a photo / scan of a handdrawn one.
We have no idea how you connected it.
I have no schematic, I do such things by my own ideas.
Arduino Pin53 > ULN Pin1
Arduino Pin51 > ULN Pin2
ULN Pin8 GND
ULN Pin9 12V, same as Relay
I measure 10k input resistance Pin1 & Pin2
I tried 1k resistor between Arduino Pin and ULN Pin
pinmode ist set to output
digtilwrite is high
It seems that my Megas can switch from low to high but 1.6mA is a too high current the the voltage drops.
But in the manuals ther is a current of 40mA alluwed!?
connect are:
USB port for serial communication / test with 12V PS failed also
7 digital pins to the ULN
6 analog pins to measure (are working fine)
Solution found!
I do it like in the documentation
I Void setup I placed the pinmode and in the loop the digitalwrite.
digitalwrite high seems to activate the internal pull up resisrors und overwrite pinmode.
Now I set the pinmode after the digitalwrite and I got 5V.
It does not overwrite pinMode. It does activate the internal pull-up only if the pin is configured as input, not when it is configured as output. That does not mean that it changes the pinMode to INPUT_PULLUP if the pinMode was OUTPUT.
You can look at figure 13-2 in the 2560 datasheet and match it to the digitalWrite function. Below taken from
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
uint8_t oldSREG = SREG;
cli();
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
SREG = oldSREG;
}
digitalWrite only modifies one register (Port).
You can find pinMode in the same file; pinMode modifes two registers (DataDirection and Port).