Monthly Archive:March 2019

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.

Byamber

Graphical Programming Tutorial for Arduino – Ultrasonic Sensor HC-SR04

Introduction

The Ultrasonic Sensor sends out a high-frequency sound pulse and then times how long it takes for the echo of the sound to reflect back. The sensor has 2 openings on its front. One opening transmits ultrasonic waves, the other receives them. In this lesson we will show you how the HC-SR04 Ultrasonic Sensor works and how to use it with the Osoyoo Uno board.

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

About Ultrasonic Sensor HC-SR04

FEATURES OF HC-SR04

  • Power Supply :+5V DC
  • Quiescent Current : <2mA
  • Working Currnt: 15mA
  • Effectual Angle: <15°
  • Ranging Distance : 2cm – 400 cm/1″ – 13ft
  • Resolution : 0.3 cm
  • Measuring Angle: 30 degree
  • Trigger Input Pulse width: 10uS
  • Dimension: 45mm x 20mm x 15mm

WHAT IS ULTRASONIC SENSOR ?

An Ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. By recording the elapsed time between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sonar sensor and the object.

WHAT IS HC-SR04 ?

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

On the front of the ultrasonic range finder are two metal cylinders. These are transducers. Transducers convert mechanical forces into electrical signals. In the ultrasonic range finder, there is a transmitting transducer and receiving transducer. The transmitting transducer converts an electrical signal into the ultrasonic pulse, and the receiving transducer converts the reflected ultrasonic pulse back into an electrical signal. If you look at the back of the range finder, you will see an IC behind the transmitting transducer labelled MAX3232. This is the IC that controls the transmitting transducer. Behind the receiving transducer is an IC labelled LM324. This is a quad Op-Amp that amplifies the signal generated by the receiving transducer into a signal that’s strong enough to transmit to the Arduino.

TIMING DIAGRAM

The timing diagram of HC-SR04 is shown. To start measurement, Trig of SR04 must receive a pulse of high (5V) for at least 10us, this will initiate the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and wait for the reflected ultrasonic burst. When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay for a period (width) which proportion to distance. To obtain the distance, measure the width (Ton) of Echo pin.

Time = Width of Echo pulse, in us (micro second)

  • Distance in centimeters = Time / 58
  • Distance in inches = Time / 148

Or you can utilize the speed of sound, since it is known that sound travels through air at about 344 m/s (1129 ft/s), you can take the time for the sound wave to return and multiply it by 344 meters (or 1129 feet) to find the total round-trip distance of the sound wave. Round-trip means that the sound wave traveled 2 times the distance to the object before it was detected by the sensor; it includes the ‘trip’ from the sonar sensor to the object AND the ‘trip’ from the object to the Ultrasonic sensor (after the sound wave bounced off the object). To find the distance to the object, simply divide the round-trip distance in half.

The time variable is the time it takes for the ultrasonic pulse to leave the sensor, bounce off the object, and return to the sensor. We actually divide this time in half since we only need to measure the distance to the object, not the distance to the object and back to the sensor. The speed variable is the speed at which sound travels through air.

The speed of sound in air changes with temperature and humidity. Therefore, in order to accurately calculate distance, we’ll need to consider the ambient temperature and humidity. The formula for the speed of sound in air with temperature and humidity accounted for is:

For example, at 20 °C and 50% humidity, sound travels at a speed of:

NOTE

The accuracy of Ultrasonic sensor can be affected by the temperature and humidity of the air it is being used in. However, for these tutorials and almost any project you will be using these sensors in, this change in accuracy will be negligible.

It is important to understand that some objects might not be detected by ultrasonic sensors. This is because some objects are shaped or positioned in such a way that the sound wave bounces off the object, but are deflected away from the Ultrasonic sensor. It is also possible for the object to be too small to reflect enough of the sound wave back to the sensor to be detected. Other objects can absorb the sound wave all together (cloth, carpeting, etc), which means that there is no way for the sensor to detect them accurately. These are important factors to consider when designing and programming a robot using an ultrasonic sensor.

Examples

USING THE ULTRASONIC SENSOR HC-SR04 READ DISTANCE FROM THE SERIAL MONITOR

We will start with a simple ultrasonic range finder that measures the output distance to the serial monitor.

Connection

The HC-SR04 ultrasonic range finder has four pins: Vcc, Trig, Echo, and GND. The Vcc pin supplies the power to generate the ultrasonic pulses. The GND pin is connected to ground. The Trig pin is where the Arduino sends the signal to start the ultrasonic pulse. The Echo pin 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:

Set the Serial baudrate as 9600. Declare and initialize a variable “Distance”.

Select the Sensor-Ultransonic block.

Define the trig and echo pins, overlay the measured value of the Ultrasonic to “Distance”.

Add the if_do function, then click the blue gear icon to select the else block.

Drag the and/or block from Logic, select the “or” fuction here.

Determine whether the distance is greater than or equal to 400 or less than or equal to 2.

If the condition is satisfied, the serial will print “Out of range!”.

The purpose of these codes is to output the distance measured by the Ultrasonic sensor, you can check it from the serial output.

With a half-second delay, uno will repeatedly judge the values measured by the sensor and output them from the serial port.

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, open the Serial Monitor, move the baffle, you will see the distance as below:

You will see the result as below:

Byamber

Graphical Programming Tutorial for Arduino – Using an Active Buzzer

Introduction

In this lesson,we will show how to use an active buzzer to make some noise.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • Breadboard x 1
  • Active Bzzer x 1
  • M/M jumpers
  • USB Cable x 1
  • PC x 1

About Buzzer

As a type of electronic buzzer with integrated structure, buzzers, which are supplied by DC power, are widely used in computers, printers, photocopiers, alarms, electronic toys, automotive electronic devices, telephones, timers and other electronic products for voice devices. Buzzers can be categorized as active and passive ones (see the following picture). Turn the pins of two buzzers face up, and the one with a green circuit board is a passive buzzer, while the other enclosed with a black tape is an active one.

The difference between an active buzzer and a passive buzzer is:

An active buzzer has a built-in oscillating source, so it will make sounds when electrified. But a passive buzzer does not have such source, so it will not tweet if DC signals are used; instead, you need to use square waves whose frequency is between 2K and 5K to drive it. The active buzzer is often more expensive than the passive one because of multiple built-in oscillating circuits.In this lesson, we use the active buzzer.

Note:

The active buzzer has built-in oscillating source, so it will beep as long as it is electrified, but it can only beep with a fixed frequency.

Connection

In this part, the only thing on the breadboard is the active buzzer. One pin of the active buzzer goes to GND connection and the other to digital pin 12.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:

This lesson is very similar to the LED lessons,

This program will give a high or low level to the buzzer connected pin 12 to turn it on and off, namelyinking. After programming, you can click the “<" button to check the corresponding code on the right bar.

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 hear the buzzer beep.

Note again:

The active buzzer has built-in oscillating source, so it will beep as long as it is electrified, but it can only beep with a fixed frequency.