Author Archives: amber

Byamber

Graphical Programming Tutorial for Arduino – Infrared Remote Control the Lamp

Introduction

In this lesson, we will show how to use the IR control an LED. When we press the “OK” button, the LED will be turned on, and when we press the “OK” button again, the LED will be truned off.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Infrared Receiver x 1
  • Remote Controller x 1
  • LED x 1
  • 200 ohm Resistor x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Connection

Build the circuit as 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 Graphical Programming software Mixly and follow the next operations:

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts.

Finally, the staus will change to ‘Upload success!’.

Running Result

A few seconds after the upload finishes, press the “OK” button of a remote controller, the LED attached connected to D12 will be light up. Then press “OK” again, and the LEDs will go out.

Byamber

Graphical Programming Tutorial for Arduino – IR Remote Receiver Module and Controller

INTRODUCTION

IR, or infrared, communication is a common, inexpensive, and easy to use wireless communication technology. IR light is very similar to visible light, except that it has a slightlty longer wavelength. This means IR is undetectable to the human eye – perfect for wireless communication. For example, when you hit a button on your TV remote, an IR LED repeatedly turns on and off, 38,000 time a second, to transmit information (like volume or channel control) to an IR photo sensor on your TV.

This tutorial will first explain the inner workings of common IR communication protocols. Then we will go over three examples that will allow you to transmit and receive IR data using an Arduino. In this example, we will read incoming IR data from a common remote control using the 1838B IR photo sensor.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Infrared Receiver x 1
  • Remote Controller x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

About the IR

WHAT IS IR?

Infra-Red light is actually normal light with a particular colour. We humans can’t see this colour because its wave length of about 950nm is below the visible spectrum. That’s one of the reasons why IR is chosen for remote control purposes, we want to use it but we’re not interested in seeing it. Another reason is because IR LEDs are quite easy to make, and therefore can be very cheap, thus making it ideal for us hobbyists to use IR control for our own projects.

We need to konw there are many more sources of Infra-Red light. The sun is the brightest source of all, but there are many others, like: light bulbs, candles, central heating system, and even our body radiates Infra-Red light.

A common modulation scheme for IR communication is something called 38kHz modulation. There are very few natural sources that have the regularity of a 38kHz signal, so an IR transmitter sending data at that frequency would stand out among the ambient IR. 38kHz modulated IR data is the most common, but other frequencies can be used.

When you hit a key on your remote, the transmitting IR LED will blink very quickly for a fraction of a second, transmitting encoded data to your appliance.

If you were to hook an oscilloscope up to your TV remote’s IR LED, you would see a signal similar to the one above. This modulated signal is exactly what the receiving system sees. However, the point of the receiving device is to demodulate the signal and output a binary waveform that can be read by a microcontroller. When you read the OUT pin of the VS1838B with the wave from above, you will see something like the second.

Modulation

As everything that radiates heat, also radiates Infra-Red light. Therefore we have to take some precautions to guarantee that our IR message gets across to the receiver without errors.Modulation of the signal on a carrier frequency is the answer to make our signal stand out above the noise. With modulation we make the IR light source blink in a particular frequency. The IR receiver will be tuned to that frequency, so it can ignore everything else.

In the picture below you can see a modulated signal driving the IR LED of the transmitter on the left side. The detected signal is coming out of the receiver at the other side.

(Thanks to SBProjects.com for the gif and excellent IR resource!)

TECHNICAL DETAILS OF VS1838B IR RECEIVER

  • Model Number : VS1838B;
  • Working Voltage :2.7V to 5.5V
  • Reception Distance : 18M;
  • Reception Angle : ± 45 Degree;
  • Low Level Voltage : 0.4V
  • High Level Voltage : 4.5V;
  • Body Size : 7 x 7 x 5mm / 0.27″ x 0.27″ x 0.2″(L*W*T);
  • Pin Length : 22.5mm / 0.88″
  • Pitch : 2mm / 0.08″;

THE PINOUT FOR VS1838B IR RECEIVER:

ABOUT THE IR CONTROL

Infrared remotes are still the cheapest way to wirelessly control a device. We have designed the remote to be small, very simple, and low-cost.There are many different IR remote controls. all of these may have different encoding methods and number of physical buttons, and different codes received when a button is pressed.

