Archives for 

how to

Arduino Source Code for Water Flow Meter Sensor

water-flow-arduino-tutorial

water-flow-arduino-tutorial

As described in the article Water Flow Meter Sensor, this sensor can detect the flow of water passing through the sensor.

This sensor has three wires (red, black and yellow). Red cable is connected to VCC. Black cable is connected to GND. And the yellow cable is connected to the arduino data pin (digital pin number 2) but you will need to pull up this cable with a 10k resistor.

Once you finish making the hardware, you should upload this program to the Arduino software IDE.

The program will calculate the flow rate and sends it via the serial port (USB cable). To view the sensors data, you must connect a computer with the Arduino and see it through the terminal on the Arduino IDE software.

 

Arduino Program Source Code for Water Flow Meter Sensor :

volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor

void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the

hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup() //
{
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is

initialised,
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate

in L/hour
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (” L/hour\r\n”); //Prints “L/hour” and returns a new line
}

SG90 Tower Pro Servo Datasheet

servo-for-arduino-sg90-tower-pro

servo-for-arduino-sg90-tower-pro

One type of electric motor is a servo. Servo motor is used to make mechanical robotic or automated devices. Servo work based on the frequency signal from the controller (such as a microcontroller or arduino).

SG90 Tower Pro servo motor can also be controlled by a ruspberry pi.

You can plug this SG90 Tower Pro Servo straight onto the raspberry pi GPIO pins 4,6,8 without some extra wires. Pin 8 on the raspberry pi is normally the UART Tx pin, so your SG90 Tower Pro servo will not work properly if you connect it without disabling the UART before running the main program, You can search the instructions for how to disabling the UART on pin 8 from google.

sg90 tower pro servo cable pin

sg90 tower pro servo cable pin

Each servo motor cables have different pin configurations. Tower Pro SG90 servo has a three-pin cable. Red cable is wired VCC. Black/brown cable is a ground cable. While the orange cable is a signal cable.

You can find the SG90 Tower Pro servo tutorial and arduino uno source code here.

AVR ATMega128 Schematic Circuit Adapter DIY

avr-atmega128-schematic-and-board-adapter

avr-atmega128-schematic-and-board-adapter

ATmega128 is one of the AVR microcontroller. Large memory (128KBytes) can be used to make a big project.

For example, if you create a storage system using the MMC and use BASCOM AVR as the programming language, then you have to load a very large libraries into the memory of the microcontroller. And this can not be done if you are using a microcontroller with a small memory such as ATMega16 or ATMega8535. Therefore, you can try using AVR ATmega128 to complete your major project.

However, you would have difficulty in assembling and soldering components on this ATmega128 microcontroller. This is because ATmega128 an SMD component. And you must be able to make a double layer PCB if you want to use a ATmega128 microcontrollers and use part of DIP components (such as IC MAX232 or another).

If you want to combine the two types of these components, then I have tips for you. Make two single PCB layer and combine with pin headers. The first is an adapter PCB for ATmega128 microcontroller and the second is used for the other DIP components. And then combine it with pin header (male and female pin header). You can see PCB adapter for ATmega128 microcontroller in the picture.

DIY – Do It Yourself project

Hopefully this tutorial ( AVR ATMega128 Schematic Circuit Adapter DIY ) can help you in completing the project.

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

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.