Category :Arduino Projects

Byamber

Arduino lesson – 2-Channel Relay Module

Content

  1. Introduction
  2. Preparations

  3. About the 2-Channel Relay Module

  4. Example
  5. Connection
  6. Upload Sketch
  7. Program Running Result

Introduction

A relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a switch, but other operating principles are also used, such as solid-state relays. Relays are used where it is necessary to control a circuit by a separate low-power signal, or where several circuits must be controlled by one signal.

In this lesson, we will show you how the 2-Channel Relay Module works and how to use it with the Osoyoo Uno board to control high voltage devices.

Preparations

Hardware

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • 2-Channel Relay Module x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Software

  • Arduino IDE (version 1.6.4+)

About 2-Channel Relay Module

Overview

This is a 5V 2-Channel Relay Module board, Be able to control various appliances, and other equipment with large current. It can be controlled directly by Microcontroller (Raspberry Pi, Arduino, 8051, AVR, PIC, DSP, ARM, ARM, MSP430, TTL logic). Very useful project for application like Micro-Controller based projects, Remote controller, Lamp on Off, and any circuits which required isolated high current and high voltage switching by applying any TTL or CMOS level voltage.

Features

  • High current relay, AC250V 10A, DC30V 10A
  • 2 LEDs to indicate when relays are on
  • Works with logic level signals from 3.3V or 5V devices
  • Opto isolation circuitry
  • PCB size: 50×45 mm

Pins Out

Input

It has a 1×4 (2.54mm pitch) pin header for connecting power (5V and 0V), and for controlling the 2 relays. The pins are marked on the PCB:

  • GND – Connect 0V to this pin.
  • IN1 – Controls relay 1, active Low! Relay will turn on when this input goes below about 2.0V
  • IN2 – Controls relay 2, active Low! Relay will turn on when this input goes below about 2.0V
  • VCC – Connect 5V to this pin. Is used to power the opto couplers

There is a second 1×3 (2.54mm pitch) pin header for supplying the “relay side” of the board with 5V. At delivery, a jumper is present on this header selecting the 5V signal from the 1×4 pin header to power the relays. For default operation, don’t change this jumper!

The pins of the 1×3 pin header are marked on the PCB:

  • JD-VCC – This is the 5V required for the relays. At delivery, a jumper is present on this and the adjacent (VCC) pin.
  • VCC – This is the 5V VCC supplied on the 1×4 pin connector
  • GND – Connected to 0V pin of 1×4 pin header

If opto isolation is required, an isolated 5V supply should be used. For normal operation, a jumper bewtween pins 1 and 2 selects the 5V signal from the 1×4 pin header. This means both the “input side”, and “relay side” use the same 5V supply, and there is no opto-isolation.

Output

The 2 channel relay module could be considered like a series switches: 2 normally Open (NO), 2 normally closed (NC) and 2 common Pins (COM).

  • COM- Common pin
  • NC- Normally Closed, in which case NC is connected with COM when INT1 is set low and disconnected when INT1 is high
  • NO- Normally Open, in which case NO is disconnected with COM1 when INT1 is set low and connected when INT1 is high

Schematic

How relay works?

The working of a relay can be better understood by explaining the following diagram given below.

There are 5 parts in every relay:

1. Electromagnet – It consists of an iron core wounded by coil of wires. When electricity is passed through, it becomes magnetic. Therefore, it is called electromagnet.

2. Armature – The movable magnetic strip is known as armature. When current flows through them, the coil is it energized thus producing a magnetic field which is used to make or break the normally open (N/O) or normally close (N/C) points. And the armature can be moved with direct current (DC) as well as alternating current (AC).

3. Spring – When no currents flow through the coil on the electromagnet, the spring pulls the armature away so the circuit cannot be completed.

4. Set of electrical contacts – There are two contact points:

.Normally open – connected when the relay is activated, and disconnected when it is inactive.

.Normally close – not connected when the relay is activated, and connected when it is inactive.

5. Molded frame – Relays are covered with plastic for protection.

Principle

The diagram shows an inner section diagram of a relay. An iron core is surrounded by a control coil. As shown, the power source is given to the electromagnet through a control switch and through contacts to the load. When current starts flowing through the control coil, the electromagnet starts energizing and thus intensifies the magnetic field. Thus the upper contact arm starts to be attracted to the lower fixed arm and thus closes the contacts causing a short circuit for the power to the load. On the other hand, if the relay was already de-energized when the contacts were closed, then the contact move oppositely and make an open circuit.