Examples

READ CODES FROM IR REMOTE

This example will show you how to read IR remote codes from any IR remote using the VS1838B IR receiver and an Arduino. Once you can receive codes from individual button presses, your remote control and Arduino become a general purpose, short range, communication interface!

Connection

Build the circuit as 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 Graphical Programming software Mixly and follow the next operations:

Drag out the IR Control block from the Communications.

Connect the IRreceive PIN to D3.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts.

Finally, the staus will change to ‘Upload success!’.

Running Result

The sketch will automatically decode the type of remote you are using and identify which button on your remote is pressed. Open the Serial Monitor in the Mixly at 9600 bps and hit different buttons on your remote.

The Serial Monitor displaying random button presses on my remote. Different buttons show different codes:

If you use the sketch above and count the 17 buttons from left to right and top to bottom, the codes received are these: (NOTE: Receiving “FFFFFFFF” means “repeat” if you hold the button down.)

1 FFA25D
2 FF629D
3 FFE21D
4 FF22DD
5 FF02FD
6 FFC23D
7 FFE01F
8 FFA857
9 FF906F
10 FF6897
11 FF9867
12 FFB04F
13 FF18E7
14 FF10EF
15 FF38C7
16 FF5AA5
17 FF4AB5

Byamber

Graphical Programming Tutorial for Arduino – Use the Push-Button as a Switch

Introduction

After the tutorial Using a Button, you might think, if we want to turn on the LED in this way, the hand cannot leave button, it is not convenient.How to control the lights as normal , click on the light, then press out? We can improve the program, which can realize the result that will modify the program for the following code, and then upload to the Osoyoo Arduino board.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Breadboard x 1
  • Switch Button x 1
  • 10k ohm resistor x 1
  • M/M jumpers
  • USB Cable x 1
  • PC x 1

Connection

Although the bodies of the buttons are square, the pins protrude from opposite sides of the button. This means that the pins will only be far enough apart when they are the correct way around on the breadboard.Build the circuit as below:

Notice:

Generally, the button is directly connected in an LED circuit in order to turn on or off the LED. This connection is relatively simple. However, sometimes the LED will light up automatically without pressing the button, which is caused by various interferences. In order to avoid these external interferences, a pull-down resistor is used, that is, to connect a 1K–10KΩ resistor between the button port and GND. It is used to consume external interferences while connected to GND for as long as the button switch is turned off.

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 Graphical Programming software Mixly and follow the next operations:

In this program, we use the “setup” block. Compared with the program under it, the “setup” block only executes once during the whole process of running the program.

In the “setup” block, we use the module that defines variables. The name of the variable is state, which is a Boolean variable, that is, its value has two kinds of “high” and “low”.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts.

Finally, the staus will change to ‘Upload success!’.

Running Result

After the program is compiled and uploaded, you can achieve: click the button to turn on the LED, and then press this button, the LED will be turned off.

Byamber

Graphical Programming Tutorial for Arduino – Digital Dice

Introduction

Dice is a squire type solid box which contains 6 different numbers on all of its sides. We throw dice on a surface to get a random number while playing the games. In this lesson, we will build a dice that is shaken by holding the button in and thrown by releasing the button. The shake, throw and number thrown are animated and displayed on a seven segment display. A 74HC595 IC is used to interface the 7-segment display to the Arduino, using only 3 Arduino digital pins.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • One digit 7-Segment LED Display x 1
  • 200 ohm Resistor x 8
  • 10k ohm Resistor x 1
  • Push Button x 1
  • 74HC595 x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

SOFTWARE

  • Arduino IDE (version 1.6.4+)

Find more information about interfacing the 74HC595 IC to the Arduino in the Arduino Lesson – 74HC595 article from the Osoyoo website. The circuit diagram uses the same Arduino pins as this article. If you want to get more info about the switch button please check the Arduino Button example, more info about the one digit 7-segment LED display please check the Arduino Lesson – one digit 7-segment LED display.

Connection

The circuit diagram is shown below. The seven segment display could have been directly interfaced to the Arduino, but by using the 74HC595, only 3 Arduino pins are used.

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 Graphical Programming software Mixly and follow the next operations:

