Friday, April 28, 2017

Controlling relays with the Arduino

Today we are learning how to control relays with a microcontroller, using an Arduino. In this easy project we will program an Arduino board to switch On or Off any device you want, for example, an electrical appliance like a lamp, a heater or a fan. This is a simple but useful project, perfect if you are new to Arduino. Some knowledge of electronics and programming is a plus, but anyone can succeed in the Arduino world. So, what's an Arduino?

The Arduino platform
Arduino is an open-source electronics platform based on cheap but powerful and easy-to-use hardware and software. Arduino designs and manufactures microcontroller kits distributed as open-source hardware and software, permitting the manufacture of Arduino boards and distribution of the software by anyone. Being an easy tool for learning and fast prototyping, Arduino quickly gained success and has been used in thousands of different projects and applications by both beginners and advanced users.

To program the boards the Arduino project provides an IDE (integrated development environment), which includes a code editor, compiler and debugger. Arduino uses a custom programming language that is very similar to C and C++.

Arduino boards
There are several Arduino boards available, using mainly ATMEL and ARM processors. They vary in processing power, capabilities and  size. Usually Arduino boards are used together with other electronic devices like sensors, switches, displays, etc. These are manufactured in such a way as to easily connect with the Arduino boards. Many expansion shields are also available.

Arduino UNO, MEGA 2560, Nano and Lilypad
Popular Arduino boards (UNO, Nano, Mega 2560 and Lilypad).

Arduino relay control project
This project consists on controlling a relay with an Arduino board and a button switch. Once the board is programmed, pressing the button switch will turn the relay to the On or Off state, switching on or off whatever device is controlled by the relay. I will be using an Arduino UNO, but other Arduino boards (Nano, Leonardo, MEGA, etc) can be used.

Arduino relay control interconnects

Relay, button and resistor
Hardware parts:
1x Arduino UNO board
1x Relay module (5V)
1x tactile button switch
1x 10KOhm resistor
Breadboard
Breadboard jumper wires

Notes:
This project uses a relay module that can be directly interfaced by an Arduino board. The relay used is not critical but it must be capable of handling the power that the appliance draws. In this tutorial a 10A relay module is used which can handle up-to 2400W (240Vx10A resistive loads) appliances. Relay coil is 5 Volts. This relay module has an led that lights up when the relay is switched on. Info on where you can buy the relay module is at the end of this post.

A breadboard makes hooking up the circuit easier, but is not essential.

How does it work?
Pressing the button switch momentarily will put pin 2 of the Arduino in HIGH (ON) state, with 5 Volts. This voltage will put the transistor in the relay module in the ON (conducting) state and that will then power the relay. When the relay is powered, the relay contacts will close and let mains power flow to our appliance. The opposite happens when the button is pressed again, pin 2 is put in LOW (OFF) state with 0 Volts and the relay is switched OFF. The controlled appliance is connected to two of the three terminal blue connector (the one with screws) on the relay module. 

Relay circuit


Step 1 - Download and install the Arduino IDE
There are two versions of the IDE, the offline one and the Arduino Web Editor. The traditional offline IDE will let you work without Internet connection. The Arduino Web Editor saves your work in the cloud and requires an Internet connection. In this tutorial I will be using the offline IDE. It can be downloaded here.  

Step 2 - Connect the circuit according to the schematic.
The circuit is really simple and all pins are labelled, both on the Arduino board and the relay module. It can all be put together using a small breadboard and some breadboard jump wires. The relay has 3 pins labelled -, + and S. Pin S is connected to an output pin on the Arduino, pin 2. The button switch has 4 pins, but 2 pairs are connected together! Check with a multimeter or, if the switch has no effect after the code is uploaded, try connecting to the other pins by rotating the switch 90º.

Step 3 - Connect the board to your computer.
Arduino boards use USB connection. If you are buying an Arduino board don't forget the correct USB cable. The Arduino UNO uses USB A to B cable (standard USB printer cable) and the Arduino Nano uses mini B USB plug.

Step 4 - Start the Arduino IDE
When the IDE is stated it will automatically create and name a file called a sketch. Sketch files is where we enter our code. Ignore the blank sketch file and download the project sketch file here. Then open the file in the IDE.

Step 5 - Select the board
Before uploading the sketch to the board we must make sure the correct type of board is selected in the IDE. Go to Tools > Board and select the correct board matching the board you are using.

