About authors

We are writers in avrchip.com. We present the articles on programming and arduino. You can get information on how to program the microcontroller and arduino. How do I write a script language for arduino and avr microcontroller.Most of the authors is an embedded systems engineer, software engineer, and electrical engineer.If you have questions about microcontrollers and arduino, please contact us at writer.avrchip@gmail.com.
Website: http://avrchip.com/
authors has written 22 articles so far, you can find them below.

HC-SR04 Ultrasonic Distance Sensor

hc-sr04-distance-sensor

hc-sr04-distance-sensor

HC-SR04 is one of a proximity sensor. This sensor is very cheap, so many developers that use these sensors to the system they developed.

HC-SR04 can measure distances with ultrasonic wave method. This sensor has two part which is important, namely the transmitter and receiver. The transmitter will throw ultrasonic waves and will be reflected by a particular object. This reflected wave will be captured by the receiver. The delivery time can be determined from the calculation of the transmitting and catching time.

hc-sr04 distance sensor for arduino

hc-sr04 distance sensor for arduino

HC-SR04 has a 4 pin connector: VCC, Trig (T), echo (R), GND. VCC is connected to the voltage of 5V, GND connected to Ground, Trig (T) is connected to the data pin microcontroller, and echo (R) is connected to the data microcontroller (different pin).

– Model: HC-SR04
– Color: Blue + Silver
– Working voltage : 5V(DC)
– Static current: Less than 2mA.
– Output signal: Electric frequency signal, high level 5V, low level 0V.
– Sensor angle: Not more than 15 degrees.
– Detection distance: 2cm~450cm.
– High precision: Up to 3mm
– Mode of connection: VCC / trig(T) / echo(R) / GND
– Module Working Principle:
– Adopt IO trigger through supplying at least 10us sequence of high level signal
– The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal
– If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving

 

hc-sr04 distance sensor and arduino wire

hc-sr04 distance sensor and arduino wire

For example, you can connect Trig (T) pin and echo (R) pin on the Arduino Uno as shown above. In the picture can be seen that Trig is connected to the pin number 11 and the echo is connected to the pin number 12. For source code and the programming tutorial you can read here.

Water Flow Meter Sensor for Arduino

Water flow sensor for arduino tutorial

Water flow sensor for arduino tutorial

Water flow meter sensor is a sensor that can detect the speed of water flow.

One of a flow sensor that is often used is the production of seeedstudio. Water flow meter sensor works based on half-effect sensors that are inside.

Half-effect sensors work by rotation of the turbine that is rotated by the flow of water. Water flow meter sensor is wrapped with a plastic body which has two holes as input and output streams.

Water flow sensor for arduino tutorial

Water flow sensor for arduino tutorial

Specifications Water Flow Meter Sensor

Mini. Wokring VoltageDC 4.5V
Max. Working Current15mA(DC 5V)
Working Voltage5V~24V
Flow Rate Range1~30L/min
Load Capacity≤10mA(DC 5V)
Operating Temperature≤80℃
Liquid Temperature≤120℃
Operating Humidity35%~90%RH
Water Pressure≤2.0MPa
Storage Temperature-25℃~+80℃
Storage Humidity25%~95%RH

 

Water flow datasheet

Water flow datasheet

Water flow arduino datasheet

Water flow arduino datasheet

Components of the water flow meter sensor

No.NameQuantityMaterialNote
1Valve body1PA66+33%glass fiber
2Stainless steel bead1Stainless steel SUS304
3Axis1Stainless steel SUS304
4Impeller1POM
5Ring magnet1Ferrite
6Middle ring1PA66+33%glass fiber
7O-seal ring1Rubber
8Electronic seal ring1Rubber
9Cover1PA66+33%glass fiber
10Screw4Stainless steel SUS3043.0*11
11Cable11007 24AWG

 

You can read data from these sensors water flow meter with arduino. For example, the schematic diagram will assist you in arranging a water flow meter in the arduino.

water-flow-sensor-for-arduino

water-flow-sensor-for-arduino

RS232 with MAX232 Schematics and Tutorial

RS232 is a serial communication standard that is used to connect peripherals to the peripherals. Also called the Path I / O (input / output).