Note: The code will be a little long You’re recommended to open the developed code example to check.

Declare the variables and array.

The text list is: 252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142

This function is to display the number in dataArray[] on the 7-segment display. Pin 12 connected to ST_CP of 74HC595:

Store values read from pin 2.

Check if the pushbutton is pressed. If yes, the corresponding pin is high level, then num adds 1.

If Num >1. clear the valueIs to prevent repeated pressing. So just count it as once no matter how many times you press.

Print the Num on the Serial Monitor:

When the pushbutton is pressed.

Generate a random number between 1 and 7, and show the RandNumber on the 7-segment:

When theres no button (pin 2)pressed, the program stops here, and keeps it displaying the last random number. Then read the state of the button again.

Check if the pushbutton is pressed. If yes, run the code below.

Turn on/off the LED.

Clear the Num.

If the button has not been pressed, show random numbers at 100 microseconds intervals.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts.

Finally, the staus will change to ‘Upload success!’.

Running Result

A few seconds after the upload finishes, you should now see the 7-segment display jump between numbers from 1 to 6. Press the button, and the jumping will slow down until it stops three seconds later. Press the button again, and the process will repeat.

Byamber

Graphical Programming Tutorial for Arduino – Traffic Light Controller

Introduction

The real time traffic light controller is a complex piece of equipment which consists of power cabinet, main controller or processor, relays, control panel with switches or keys, communication ports etc.

In this lesson, we will go over how to build a traffic light circuit with an arduino microcontroller.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • One Digit 7-Segment LED Display x 1
  • 74HC595 x 1
  • 200 ohm Resistor x 7
  • LEDs (Red LED x 2, Yellow LED x 2, Green LED x 2)
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

About this project

The use of personal vehicles is very common now a days and a result, the number of vehicles on the roads are exponentially increasing. Roads without any supervision or guidance can lead in to traffic congestions and accidents.

Traffic Lights or Traffic Signals are signalling devices that are used to control the flow of traffic. Generally, they are positioned at junctions, intersections, ‘X’ roads, pedestrian crossings etc. and alternate the priority of who has to wait and who has to go.

The traffic lights will provide instructions to the users (drivers and pedestrians) by displaying lights of standard color. The three colors used in traffic lights are Red, Yellow and Green.

In this project, an Arduino based Traffic Light Controller system is designed. It is a simple implementation of traffic lights system but can be extended to a real time system with programmable timings, pedestrian lighting etc. There is a green LED, which represents the green light. A yellow LED, which represents the yellow light. And a red LED, which represents the red light.

We will show all the hardware connections and the software needed to make this circuit work.

Connection

Build the circuit as below:

In this experiment, we use a 7-segment display to count down and set two groups of traffic lights to represent two directions, let’s say, north-south (TF1) and east-west (TF2), as shown in the above picture.

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 Graphical Programming software Mixly and follow the next operations:

Setup baud rate and define datArray[] to store the to-be-display number.

Set a function State 1(), to light up a red LED(Pin 5).

Display the number from 9 to 1 on the 7-segment Display, and light up the Green2 LED (Pin 4), set T_CP( Pin 12) Low and hold low for transmitting, then pull it to save the data.

Turn off the Green LED (Pin 4), and display the number 3 to 1 on the display, then turn on Yellow 2 LED (Pin 3). Next, dim LED Yellow 2 and Red 1( Pin 5).

Next comes the State2() The blocks of State2() is just similar and you can study by yourself.

Execute function State 1() and State2().

Running Result

A few seconds after the upload finishes, you can see what is similar to the traffic light now. First, the 7-segment display counts down from 9s, and the red light in the TF1 and the green one in the TF2 light up. Then it counts down from 3, and the green LED in the TF2 goes out when the yellow lights up, with the TF1 red light still on. 3s later, the 7-segment counts down from 9s again. Meanwhile, the red light in the TF2 and the green in the TF1 light up. After 9s, it counts down from 3s, when the yellow light in the TF1 lights up and the red in the TF2 keeps on. And this repeats over and over again, as a traffic light would.

Although it is not the ideal implementation for real life scenarios, it gives an idea of the process behind the traffic light control system.

Note: The project implemented here doesn’t include the pedestrian crossing and pedestrian signaling in to consideration.

