Need a code because I'm a very newbie in arduino programming

I have an arduino mega 2560, 18 relays (2 boards of 8 relay and 1 board of 2 relay) and a bluetooth module HC-05. I want to on and off the every relay from bluetooth also i do want to know how can i connect 18 relays to my arduino, somebody help me please :slight_smile:

Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial

What relay boards? How do you intend to use Bluetooth?

Hi @haydeez
I am afraid you have chosen a too complex project to begin with. Do not immediately try to connect all 18 relays. Even an experienced programmer never does this.
Move gradually. There are many projects in the net with connecting one relay to arduino. Start with one two-relay module, connect it to the arduino Mega, learn how to turn them on and off. Get them to work stably. After that, you can connect the bluetooth and try to control your relays by radio.

Waiting for someone to give you a code is not worth it. It's not in the tradition of the community.

First aid is reading this link and reply with updated information: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum


everything's is in the picture please guide me how can i connect every relay to the arduino

First learn how to connect one relay and control it.

Your favorite search engine and the phrase "arduino relay" will find tutorials.

The perfect question, and best place to start.

You need to sketch out with your best pen and paper a diagram of how the pieces will be wired together - including your power supplies or battery.

PLEASE DON’T USE FRITZING DRAWINGS

This will indicate the pin numbers and possibly the signal names you’ll give to those functions.

This will teach you some valuable lessons in planning and starting ANY project.

Try to keep the diagram simple, with the logic and signals flowing from the left (sources), across to the right (output devices)… in your case relays.
Often designers try to keep higher voltages at the top, and lower /ground potential toward the bottom of the diagram.

Once you know ‘what’s’ connected to ‘where’, it’s almost trivial to get the basic code working.

You will need another power supply for the relay coils. The Mega cannot power relay coils.

What wil be sending data through the Bluetooth? The serial input basics tutorial has good information receiving and parsing serial data.

I agree start off with something simple like working with an lcd screen.

You can have a look at Trouble with Relay Module - #5 by LarryD how to wire your relay boards.

Robin's serial input basics was already mentioned; change it to use Serial1. Connect your HC05 to serial 1 so it does not interfere with upload and USB (serial) is available for debugging.

I politely disagree.

That's not really useful. Controlling a LED via serial might be more useful.

Hello haydeez

Did you connect the BT module already?
Did you can receive and transmit information via BT?

I'd just start with the two relay module and get them each turning something on and off at intervals.

What are you ultimately planning to control with the full set?

this is for the school project my team made an entire school model and my work is to control the lights of the model with bluetooth. i have a basic knowledge of arduino and i do know how to turn on and off the lights with bluetooth (control from my android). I just want to know how can i connect these boards to arduino, i only know about 8 relay board which can i connect, upload code, and successfully turn on and off the relays

I already know about switching on and off the relays with bluetooth, i want to know how can i make the relays go in stream in code for example: "if i turn on the only 1 switch from my android, the relays will turn on one by one and the previous relay will be turned off when the next relay turned on" i hope you got my point

Then please post your code and wiring diagram for that. Then it will be possible for people to offer specific advice about your control question.

and

i want to know how can i make the relays go in stream in code for example: "

are a contradiction.

What are you really doing over there? Please show us what you have done already.

I closed the IDE again, assuming this was just a wiring issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.