The best example we often encounter is a connection between a computer with a modem, or a computer with a mouse can even also between the computer and the computer are all normally connected via the RS232 serial port. This standard uses several tools in its implementation. The most commonly used is a plug / connector DB9 or DB25. For RS232 with DB9 connector, typically used for mouse, modem, cashier registers, etc., while the DB25 connector, typically used for joystick games.

RS232 standards set by the Electronic Industry Association and Telecommunications Industry Association in 1962. 

The function of the serial RS232 port is for connecting / connections from one device to another device, or equipment standards concerning the communication of data between computers by means of computer peripherals. That other devices such as modem, mouse, cash registers and so forth. Serial RS232 port on a DB9 connector has a pin 9 units and the DB25 connector has a pin 25 pieces.

RS232 was made in 1962, long before the popular TTL IC, therefore the voltage level specified for RS232 has nothing to do with TTL voltage levels, and even can be said to be much different. TTL Serial communications work at a voltage of 5V to + 5V RS232 serial communication while working at a voltage of + 25V to -25V.

All microcontroller using TTL serial communications topologies. While some devices using RS232 serial topology. Therefore, you must create a device for connecting two different topologies so that both can communicate.

rs232 schematics tutorial with max232

rs232 schematics tutorial with max232

The circuit above is a TTL into RS232 serial converter or RS232 into TTL serial converter. So that the circuit can connect a microcontroller with RS232 devices such as modems or other devices. You can create a series of mini-RS232 converter IC MAX232 and some capacitors 1uF as shown following circuit. As an interface port, you can use a DB9 connector or just a pin header.

rs232-board-and-schematics-tutorial-with-max232

rs232-board-and-schematics-tutorial-with-max232

USBasp AVR Microcontroller Downloader Schematics

avr-microcontroller-schematics-downloader

avr-microcontroller-schematics-downloader

This USBasp downloader can be used on the AVR microcontroller families such as ATMega8, ATmega16, ATMega8535, ATmega32, ATmega128 and much more. Based on Atmega8 (or can also be used ATMega88) and some additional components.

USB connector as the interface with a computer and five pins as an interface with a microcontroller. The USBasp’s hardware is very easy to make. Once you finish making the hardware, you should fill the ATMega8’s memory with two firmware program that will be filled in eeprom microcontroller ATmega8.

After that, USBasp downloader has been ready for use. To download the program, you must compile into .hex file using BASCOM AVR or CAVR.

And you can transfer files with the .hex downloader software like avrdude, USBasp, khazama, PonyProg or other programs.

avr microcontroller BOARD schematics downloader

avr microcontroller BOARD schematics downloader

Arduino Uno R3 the Computing Platform

Arduino is a trademark that manufactures microcontroller development board. Arduino UNO is one type of development board produced by Arduino, and the new series is arduino uno R3.

arduino-uno-r3-board

arduino-uno-r3-board

Arduino UNO R3 is a computing platform that is very easy to use. Arduino UNO R3 is ATmega328P microcontroller based. According datasheet from ATmega328P, Arduino UNO R3 has a 14 pin digital input / output, and 6 of them can be used as PWM output pin. Arduino UNO R3 also has 6 analog inputs, has a 16MHz crystal, a USB port which can be used to download the program, a power jack, a reset button, and ICSP header.

how to optimized the arduino uno r3

how to optimized the arduino uno r3

 

Arduino features shown in the diagram above.

Arduino UNO R3 provide + 5V, 3.3V and GND pin as a power source if needed by sensors or other devices. Users can also use the SDA and SCL pins on the pin number 27 and 28. Features ADC (Analog to Digital Converter) can be used on 23-28 pins. While the interrupt feature can be used on pin number 4 and 5 (pin number 4 is int0 and pin number 5 is int1). Serial communication (RX and TX) is provided on pin numbers 2 and 3.

arduino uno r3 layout diagram

arduino uno r3 layout diagram

 

Arduino Uno R3 design is very simple to facilitate the user in using it. On the left we will see an electric jack socket. Power jack is compatible to the power supply voltage 9-12V. In addition, we will see the USB port to communicate with a computer, either in downloading a program or data transfer via USB. As an indicator, arduino provides 4 LEDs. 1 for the power indicator, two LED indicators for serial communication (RX and TX), and 1 other LED connected at pin 13.

 