Once you know how the software operates, you can change the values to make the LEDs be on or off for any period of time. For example, instead of being on for 9 seconds, you can easily change it to 15 seconds or 30 seconds. You could make the yellow LED be on just for 1 second or 2 seconds.

Byamber

Graphical Programming Tutorial for Arduino – Photoresistor

Introduction

In this lesson, we will show how to use the photoresistor with an Osoyoo UNO, we will monitor the output of a photoresistor, allow the Arduino to know how light or dark it is. When the light falls below a certain level, the Arduino turns on an LED.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Breadboard x 1
  • Photoresistor x 1
  • 10k ohm resistor x 1
  • 200 ohm resistor x 8
  • LED x 8
  • M/M jumpers
  • USB Cable x 1
  • PC x 1

About Photoresistor

Photocells are sensors that allow you to detect light. They are small, inexpensive, low-power, easy to use and don’t wear out. For that reason they often appear in toys, gadgets and appliances. They are often referred to as CdS cells (they are made of Cadmium-Sulfide), light-dependent resistors (LDR), and photoresistors.

Photocells are basically a resistor that changes its resistive value (in ohms Ω) depending on how much light is shining onto the squiggly face.When it is dark, the resistance of a photoresistor may be as high as a few MΩ. When it is light, however, the resistance of a photoresistor may be as low as a few hundred ohms. They are very low cost, easy to get in many sizes and specifications, but are very innacurate. Each photocell sensor will act a little differently than the other, even if they are from the same batch. The variations can be really large, 50% or higher! For this reason, they shouldn’t be used to try to determine precise light levels in lux or millicandela. Instead, you can expect to only be able to determine basic light changes.

This graph indicates approximately the resistance of the sensor at different light levels:

Connection

You connect the components as shown in the diagram below. Connect the LED to pin 9 of the Arduino. The 200 ohm resistor is current limiting resistor. One lead of the photo resistor is connected to 5V, the other to one lead of the 10k ohm resistor. The other lead of the 10k ohm resistor is connected to ground. This forms a voltage divider, whose output is connected to pin A0 of the Arduino.

As the light impinging on the photoresistor gets stronger, the resistance decreases, and the voltage output of the divider increase. The reverse happens, when the impinging light gets weaker.

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 Graphical Programming software Mixly and follow the next operations:

Connect the light sensor with the A0 analog port of the UNO board. Users can change the analog port to A1 ~ A5 on your own.

In this experiment, we will connect a photoresistor to an Arduino analog input and read the value with the analogRead() function. Depending on the value the Arduino reads, the program will then set pin 9 HIGH or LOW to turn on or turn off the LED night lights. The threshold value is 500. When the analog value read is less than 500, the Arduino will turn the LEDs on. When the analog value it reads is more than 500, the Arduino will turn the LEDs off.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts

Finally, the staus will change to ‘Upload success!’.

Running Result

If the room is lighted, the LEDs should not light. Try getting them to turn on it by covering the photoresistor with your hand. Remove your hand and observe that they turn off again.

In the same time, open the Serial Monitor and you will get the output data as below :

Note:

When you are using the Serial Monitor, please make sure the baudrate setting is same as your sketch definition.

Byamber

Graphical Programming Tutorial for Arduino – Sound Detection Sensor

Introduction

The Sound Detection Sensor is a small board that combines a microphone and some processing circuitry, it has the ability to detect different sizes of sound. This sensor can be used to for a variety of uses from industrial to simple hobby or playing around.

In this lesson we will guide you through hooking up and using the Sound Detector. It will examine how the circuit works, explain some details about getting the best performance from the Sound Sensor, then present some projects that demonstrate how to use it.

Preparations

HARDWARE

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

About Sound Detection Sensor

OVERVIEW

The Sound Detection sensor module has a built-in capacitive electret microphone which is highly sensitive to sound. Sound waves cause the thin film of the electret to vibrate and then the capacitance changes, thus producing the corresponding changed voltage, so it can detect the sound intensity in ambient environment. Since the change is extremely weak, it needs to be amplified. We use a LM393 as the power amplifier here. You can adjust the sensitivity with by adjusting the Potentiometer. When the sound level exceeds the set point, an LED on the sensor module is illuminated and the output is sent low.

