xplained-mini with relay module

Go To Last Post
31 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I found myself an xplained-mini board and am trying to use it to control a relay module (the keyes-sr1y).

So I connected the relay module in about the same way as I saw in most arduino examples, expecting it to work the same. 

Like this:

Now the problem is that the voltage on PD1 drops to around 2.4V whenever the module is connected, instead of the 5V that it is supposed to give. Does anyone know what the cause of this is, and how to solve this problem?

Thanks in advance

This topic has a solution.
Last Edited: Tue. Apr 6, 2021 - 04:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn’t PD1 a USART pin?

 

jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks

 

bamischijf wrote:
PD1 drops to around 2.4V whenever the module is connected

What current does the module take? sounds like it's too much.

 

Do you actually have code in the AVR to drive PD1 high?

 

Please post a link to the module you are using.

 

Would also be good to know which AVR you are using - there are several different "Xplained-mini" boards

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I couldn't find how much current the module needs since there is almost no info on this module. This is the most I could find: link to the module

Here is the code that im using to test it.

void relayInit()
{
	DDRD &=  ~(1<<1); //set pinD1 as output
	PORTD &= ~(1<<1); //set portD1 off
}

int main(void)
{
    relayInit();

    //start loop
    while (1)
    {
	_delay_ms(2000);
	PORTD |= (1<<PORTD1);

	_delay_ms(2000);
	PORTD &= ~(1<<PORTD1);
    }
}

I'm using the ATmega328P Xplained mini.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


bamischijf wrote:

I couldn't find how much current the module needs since there is almost no info on this module. This is the most I could find: link to the module

 

Oh boy...

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


bamischijf wrote:
This is the most I could find: link to the module 

that shows that it includes a driver transistor:

So that should be OK - assuming that this really is the module that you have ...

 

 

I'm using the ATmega328P Xplained mini.

As Jim said, PD1 is used by the Virtual COM Port (VCP) connection to the PC:

 

 

Better to choose another pin - so that you know there's no conflicts

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seriously... wrong.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That driver transistor configuration does not look right.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That schematic has the transistor in backwards, ie. E and C are reversed! Hope its a drawing error and not an as built error!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So i just switched the signal pin from PD1 to PB1 but it still has the same issue. I tried to connect the signal pin directly to the 5V pin as well, which does make it turn on fully. I'm guessing that pin can give more current or something?

 

Also could the transistor being in the wrong way cause the voltage to drop or can that cause other problems?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you post a picture of your setup?  a port pin should be able to supply the 20ma's needed to operate your relay, so something else is the problem.

Do you have a VOM that you can use to measure the needed relay current?

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bamischijf wrote:

 

void relayInit()
{
	DDRD &=  ~(1<<1); //set pinD1 as output
	PORTD &= ~(1<<1); //set portD1 off
}


 

You sure about that?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The XPlained Mini can be set to 5V or 3V - are you sure you have it correct?

 

 i just switched the signal pin from PD1 to PB1 

and you're sure you updated the code to match, built it successfully, and downloaded it to the board?

 

 

I don't see an F_CPU setting in your code - so are you sure that the delays are actually what you think?

 

See Tip #3 in my signature, below:

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here is my setup with the S pin switched to PB1. usb connected to my laptop. as you can see the led blinks, but is not nearly as bright as when S is connected directly to the 5V and it doesn't activate the relay.

I think by VOM you mean like a multimeter that measures voltage, current and resistance. I do have one yea, but i can't seem to find out how to measure the amps correctly...

 

I'm certain the xplained mini is set to 5V since it measures ~5V on the multimeter from PB1 to ground when the module isn't connected.

 

Also the F_CPU is set to 16000000 on the first line of the code, followed by #include <avr/io.h> and #include <util/delay.h>, sorry for not adding that one.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bamischijf wrote:
I think by VOM you mean like a multimeter that measures voltage, current and resistance. I do have one yea, but i can't seem to find out how to measure the amps correctly...

 

nvm, used a 10ohm resistor inbetween the S and the Xplained mini and measured the voltage over it.

when connected to the 5V it measures 1.704V, and when connected to PB1 it measures 0.033V. So 170mA vs 33mA. I don't know if that helps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

bamischijf wrote:
it measures 0.033V. So 170mA vs 33mA. I don't know if that helps.

Yes very helpful, you relay draws too much current to be controlled directly from a port pin!

Either select a different relay module or add a p-fet driver to handle the needed current for this relay module.

 

Jim

 