arduino uno r3 microcontroller pin mapping

arduino uno r3 microcontroller pin mapping

 

The ATmega328 microcontroller datasheet shows the various features that can be used on the Arduino UNO R3.

 

arduino uno r3 board layout

arduino uno r3 board layout

Build Your Own Hexapod Robot

servo-for-hexapod-robot

servo-for-hexapod-robot

Hexapod robot is a robot that has six legs.

Hexapod robot is used for through steep terrain or rocky areas. Wheeled robots can’t pass through the rocky and steep area. Therefore hexapod robot designed to replace wheeled robots in this area. Hexapod robot inspired by spider legs. Six feet make a robot stable and has a smooth movement. The movement of the robot will be smoother if more joints on the robot.

Each robot joints filled by a servo motor.

Servo motor allows a movement like a joint in humans or animals. However, in general, the servo will only make one-way direction movement (right-left). So if you are going to make a four-way movement (right-left-front-back) then it must be made of two joints.

In general, a hexapod robot has three joints on each leg. So you need eighteen servo to make a hexapod robot.

how to make hexapod robot mechanics

how to make hexapod robot mechanics

Now many companies that sell body hexapod robot. So you do not have to bother making mechanics. Part of the body of the robot is shown in the image above. There are five different robot parts. To make a joint, you can use a servo Tower Pro SG90 as used in the hexapod robot in the picture No. 1. But the selection of servo should be tailored to the needs of torque. If the load of the robot is heavy, then you should use a servo with greater torque.

small servo for hexapod robot

small servo for hexapod robot

Source Code for Arduino Servo Control

tower-pro-sg90-servo-and-arduino-uno-wiring-cable-tutorial

tower-pro-sg90-servo-and-arduino-uno-wiring-cable-tutorial

Servo is one type of motor controlled by a frequency signal. However, some types of servo have different ways to control it. Because each type of servo have different degrees of movement.

For example, I use a servo Tower Pro SG90 and controlled using the Arduino UNO. Servo Tower Pro SG90 this has the following specifications (or you can read here for more details):

Tiny and lightweight with high output power. Servo can rotate approximately 180 degrees (90 in each direction), and works just like the standard kinds but smaller. You can use any servo code, hardware or library to control these servos. Good for beginners who want to make stuff move without building a motor controller with feedback & gear box, especially since it will fit in small places. It comes with a 3 horns (arms) and hardware.

Tower Pro SG90 Specifications :
Weight: 9 g
Dimension: 22.2 x 11.8 x 31 mm approx.
Stall torque: 1.8 kgf·cm
Operating speed: 0.1 s/60 degree
Operating voltage: 4.8 V (~5V)
Dead band width: 10 μs
Temperature range: 0 °C – 55 °C

 

Tower Pro SG90 Servo characteristic : Position “0” (1.5 ms pulse) is middle, “90” (~2 ms pulse) is all the way to the right, “-90” (~1ms pulse) is all the way to the left.

This is the Arduino Source Code for the Sweep Mode Servo :

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}

ATMega16 Schematic Circuit Tutorial

avr-atmega16-minimum-system-schematic-circuit

avr-atmega16-minimum-system-schematic-circuit

Many projects can be built from a microcontroller such as control and monitoring project.

AVR ATmega16 can work when there are several supporting components such as resistors and capacitors in the circuit. ‘Reset’ feature on ATmega16 microcontroller must pull up using resistors (Also applies to the other AVR ATMega microcontroller). The series of pull up on the reset button typically use 4.7 Kohm resistor and stabilized with 100nF capacitor.

For AVR ATmega16 You can use up to 16 MHz crystal. But if you use the AVR ATMega16L you can only use 0-8MHz. Crystal components is enclosed by two capacitors whose capacity is set in microcontroller datasheet. However, it is usually used 22pF.

The downloader pin must be arranged  like the downloader standart pin (MOSI, MISO, SCK, RESET, GROUND).

Once you complete all the components of the minimum system, the microcontroller you’ve been able to work properly.

Source Code for Arduino LCD Keypad Shield

lcd keypad shield - datasheet

lcd keypad shield – datasheet