Note: This sound sensor is used to detect whether there’s sound surround or not, it cannot recognize the frequence or volum, please don’t use the module to collect sound signal.

ARDUINO SOUND DETECTION SENSOR PIN OUTS

The image and table below detail the controls, pin outs, and other key components.

When referring sensititivity, well. I mean:

  • When less sensitive, it takes more sound to trigger the device
  • When more sensitive, it takes less sound to trigger the device

Parameter Value
+ 5 V DC from your Arduino
G GND from your Arduino
D0 Connect to Digital Input Pin
A0 Connect to Analog Input Pin
Power LED Illuminates when power is applied
Sound Detect LED Illuminates when sound is detected
Potentiometer CW = More Sensitive
CCW = Less Sensitive

It has four pins that needs to be connected to your Arduino. The top one(if you look at the image above), is AO. This should be connected to the analog input 0 on the Arduino(A0). The one beside that is GND, which is connected to ground, the VCC is connected to +5V, and the last one is DO – which is the digital output of the module, and should be connected to digital pin 2 on the Arduino.

On the top of the sound sensor is a little flathead screw you can turn to adjust the sensitivity and analog output of the sound sensor. To calibrate the sound sensor you can make some noise and keep turning it until you start seeing the sensor-LED on the module starts blinking with the rhythm.

USES FOR THE ARDUINO SOUND DETECTOR

Given that this device measures whether or not sound has exceeded a threshold, you’re basically left with determining what it is you want to do. What I mean by this is that you can do something when it is quiet and/or you can do something when it is loud. For example:

  • You could detect whether or not a motor is running.
  • You could set a threshold on pump sound so that you know whether or not there is cavitation.
  • In the presence of no sound, you might want to create an ambiance by turning on music.
  • In the presence of no sound and no motion, you may go into an energy savings mode and turn off the lights.

Examples

ANALOG DETECT SOUND SENSITIVE LIGHTS

In this example, we will show how to use the analog pin to detect the sound. The microphone sensor will detect the sound intensity of your surroundings and will light up an LED(we use the on-board LED here) if the sound intensity is above a certain threshold.

Connection

Overhere we use the A0 as the analog pin to connect with the sound sensor, build the circuit as 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 Graphical Programming software Mixly and follow the next operations:

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts

Finally, the staus will change to ‘Upload success!’.

Running Result

After uploading this code, when the volume reaches to a certain value, the LED attached to pin 13 on the Uno board will light up. If the sound does not sense very well, try changing the threshold value or changing the sensor sensitivity by rotating the potentiometer.

You can open the Serial Monitor by going to Tools > Serial Monitor or pressing the magnifying glass-button in the Arduino software window.

What prints out is the analog and digital values of from the sound sensor module. The analog value should spike up when a noise occurs and stabilize when it gets quiet again.

Now in the code there is an “AnalogRead(A0) > 600” line that needs to be changed to something very close but higher than the value you get from the Serial Monitor when it is quiet around you. For instance if you see an analog value of 600, then threshold should be changed to perhaps 603 or 605. When a sound occurs, the analog value will rise and go above the threshold value. When that happens your LEDs will turn on. When it gets quiet again the analog value will go back to 603 and the LEDs go dark again.

Byamber

Graphical Programming Tutorial for Arduino – Servo

e a servo arm that can turn 180 degrees. Using the Arduino, we can tell a servo to go to a specified position and it will go there. As simple as that!

Servo motors were first used in the Remote Control (RC) world, usually to control the steering of RC cars or the flaps on a RC plane. With time, they found their uses in robotics, automation, and of course, the Arduino world.

In this lesson, you will learn how to control a servo motor using an Arduino.

Firstly, you will get the servo to sweep back and forth automatically and then you will add a pot to control the position of the servo.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Servo Motor SG90 x 1
  • 10k ohm Potentiometer x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

About Servo

Servo consists of shell, circuit board, non-core motor, gear and location detection.The servo motor has three leads. The color of the leads varies between servo motors, but the red lead is always 5V and GND will either be black or brown. The other lead is the control lead and this is usually orange or yellow. This control lead is connected to digital pin 9.

HOW IT WORK ?