As soon as the coil current is off, the movable armature will be returned by a force back to its initial position. This force will be almost equal to half the strength of the magnetic force. This force is mainly provided by two factors. They are the spring and also gravity.

Relays are mainly made for two basic operations. One is low voltage application and the other is high voltage. For low voltage applications, more preference will be given to reduce the noise of the whole circuit. For high voltage applications, they are mainly designed to reduce a phenomenon called arcing.

High Voltage Warning


Before we continue with this lesson, I will warn you here that we will use High Voltage which if incorrectly or improperly used could result in serious injuries or death. So be very caution of what you are doing.

Examples

Using the Arduino to Control a 2 Channel Relay

In this example, when a low level is supplied to signal terminal of the 2-channel relay, the LED on the relay will light up. Otherwise, it will turn off. If a periodic high and low level is supplied to the signal terminal, you can see the LED will cycle between on and off.

Connection

Build the circuit as below digram:

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

//the relays connect to int IN1 = 2; int IN2 = 3; #define ON 0 #define OFF 1 void setup() { relay_init();//initialize the relay } void loop() { relay_SetStatus(ON, OFF);//turn on RELAY_1 delay(2000);//delay 2s relay_SetStatus(OFF, ON);//turn on RELAY_2 delay(2000);//delay 2s } void relay_init(void)//initialize the relay { //set all the relays OUTPUT pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); relay_SetStatus(OFF, OFF); //turn off all the relay } //set the status of relays void relay_SetStatus( unsigned char status_1, unsigned char status_2) { digitalWrite(IN1, status_1); digitalWrite(IN2, status_2); } 

Running Result

A few seconds after the upload finishes, you should see the LED cycle between on and off.

Byamber

Arduino lesson – Digital Touch Sensor Module

Introduction

We need Switch to control electronics or electrical appliances or some thing, Some time electrical switches will give a shock when we use electrical switches with wet hand and then touch to control electrical or electronic load is much interactive than ordinary switches, may be some projects needs touch switch.

In this lesson, we will show what is Digital Touch Sensor Module and how to use it with the Arduino board.

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Breadboard x 1
  • Digital Touch Sensor Module x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

SOFTWARE

Arduino IDE (version 1.6.4+)

About Digital Touch Sensor Module

Overview:

  • The module is based on a touch-sensing IC (TTP223B) capacitive touch switch module.
  • In the normal state, the module output low, low power consumption; When a finger touches the corresponding position, the module output high, if not touched for 12 seconds, switch to low-power mode
  • Jog type : the initial state is low , high touch , do not touch is low ( similar touch of a button feature )
  • Module can be installed in such as surface plastic, glass of non-metallic materials. In addition to the thin paper ( non-metallic ) covering the surface of the module , as long as the correct location of the touch , you can make hidden in the walls, desktops and other parts of buttons

Features:

  • Low power consumption
  • Power supply for 2 ~ 5.5V DC
  • Operating Current(Vcc=3V):1.5 – 3.0μA
  • Operating Current(VDD=3V):3.5 – 7.0μA
  • Can replace the traditional touch of a button
  • Four M2 screws positioning holes for easy installation
  • Response Time: Low power mode:220ms;Quick mode :60ms
  • Size: 8*6*0.5 cm

Specification:

-Control Interface : A total of three pins (GND, VCC, SIG), GND to ground , VCC is the power supply , SIG digital signal output pin ;
-Power Indicator : Green LED, power on the right that is shiny ;
-Touch area : Similar to a fingerprint icon inside the area , you can touch the trigger finger .
-Positioning holes : 4 M2 screws positioning hole diameter is 2.2mm, the positioning of the module is easy to install , to achieve inter- module combination ;

TTP223-IC

TTP223 is 1 Key Touch pad detector IC, and it is suitable to detect capacitive element variations. It consumes very low power and the operating voltage is only between 2.0V~5.5V. The response time max about 60mS at fast mode, 220mS at low power mode @VDD=3V. Sensitivity can adjust by the capacitance(0~50pF) outside.

Applications:

  • Water proofed electric products
  • Button key replacement
  • Consumer products

Example

Connect the Touch Sensor to Your Arduino