Step 6 - Select the Port
Before uploading the sketch to the board select the correct communications port for the board. In the Tools menu, in Board, select the correct COM port.

Step 7- Upload the code
To upload the code to the Arduino board go to File and select Upload, or press the Upload button on the IDE toolbar. In a few seconds the code will be compiled and then uploaded to the board.

Arduino IDE

Testing
Once the code upload is completed you can test the circuit by pressing the switch button. You should hear the relay click on and off as you press the button.  If you use the suggested relay module, an led will also light up when the relay is switched on. If the switch has no effect, check the connections for errors or bad contacts and try rotating the tactile switch by 90º.

That's it! You now know how to use and program an Arduino to switch relays. You can use this project as it is or you can make changes to the code, like adding more relays or switching the relay On or Off at predetermined programmed times. Have fun!

Buy the parts and support MakerCorner!
I may get a small fee if you use the following links to buy the parts. Thank you for your support!


Thursday, April 6, 2017

72MHz-108MHz DIY FM Clock Radio Kit with digital display from Banggood

Few things are more fun to experiment with than "old style" radios! Peeking inside a radio is one of top things that sparks the interest of many young people in electronics!

Recently, while shopping for some electronics, an interesting FM radio kit came to my attention. It's an DIY (user assembled) FM radio with digital display and alarm clock. But what draw my attention to this kit was the fact that this radio can be easily modded to work outside of the commercial FM band and it has a digital frequency readout module that can be used in multiple radio projects! The radio is based on the popular CD2003GP/GB FM/AM radio IC. The digital frequency display uses the SC3610D IC, a frequency and clock display driver capable of up-to 150Mhz frequency display. Since the radio comes in kit form, it is also an excellent project to practice component assembling and soldering. 

DIY FM Radio Kit 72-108Mhz

There are two kits of this same radio, type 1 and type 2. They are identical, the only difference is that type 1 comes with the digital display module pre-assembled, which I recommend. Both kits cost around 9 USD with free shipping from Banggood. The radio operates from two AA batteries (3V), which are not included in the kit. 

cd2003 DIY FM radio kit schematic + pcb


FM radio kit assembly:
Assembly of FM radio kit is straightforward and should take well under two hours. All the necessary components are provided together with a big paper schematic of the radio circuit and parts list, which is excellent. Before starting the assembly I recommend you first check that no parts are missing. The kit that I received came with a few extra passive components and screws, which is a nice touch.

DIY FM radio kit components

Things you need:
To assemble the radio you will need a a low power soldering iron, 60/40 soldering wire, a wire cutter to trim the components leads after soldering and a small Philips screwdriver. Desoldering braid (wick) will also come handy if you need to desolder or remove excess solder from a joint.

Assembly steps:
  1. Start by inspect the main PCB and clean it if necessary. 
  2. Install the passive components on the board: resistors, capacitors, coils, etc. 
  3. Solder them in place and cut excess lead wires. 
  4. Install and solder the transistors and the two IC's. Be careful when soldering the IC's and transistors, since excessive heat can easily damage them! 
  5. Solder the speaker, antenna and battery wires to the PCB. 
  6. Place the metallic switch domes on the digital display board with some plastic tape and connect the digital display to the main board by soldering the wires. 
  7. Attach the speaker to the plastic case. 
  8. Place the plastic buttons and the two boards and insert the screws. 
  9. Attach the antenna wire to the antenna rod. 
  10. Solder the battery wires to the battery compartment.

Before inserting the batteries check if all components are in place and soldered properly. All solder joints should have a shiny finish!

That's it! Turn on the radio and try to tune to some FM radio station. 

I have made a video of the assembly process. Please take a look:




Tuning adjustment:
You may need to adjust the tuning capacitor to set the low and high FM band limits or to get the best reception quality. This is easily accomplished by tweaking two adjustment trimmers on the back of the tuning capacitor.

DIY FM Radio tuning adjustment


Improvements and Hacks:
The radio works reasonably well as it is, but you can make some improvements easily. You can even make the radio receive the Air Band (108-136Mhz). This is part of the fun of course.

Main components (datasheets):
CD2003GP FM/AM Radio IC datasheet
SC3610 Frequency and Clock Display Driver datasheet
TDA2822M Audio Amplifier IC Datasheet
 
Buy the kit and support MakerCorner!
I may get a small fee if you buy the kit through a link in MakerCorner. If you want to buy this kit and you found this post helpful, please support my work by clicking on this link to Banggood. Thank you!