typical circuit, any AVR can be used: Pulling the gate low will turn on the  fet

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Tue. Apr 6, 2021 - 03:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Something is very wrong with those current measurements. The S line has a 150R resistor in series with an LED and the base of the transistor. The current should not exceed 18mA even when connected directly to 5V.

 

Also, you still haven't addressed the software issue I pointed out above.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unless it needs to be something else than an output, i don't see what the problem could be with that part of the code?

 

Also do you mean something is wrong with how i measured it, or just that those values wouldnt make sense normally?

(ps sorry for my poor paint skills)

 

Last Edited: Tue. Apr 6, 2021 - 03:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alright I will look into this Jim, thanks!

Last Edited: Tue. Apr 6, 2021 - 03:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am looking at the datasheet for that relay module and I am having a hard time accepting that schematic as viable.  An NPN transistor switching ground from the collector is just not possible with the Emitter tied through a relay to +5.

 

Theres something VERY wrong with that device.

 

I pulled the datasheet on that relay:

 

https://datasheetspdf.com/pdf-fi...

 

And that relay draws about 72 milliamps all by itself.  If the OP is using a low power USB port that maxes out at 100MA the OP is on teh border of overloading the USB port to begin with.  Even worse if its a crappy computer where teh power capability of the USB would be questionable.

 

Right Side Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

bamischijf wrote:

Unless it needs to be something else than an output, i don't see what the problem could be with that part of the code?

 

This is hard work! What are you setting the relevant DDR bit to with the code you posted?

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Tue. Apr 6, 2021 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

I am looking at the datasheet for that relay module and I am having a hard time accepting that schematic as viable.  An NPN transistor switching ground from the collector is just not possible with the Emitter tied through a relay to +5. Theres something VERY wrong with that device.

 

Indeed. The OP's current measurement do not make sense.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

An NPN transistor switching ground from the collector is just not possible with the Emitter tied through a relay to +5.

 

It'll do something but not very well. Vcesat (Vecsat?) will not be very impressive.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
It'll do something but not very well.

 

If at all?  Since teh Base needs to be .6v higher than the emitter to turn on then the voltage at the trigger will need to be much higher than +5v to turn on teh LED and the transistor.  And then the Emitter will never be at the collector ground potential either.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 

bamischijf wrote:
a multimeter that measures voltage, current and resistance. I do have one yea, but i can't seem to find out how to measure the amps correctly...

Do you mean you're not sure how to take a current reading with any meter, or you just can't work out how to set that particular meter into "current" mode?

 

The general approach is to put the meter in series with what you're measuring:

 

https://electronicsclub.info/meters.htm#ammeters

 

 

EDIT

 

Use an image which renders properly

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Apr 6, 2021 - 04:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

 

bamischijf wrote:

Unless it needs to be something else than an output, i don't see what the problem could be with that part of the code?

 

This is hard work! What are you setting the relevant DDR bit to with the code you posted?

 

 

I get now what you're trying to say and i appologise to everyone here.

looked over that small piece of code a lot of times trying to find out what you were trying to say but didnt look at the operator

turns out i set the port to input instead of output...

changing this made it work as expected.

 

this probably attributes to the weird measurements as well.

Last Edited: Tue. Apr 6, 2021 - 05:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

 

 

bamischijf wrote:
a multimeter that measures voltage, current and resistance. I do have one yea, but i can't seem to find out how to measure the amps correctly...

Do you mean you're not sure how to take a current reading with any meter, or you just can't work out how to set that particular meter into "current" mode?

 

The general approach is to put the meter in series with what you're measuring:

 

https://electronicsclub.info/meters.htm#ammeters

 

 

EDIT

 

Use an image which renders properly

 

I meant how to get this particular meter that i just got into current mode yea, but i found that one just now as well.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bamischijf wrote:
turns out i set the port to input instead of output...

 

YEs, but from looking at only the hardware(and the datasheet for the relay module) teh circuit does not appear to be proper either.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

bamischijf wrote:
turns out i set the port to input instead of output...

 

YEs, but from looking at only the hardware(and the datasheet for the relay module) teh circuit does not appear to be proper either.

 

Jim

 

I think you were right when mentioning that they drew the schematic wrong, since another source for the same module has the transistor flipped.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bamischijf wrote:
I think you were right when mentioning that they drew the schematic wrong, since another source for the same module has the transistor flipped.

 

Thats more like it!

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bamischijf wrote:
I think you were right when mentioning that they drew the schematic wrong, since another source for the same module has the transistor flipped.

That's the problem with the internet, once it's out there, it's hard to rain it back in!

 

Glad your project is working for you now, hope the freaks were of help!

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"