Servos are clever devices. Using just one input pin, they receive the position from the Arduino and they go there. Internally, they have a motor driver and a feedback circuit that makes sure that the servo arm reaches the desired position. But what kind of signal do they receive on the input pin?

It is a square wave similar to PWM. Each cycle in the signal lasts for 20 milliseconds and for most of the time, the value is LOW. At the beginning of each cycle, the signal is HIGH for a time between 1 and 2 milliseconds. At 1 millisecond it represents 0 degrees and at 2 milliseconds it represents 180 degrees. In between, it represents the value from 0–180. This is a very good and reliable method. The graphic makes it a little easier to understand.

WHAT YOU SHOULD NOTE ?

our servo may behave erratically, and you may find that this only happens when the Arduino is plugged into certain USB ports. This is because the servo draws quite a lot of power, especially as the motor is starting up, and this sudden high demand can be enough to drop the voltage on the Arduino board, so that it resets itself.
If this happens, then you can usually cure it by adding a high value capacitor (470uF or greater) between GND and 5V on the breadboard.

LEARN MORE ABOUT THE LIBRARY — SERVO.H

This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

CIRCUIT

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board. Note that servos draw considerable power, so if you need to drive more than one or two, you’ll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together.

Examples

ARDUINO SERVO USE

Servo is a type of geared motor that can only rotate 180 degrees. It is controlled by sending electrical pulses from your Osoyoo Uno board. These pulses tell the servo what position it should move to. At this part, we control the servo motor rotate 90 degrees (rotate once every 15 degrees). And then rotate in the opposite direction.

Connection

As we can see from above, servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino or Genuino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the board.

Build the circuit as 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 Graphical Programming software Mixly and follow the next operations:

Drag out the servo control module from “Actuator”.

“Servo Control Module” description.

Make the servo rotate to a certain angle. At this part, we control the servo motor rotate 90 degrees (rotate once every 15 degrees).

And then rotate in the opposite direction.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts

Finally, the staus will change to ‘Upload success!’.

Running Result

A few seconds after the upload finishes, you should now see the servo motor rotate 90 degrees (rotate once every 15 degrees). And then rotate in the opposite direction.

Byamber

Graphical Programming Tutorial for Arduino – Ultrasonic Range Finder

Introduction

In this lesson, we will show how to make an ultrasonic range finder and display the distance on the screen.

If you want to display the results from the HC-SR04 Ultrasonic Sensor on an I2C LCD you can use the following source.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Ultrasonic Sensor HC-SR04 x 1
  • I2C LCD1602 x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Connection

Before you write the code you have to build the circuit. To do this, connect the pins as follows:

Osoyoo UNO I2C 1602 LCD
GND GND
5V VCC
A4 SDA
A5 SCL

Note:

  • For Mega2560: the I2C connections are on SDA=20 and SCL=21. So go ahead and wire these up, along with the two power leads to the 5V and GND terminals.
  • For Arduino Leonardo: connect SDA to digital pin 2 and SCL to digital pin 3 on your Arduino.

The HC-SR04 ultrasonic range finder has four pins: Vcc, Trig, Echo, and GND. The Vcc pin(Connect to +5V here) supplies the power to generate the ultrasonic pulses. The GND pin is connected to ground. The Trig pin(Connect to D3 here) is where the Arduino sends the signal to start the ultrasonic pulse. The Echo pin(Connect to D2 here) is where the ultrasonic range finder sends the information about the duration of the trip taken by the ultrasonic pulse to the Osoyoo Uno board.

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 Graphical Programming software Mixly and follow the next operations:

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts

Finally, the staus will change to ‘Upload success!’.

Running Result

A few seconds after the upload finishes, move a board close to the sensor or remove it farther. You can see the value displayed on the LCD changes accordingly; it indicates the distance between the board and the ultrasonic sensor.

Byamber

Graphical Programming Tutorial for Arduino – PIR Motion Sensor

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

  • Osoyoo 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

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 Graphical Programming software Mixly and follow the next operations:

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.

Click Save aftogramming is done. Select the board type and serial port before uploading. For instause a Uno board, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.

Select the serial device of the Arduino board from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Next,upload the code. If the uploading fails, check and correct the code according to the prompts.

Finally, the staus will change to ‘Upload success!’.

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.