Project under construction. Please revisit the blog later !
Monday, December 21, 2015
Tuesday, December 15, 2015
Monday, November 30, 2015
Wednesday, November 25, 2015
Friday, November 13, 2015
Sunday, October 25, 2015
Monday, October 19, 2015
ARTICLE #8 Control a Servo Motor Using Infrared Receiver Sensor and Remote Control
Circuit wiring :
Project parts :
To realize this project you will need :
- 1 Arduino Uno.
- 1 Breadboard.
- 1 IR Receiver Sensor ( TSOP38238).
- 1 Mini Remote Control.
- 1 Servo Motor.
- Connector wires.
Wiring :
Code
#include <IRremote.h>
#include <Servo.h>
int RECV_PIN = 5;
Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;
int i=0;
void setup() {
servo.attach(9);
servo.write(0);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if(irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if(results.value == 0xFD609F){
i+=10;
servo.write(i);
delay(200);
}
if(results.value == 0xFD20DF){
i-=10;
servo.write(i);
delay(200);
}
irrecv.resume();
}
delay(50);
}
#include <Servo.h>
int RECV_PIN = 5;
Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;
int i=0;
void setup() {
servo.attach(9);
servo.write(0);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if(irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if(results.value == 0xFD609F){
i+=10;
servo.write(i);
delay(200);
}
if(results.value == 0xFD20DF){
i-=10;
servo.write(i);
delay(200);
}
irrecv.resume();
}
delay(50);
}
Sunday, October 11, 2015
ARTICLE #7 Tilt sensor
What is a tilt sensor ?
Next time when you play Tomb Raider on your PS3, you are controlling the movements of Lara Croft with the analogue joystick, remember that you are using a bunch of tilt sensors.These sensors allow the movement of your thumb on the joystick be transformed into the movements you see on the screen when you are playing.
The tilt sensor, usually called tilt switch, is a small low-power 2-pin electrical device that simply indicates if a system is inclined or not in reference to earth’s surface. It is its simplicity that made it popular for many applications in robotics, Aircraft Flight Controls, automotive systems …etc.
In this article, we will explore in depth the functioning of the tilt sensor by making a simple project. But first, here are some features of this device.
Some features of the tilt sensor :
How does a tilt sensor work :
Circuit wiring :
Project parts :
To realize this project you will need :
- 1 Arduino Uno.
- 1 Breadboard.
- 1 Tilt sensor.
- 1 LED.
- 2 Resistors.
- Connector wires.
Wiring :
In this project, the tilt sensor can sense the orientation of the circuit. It turns the LED on when the circuit is turned upside down.
Connect the parts of the circuit as seen in the picture below.
Notice that I connected the tilt sensor pin to a pull-up resistor. So the pin takes the logic value “1” when the switch is open and value “0” when the switch is closed.
Connect the parts of the circuit as seen in the picture below.
Notice that I connected the tilt sensor pin to a pull-up resistor. So the pin takes the logic value “1” when the switch is open and value “0” when the switch is closed.
Code :
int led = 10;
int tilt = 4;
void setup() {
pinMode(led, OUTPUT);
pinMode(tilt, INPUT);
}
void loop() {
int tiltVal = digitalRead(tilt);
if(tiltVal == 1)
digitalWrite(led, HIGH);
else
digitalWrite(led, LOW);
}
Tuesday, September 29, 2015
ARTICLE #6 : Using L293D dual H bridge motor driver with Arduino
Introduction :
The L293D H bridge is a simple circuit that
allows the Arduino board to control two independent DC motors (also steppers
and servos). So, for example in a robotics application, by connecting each DC
motor to a robot’s wheel you will be able to program it to drive forward,
backward and turn left or right. You can also control the rotation speed of the
motors by connecting them to the PWM pins instead of the digital pins as we
will see in the present tutorial.
L293D features and pin description :
The L293D H bridge is a device designed to control two DC motors from
4.5V to 36V simultaneously. It can provide bidirectional currents up to 600 mA.
All its pins are TTL compatible and it can work in a temperature range from
-65°C to 150°C.
You can find all electrical features and other technical informations by
viewing the datasheet.
pinout description diagram :
- L239D has two pin groups, pins from 1 to 8 used for the right motor and pins from 9 to 15 for the left one.
- Vss is the device’s working voltage.
- Vs is the motors supply voltage, it varies from 6V to 12V depending on the motor type.
- Enable pins are used to
activate the pin groups of each side of the L293D. If Enable pin is low, the output pin
will be at 0 always. If it is high, output depends
on input. In this tutorial, enable pins are connected to logical level one
from the start.
- Input pins :
Inputs 1, 2, 3 and 4 are
connected to digital I/O pins of the Arduino. They are the pins that are used
in the program code to control the output pins.
- Output pins :
Output 1 (Pin 3) -------
> Negative Terminal lead of Right Motor
Output 2 (Pin 6) ------- > Positive Terminal lead of Right Motor
Output 3 (Pin 10) ------- > Positive Terminal lead of Left
Motor
Output 4 (Pin 14) ------- > Negative Terminal lead of Left
Motor
INPUT
1
|
INPUT
2
|
INPUT
3
|
INPUT
4
|
OUTPUT
1
|
OUTPUT
2
|
OUTPUT
3
|
OUTPUT
4
|
MOTOR
OUTPUTS
|
MOVEMENT
|
|
RIGHT
|
LEFT
|
|||||||||
LOW
|
HIGH
|
HIGH
|
LOW
|
0
|
Vss
|
Vss
|
0
|
Straight
|
Straight
|
Forward
|
LOW
|
HIGH
|
LOW
|
HIGH
|
0
|
Vss
|
0
|
Vss
|
Straight
|
Reverse
|
Turn
left
|
HIGH
|
LOW
|
HIGH
|
LOW
|
Vss
|
0
|
Vss
|
0
|
Reverse
|
Straight
|
Turn
right
|
HIGH
|
LOW
|
LOW
|
HIGH
|
Vss
|
0
|
0
|
Vss
|
Reverse
|
Reverse
|
Backward
|
Circuit wiring :
Project parts :
In this project, you will need :
- 1 breadboard.
- 1 Arduino Uno.
- 1 L293D H-bridge motor controller.
- 2 DC motors.
- 9V battery.
- Wire connectors.
Wiring :
As seen in the image below, there are two DC motors connected to the for output pins of the L293D H-bridge.each of these outputs is controlled by an input pin as described in the previous table, and we connect all these input pins to the microcontroller's pins.
Enable1 and enable2 pins, as well as Vss pin are connected to the 5V supply voltage of Arduino. Vs (pin No 8) is connected to 9V battery that is used to supply the two DC motors.
The for remaining pins are connected to the ground.
Enable1 and enable2 pins, as well as Vss pin are connected to the 5V supply voltage of Arduino. Vs (pin No 8) is connected to 9V battery that is used to supply the two DC motors.
The for remaining pins are connected to the ground.
Code :
This program below makes the DC motors to both turn in one sens to perform the driving forward behavior of a wheeled robot, then turn in the other sens to perform a backward movement. When motors turn in opposite senses it performs a turn left or right movement. And finally it stops when both motors stop turning.
To be able to control the turning speed of DC motors, you just have to connect the 4 input pins to PWM pins of the microcontroller. you should also use analogWrite function in place of digitalWrite.
In a future development of this tutorial, I will enhance the previous system by adding a potentiometer that enables the user to increase or decrease the speed of these DC motors. I will add a picture of this project as well as the code when I finish writing it. Stay tuned!
// Use this code to test your motor with the Arduino board:
// ---------------------------------------------------------- Motors pin declaration
int motor_left[] = {11, 10};
int motor_right[] = {9, 6};
int delay_sec = 10000;
// ----------------------------------------------------------- Setup function
void setup() {
Serial.begin(9600);
// Initializing motors as outputs
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
}
// ------------------------------------------------------------ Loop function
void loop() {
drive_forward();
delay(delay_sec);
motor_stop();
Serial.println("1");
drive_backward();
delay(delay_sec);
motor_stop();
Serial.println("2");
turn_left();
delay(delay_sec);
motor_stop();
Serial.println("3");
turn_right();
delay(delay_sec);
motor_stop();
Serial.println("4");
motor_stop();
delay(delay_sec);
motor_stop();
Serial.println("5");
}
// ----------------------------------------------------------- Drive functions
void motor_stop(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], LOW);
delay(25);
}
void drive_forward(){
analogWrite(motor_left[0], HIGH);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], HIGH);
analogWrite(motor_right[1], LOW);
}
void drive_backward(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], HIGH);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], HIGH);
}
void turn_left(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], HIGH);
analogWrite(motor_right[0], HIGH);
analogWrite(motor_right[1], LOW);
}
void turn_right(){
analogWrite(motor_left[0], HIGH);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], HIGH);
}
// ---------------------------------------------------------- Motors pin declaration
int motor_left[] = {11, 10};
int motor_right[] = {9, 6};
int delay_sec = 10000;
// ----------------------------------------------------------- Setup function
void setup() {
Serial.begin(9600);
// Initializing motors as outputs
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
}
// ------------------------------------------------------------ Loop function
void loop() {
drive_forward();
delay(delay_sec);
motor_stop();
Serial.println("1");
drive_backward();
delay(delay_sec);
motor_stop();
Serial.println("2");
turn_left();
delay(delay_sec);
motor_stop();
Serial.println("3");
turn_right();
delay(delay_sec);
motor_stop();
Serial.println("4");
motor_stop();
delay(delay_sec);
motor_stop();
Serial.println("5");
}
// ----------------------------------------------------------- Drive functions
void motor_stop(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], LOW);
delay(25);
}
void drive_forward(){
analogWrite(motor_left[0], HIGH);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], HIGH);
analogWrite(motor_right[1], LOW);
}
void drive_backward(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], HIGH);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], HIGH);
}
void turn_left(){
analogWrite(motor_left[0], LOW);
analogWrite(motor_left[1], HIGH);
analogWrite(motor_right[0], HIGH);
analogWrite(motor_right[1], LOW);
}
void turn_right(){
analogWrite(motor_left[0], HIGH);
analogWrite(motor_left[1], LOW);
analogWrite(motor_right[0], LOW);
analogWrite(motor_right[1], HIGH);
}
Sunday, September 13, 2015
ARTICLE #5 - Control an Arduino from MATLAB
Introduction :
MATLAB is a technical computing software and also a high level
programming language widely used by engineers and scientists in many fields to
perform mathematical computation, algorithm development, simulation, analysis
and data visualization and also GUI application development.
In this tutorial we will learn how to interface Matlab with the Arduino
board.it simply means that you will use Matlab software to communicate with
your Arduino board without using the Arduino IDE. So you will directly write
the commands on the Matlab command window, send them to the Arduino board via
the USB cable wich will then execute these commands and send back the results.
We will use Matlab built-in specific Arduino commands to write a simple
blinking LED program, then we will write another program that reads the surrounding
temperature using a TMP36 sensor (you can click here to see my previousarticle about the TMP36 temperature sensor) and also we will build a simple GUI
application that plots this temperature data in a 2D graph.
Project parts :
Software :
- MATLAB
- MATLAB support package for Arduino
Hardware
- Arduino Uno
- 1 Breadboard
- 1 Red LED
- 1 TMP36 temperature sensor
- Wire connectors
Interfacing steps :
To install the MATLAB and Simulink hardware
support packages for Arduino in the 2014a version and later releases, you click
on “Add-ons” in “Home” tab, choose “Get hardware support packages”. Then from
the “Support Package installer” window you click on “Install from internet” and
you click on “Next”, after that you search for “Arduino” in the scroll bar section
and you click on it, check all the three install boxes of the packages and you
click “Next”. This launches the support packages installation, you follow the installation steps until it finishes.
After the support packages were downloaded,
we will test if all of this works fine. Connect the Arduino board to your PC. Under
the MATLAB command window, you create an Arduino object by typing the following
command line :
a = arduino(‘comX’,‘uno’)
(Where X should be replaced by the correspondent
COM port of your Arduino)
You should see the following text once you
click “ENTER” button :
Attempting connection .............
Basic I/O Script detected !
Arduino successfully connected !
Basic I/O Script detected !
Arduino successfully connected !
This object can now perform digital and analog I/O functions and utilize
all the functions specified by the arduino.m library.
Circuit wiring 1 : Blinking LED
Subscribe to:
Posts (Atom)