Here is the Arduino programming tutorial for LCD keypad shield. Arduino LCD keypad shield used is described in this article.

How to install LCD keypad shield on arduino uno simply by plugging in the arduino board. This tutorial will explain 3 arduino program. The first source code explains how to display characters on the LCD shield. Source code number two explains how to read keys on the keypad shield. And source code number three is the incorporation of lcd shield source code and keypad shield source code.

Source code to display characters on the LCD

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print(“avrchip.com”); // print a simple message
}

void loop()
{
lcd.setCursor(9,1); // move cursor to second line “1” and 9 spaces over
lcd.print(millis()/1000); // display seconds elapsed since power-up

}

 

 

Source code to read keys on keypad shield

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
// define some values used by the panel and buttons
int button = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;

// For V1.0 comment the other threshold and use the one below:
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
*/
return btnNONE; // when all others fail, return this…
}

void setup()
{

}

void loop()
{
button = read_LCD_buttons(); // read the buttons
}

 

LCD keypad shield source code

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;

// For V1.0 comment the other threshold and use the one below:
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
*/
return btnNONE; // when all others fail, return this…
}

void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print(“Push the buttons”); // print a simple message
}

void loop()
{
lcd.setCursor(9,1); // move cursor to second line “1” and 9 spaces over
lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons

switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
lcd.print(“RIGHT “);
break;
}
case btnLEFT:
{
lcd.print(“LEFT “);
break;
}
case btnUP:
{
lcd.print(“UP “);
break;
}
case btnDOWN:
{
lcd.print(“DOWN “);
break;
}
case btnSELECT:
{
lcd.print(“SELECT”);
break;
}
case btnNONE:
{
lcd.print(“NONE “);
break;
}
}

}

Arduino Nano Datasheet and Tutorial

arduino-nano-configuration

arduino-nano-configuration

Arduino Nano is a function module which is very small but has a lot of advantages. The shape is very small so it is suitable to make a project that looks small. Arduino Nano is very special because of this support with breadboards. You can plug arduino and other electronic components in one breadborad. In the Arduino Nano 2.x version, still used avr ATmega168 microcontroller while the Arduino Nano 3.x version already used avr ATmega328 microcontroller.

arduino nano tutorial

arduino nano tutorial

Arduino Nano has features and functions similar to arduino Duemilanove. But Arduino Nano in different packaging. Arduino nano does not have a DC jack so that its power supplied through mini-B USB port or directly connect to the VCC pin and GND. Arduino Nano can be supplied with a voltage of 6-20V power source via USB mini-B port. Or you can provide a voltage of 5V on pin 30 (this voltage will not be adjusted by the regulator, so make sure you provide 5V voltage)

arduino nano pin configuration

arduino nano pin configuration

Arduino Nano Specifications:

MicrocontrollerAtmel ATmega168 or ATmega328
Operating Voltage (logic level)5 V
Input Voltage (recommended)7-12 V
Input Voltage (limits)6-20 V
Digital I/O Pins14 (of which 6 provide PWM output)
Analog Input Pins8
DC Current per I/O Pin40 mA
Flash Memory16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB used by bootloader
SRAM1 KB (ATmega168) or 2 KB (ATmega328)
EEPROM512 bytes (ATmega168) or 1 KB (ATmega328)
Clock Speed16 MHz
Dimensions0.73″ x 1.70″
Length45 mm
Width18 mm
Weigth5 g

 

 

arduino nano datasheet

arduino nano datasheet

In some cases, Arduino Nano has features that are more complete than arduino uno. Arduino Nano has 8 channel ADC (Analog to Digital Converter) while the Arduino Uno only has 6 channels. Through the RX and TX pins you can communicate serially with other devices. According datasheet ATmega328 AVR microcontroller, Arduino Nano has 2 pin interrupt, namely int0 and int1.

arduino nano pin input output configuration

arduino nano pin input output configuration

Overall, Arduino nano has 30 pins. The 8 pin of them (19-26 pin) are Analog pins (ADC). While the other 14 pins are Digital pins (Please see the picture above to see the position of digital and analog pins).

arduino nano connected to computer

arduino nano connected to computer

You have to write the source code for arduino nano on Arduino IDE sofftware. Then, you can download the program on an Arduino Nano using a USB-B cable.