Connect Vcc pin of Sensor breakout board to Arduino’s +5V pin and GND to GND. Connect Signal (SIG) pin to Arduino Digital pin D2.

Copy, Paste and Upload the Arduino Sketch

The sketch below provides an output to your serial monitor indicating whether or not the sensor is pressed.

Result

After the uploader , if use finger or metal object touch the metal surface of the transducer , the red LED lights on the UNO will light. Open the Serial Monitor at baudrate 9600, and you will see something as below:

Byamber

Arduino lesson – PIR Motion Sensor

Content

  1. Introduction
  2. Preparations
  3. About the PIR Motion sensor
  4. Examples

Introduction

A passive infrared sensor (PIR Motion sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. So, it can detect motion based on changes in infrared light in the environment. It is ideal to detect if a human has moved in or out of the sensor range. In this lesson we will learn how a PIR Sensor works and how to use it with the Arduino Board for detecting motion.

Preparations

Hardware

  • UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • PIR Motion sensor x 1
  • Relay x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Software

  • Arduino IDE (version 1.6.4+)

About PIR Motion sensor

Overview

PIR Motion Sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and don’t wear out. For that reason they are commonly found in appliances and gadgets used in homes or businesses. They are often referred to as PIR, “Passive Infrared”, “Pyroelectric”, or “IR motion” sensors.

Use this Arduino motion sensor to build burglar alarm systems, home automation systems, or any simple gadget that prevents people from getting into your room!

Specifications

  • Working voltage: 4.5V to 20V
  • Output: High: 3.3V, Low: 0V
  • Detection angle: Approximately 120 degrees
  • Range: Adjustable, up to 7m
  • Trigger modes: L unrepeatable trigger / H repeatable trigger (default)
  • Dwell time: (Stay-ON time) adjustable between 5-300 Seconds. –– it can be further increased by increasing the value of the CY1-Timing capacitor on pin 4 of the IC
  • Operating Temperature: -20 – +80 Degrees C.
  • PCB Dimensions: 33x25mm, 14mm High not including the Lens; Lens: 11mm high, 23mmDiameter.
  • Weight: 6g

PIRs are basically made of a pyroelectric sensor (which you can see above as the round metal can with a rectangular crystal in the center), which can detect levels of infrared radiation. Everything emits some low level radiation, and the hotter something is, the more radiation is emitted. The sensor in a motion detector is actually split in two halves. The reason for that is that we are looking to detect motion (change) not average IR levels. The two halves are wired up so that they cancel each other out. If one half sees more or less IR radiation than the other, the output will swing high or low.

This sensor is then placed behind a multifaceted lens (a Fresnel lens) that “chops up” the view of the world into smaller cones of heightened visibility and intervening areas of lessened visibility thus widening the useful viewing /detection angle dramatically.

PIR Sensing Angle diagram:

Along with the pyroelectic sensor is a bunch of supporting circuitry, resistors and capacitors. It seems that most small hobbyist sensors use the BISS0001 (“Micro Power PIR Motion Detector IC”), undoubtedly a very inexpensive chip. This chip takes the output of the sensor and does some minor processing on it to emit a digital output pulse from the analog sensor.

Our PIR Motion Sensors looked like this:

Pin or Control Function
Delay Time Adjust Sets how long the output remains high after detecting motion…. Anywhere from 5 seconds to 5 minutes.
Sensitivity Adjust Sets the detection range…. from 3 meters to 7 meters
Ground pin Ground input
Digital Output Pin Low when no motion is detected.. High when motion is detected. High is 3.3V
Power Pin 4.5 to 20 VDC Supply input

How Does it Work?

Here, we are using a PIR motion sensor. PIR stands for Passive InfraRed. This motion sensor consists of a fresnel lens, an infrared detector, and supporting detection circuitry. The lens on the sensor focuses any infrared radiation present around it towards the infrared detector. Our bodies generate infrared heat and as a result, this gets picked up by the motion sensor. The sensor outputs a 5V signal for a period of one minute as soon as it detects the presence of a person. It offers a tentative range of detection of about 6-7 m and is highly sensitive.

When the PIR motion sensor detects a person, it outputs a 5V signal to the Arduino. Thus, an interrupt on Arduino is triggered. We define what the Arduino should do as it detects an intruder.

Sensitivity Adjustment

As mentioned, the adjustable range is from approximately 3 to 7 meters. The illustration below shows this adjustment. You may click to enlarge the illustration.

Delay Time Adjustment

The time delay adjustment determines how long the output of the PIR sensor module will remain high after detection motion. The range is from about 5 seconds to five minutes. The illustration below shows this adjustment.

Trigger Mode Selection Part

The trigger mode selection jumper allows you to select between single and repeatable triggers. The affect of this jumper setting is to determine when the time delay begins.

  • SINGLE TRIGGER – The time delay begins immediately when motion is first detected.
  • REPEATABLE TRIGGER – Each detected motion resets the time delay. Thus the time delay begins with the last motion detected.

5 Seconds Off After Time Delay Completes – IMPORTANT

The output of this device will go LOW (or Off) for approximately 5 seconds after the time delay completes. In other words, all motion detection is blocked during this three second period.

For Example:

  • Imagine you’re in the single trigger mode (see below) and your time delay is set 5 seconds.
  • The PIR will detect motion and set it high for 5 seconds.
  • After five seconds, the PIR will sets its output low for about 3 seconds.
  • During the three seconds, the PIR will not detect motion.
  • After three seconds, the PIR will detect motion again and detected motion will once again set the output high and the output will remain on as dictated by the Delay Time adjustment and trigger mode selection.

Examples

PIR Motion Sensor Control LED

In this project you’re going to create a simple circuit with an Arduino and PIR motion sensor that can detect movement. An LED will light up when movement is detected.

Connection

Build the circuit as below:

Connecting PIR sensors to a microcontroller is really simple. The PIR acts as a digital output so all you need to do is listen for the pin to flip high (detected) or low (not detected).

Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin. In this example we’ll use pin 2.

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input Serial.begin(9600); } void loop(){ val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; } } else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } } }

This code just keeps track of whether the input to pin 2 is high or low. It also tracks the state of the pin, so that it prints out a message when motion has started and stopped.

Running Result

A few seconds after the upload finishes, have a look at your Arduino’s pin 13 LED. You can also open your serial monitor, and set the baud rate to 9600 bps, you may see the following:

The PIR sensor requires a couple seconds of motion-free activity, while it gets a “snapshot” of it’s viewing area. Try not to move until the pin 13 LED turns off, then wave your hands, jump in the air, go crazy!

You will also notice that there is a delay associated with the motion sensor after each detection. Depending on the sensor, you may be able to adjust this delay.

PIR Motion Sensor Control Relay

As an example for this lesson I will make a circuit that will turn on a relay to control some high voltage things when the sensor will detect an object.

Connection

Build the circuit as below:

The output pin of the sensor will be connected to pin number 2 on the Arduino Board and when an object will be detected the pin number 3 will activate the relay module and the high voltage lamp will turn on. For more details how the relay module works, you can check the sketch below.

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

int ledPin = 13; // choose the pin for the LED int relayInput = 3; // choose the pin for the relay int inputPin = 2; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input pinMode(relayInput, OUTPUT); // declare relay as output digitalWrite(relayInput, HIGH);//assuming relay is off Serial.begin(9600); } void loop(){ val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; digitalWrite(relayInput, LOW); // The Relay Input works Inversly Serial.println("Turn on the Lamp!"); Serial.println("Wait for 30 seconds"); delay(30000); // delay for 30 seconds digitalWrite(relayInput, HIGH);// Relay input operation is positive Serial.println("Turn off the Lamp!"); } } else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH) { // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } } }

Here’s the Arduino Code for this example. It’s quite simple. We just need to define the PIR Sensor pin as input and the relay pin as output. Using the digitalRead() function we will read the output of the sensor and if its high or if an object is detected it will activate the relay. For activating the relay module we will send a logic low as the relay input pin works inversely.

Running Result

A few seconds after the upload finishes, you will see as below:

Note that after powering the sensor module it needs about 20 – 60 seconds to “warm-up” in order to function properly. Now when you will put your hand in front of the sensor the relay will activate the lamp. But note that even if you move your hand constantly the lamp will turn off after the adjusted delay time is over because the PIR sensor is in “non-repeatable trigger” mode. If you change the sensor with the jumper to the “repeatable trigger” mode and you constantly move the hand, the lamp will be constantly on as well and it will turn off after the movement is gone and the set delay time is over.

Keep in minds that if you are using high voltage in this example, so you should be very caution.