The Best Twenty Six Project With The Arduino PDF
The Best Twenty Six Project With The Arduino PDF
THE ARDUiNO
sensor we have seen in our life. First I will tell you what
Arduino is doing. We can easily
NECESSARY MATERIALS:
ARDUINO
4 LEDs
5 PCS 220 OHM RESISTANCE
1 PIECE BUZZER
BREAD BOARD
QUANTITY JUMPER CABLE
Scheme showing the links of our Project
Deviation Codes:
int sure ;
int mesafe ;
void setup() {
pinMode(aled , OUTPUT);
pinMode(bled , OUTPUT);
pinMode(cled , OUTPUT);
pinMode(dled , OUTPUT);
pinMode(buzzer , OUTPUT
pinMode(trigger_pin , OUTPUT);
pinMode(echo_pin , INPUT);
void loop()
digitalWrite(trigger_pin , HIGH);
delayMicroseconds(1000); //
digitalWrite(trigger_pin , LOW);
digitalWrite(aled , HIGH);
digitalWrite(bled , HIGH);
digitalWrite(cled , HIGH);
digitalWrite(dled , HIGH);
digitalWrite(buzzer , HIGH);
delay(250);
digitalWrite(buzzer , LOW);
digitalWrite(aled , LOW);
digitalWrite(bled , HIGH);
digitalWrite(cled , HIGH);
digitalWrite(dled , HIGH);
digitalWrite(buzzer , HIGH);
delay(500);
digitalWrite(buzzer , LOW);
digitalWrite(aled , LOW);
digitalWrite(bled , LOW);.
digitalWrite(cled , HIGH);
digitalWrite(dled , HIGH);
digitalWrite(buzzer , HIGH);
delay(750);
digitalWrite(buzzer , LOW);
else
digitalWrite(aled , LOW);
digitalWrite(bled , LOW);
digitalWrite(cled , LOW);
digitalWrite(dled , HIGH);
}
http://www.thingiverse.com/thing:1009659
http://www.instructables.com/id/DIY-Spider-RobotQuad-robot-
Quadruped/step1/Test-the-main-board/
Parts Required:
1x body_d.stl
1x body_u.stl
2x coxa_l.stl
2x coxa_r.stl
2x tibia_l.stl
2x tibia_r.stl
4x femur_1.stl
8x s_hold.stl
Now all the plastic parts are going to be assembled after the
punch. The first thing you need to do is to insert the servo
motors into the places where you need to enter, remove the 4
screws under the servos and lift the lid so as not to damage the
servo cable. Screw in the cover again after inserting the servo
into place.
Arduino Code:
http://www.instructables.com/id/DIY-Spider-RobotQuad-robot-
Quadruped/step13/It-is-showtime/
/* Includes ------------------------------------------------------------------*/
#include <Servo.h> //to define and control servos
#include <FlexiTimer2.h>//to set a timer to manage all servos
/* Servos --------------------------------------------------------------------*/
//define 12 servos for 4 legs
Servo servo[4][3];
//define servos' ports
const int servo_pin[4][3] = { {2, 3, 4}, {5, 6, 7}, {8, 9, 10}, {11, 12, 13}
};
/* Size of the robot ---------------------------------------------------------*/
const float length_a = 55;
const float length_b = 77.5;
const float length_c = 27.5;
const float length_side = 71;
const float z_absolute = -28;
/* Constants for movement ----------------------------------------------------*/
const float z_default = -50, z_up = -30, z_boot = z_absolute;
const float x_default = 62, x_offset = 0;
const float y_start = 0, y_step = 40;
/* variables for movement ----------------------------------------------------*/
volatile float site_now[4][3]; //real-time coordinates of the end of each
leg
volatile float site_expect[4][3]; //expected coordinates of the end of each
leg
float temp_speed[4][3]; //each axis' speed, needs to be recalculated before
each movement
float move_speed; //movement speed
float speed_multiple = 1; //movement speed multiple
const float spot_turn_speed = 4;
const float leg_move_speed = 8;
const float body_move_speed = 3;
const float stand_seat_speed = 1;
volatile int rest_counter; //+1/0.02s, for automatic rest
//functions' parameter
const float KEEP = 255;
//define PI for calculation
const float pi = 3.1415926;
/* Constants for turn --------------------------------------------------------*/
//temp length
const float temp_a = sqrt(pow(2 * x_default + length_side, 2) +
pow(y_step, 2));
const float temp_b = 2 * (y_start + y_step) + length_side;
const float temp_c = sqrt(pow(2 * x_default + length_side, 2) + pow(2 *
y_start + y_step + length_side, 2));
const float temp_alpha = acos((pow(temp_a, 2) + pow(temp_b, 2) -
pow(temp_c, 2)) / 2 / temp_a / temp_b);
//site for turn
const float turn_x1 = (temp_a - length_side) / 2;
const float turn_y1 = y_start + y_step / 2;
const float turn_x0 = turn_x1 - temp_b * cos(temp_alpha);
const float turn_y0 = temp_b * sin(temp_alpha) - turn_y1 - length_side;
/* ---------------------------------------------------------------------------*/
/*
- setup function
---------------------------------------------------------------------------*/
void setup()
{
//start serial for debug
Serial.begin(115200);
Serial.println("Robot starts initialization");
//initialize default parameter
set_site(0, x_default - x_offset, y_start + y_step, z_boot);
set_site(1, x_default - x_offset, y_start + y_step, z_boot);
set_site(2, x_default + x_offset, y_start, z_boot);
set_site(3, x_default + x_offset, y_start, z_boot);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
site_now[i][j] = site_expect[i][j];
}
}
//start servo service
FlexiTimer2::set(20, servo_service);
FlexiTimer2::start();
Serial.println("Servo service started");
//initialize servos
servo_attach();
Serial.println("Servos initialized");
Serial.println("Robot initialization Complete");
}
void servo_attach(void)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
servo[i][j].attach(servo_pin[i][j]);
delay(100);
}
}
}
void servo_detach(void)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
servo[i][j].detach();
delay(100);
}
}
}
/*
- loop function
---------------------------------------------------------------------------*/
void loop()
{
Serial.println("Stand");
stand();
delay(2000);
Serial.println("Step forward");
step_forward(5);
delay(2000);
Serial.println("Step back");
step_back(5);
delay(2000);
Serial.println("Turn left");
turn_left(5);
delay(2000);
Serial.println("Turn right");
turn_right(5);
delay(2000);
Serial.println("Hand wave");
hand_wave(3);
delay(2000);
Serial.println("Hand wave");
hand_shake(3);
delay(2000);
Serial.println("Sit");
sit();
delay(5000);
}
/*
- sit
- blocking function
---------------------------------------------------------------------------*/
void sit(void)
{
move_speed = stand_seat_speed;
for (int leg = 0; leg < 4; leg++)
{
set_site(leg, KEEP, KEEP, z_boot);
}
wait_all_reach();
}
/*
- stand
- blocking function
---------------------------------------------------------------------------*/
void stand(void)
{
move_speed = stand_seat_speed;
for (int leg = 0; leg < 4; leg++) { set_site(leg, KEEP, KEEP, z_default); }
wait_all_reach(); } /* - spot turn to left - blocking function - parameter
step steps wanted to turn ---------------------------------------------------------
------------------*/ void turn_left(unsigned int step) { move_speed =
spot_turn_speed; while (step-- > 0)
{
if (site_now[3][1] == y_start)
{
//leg 3&1 move
set_site(3, x_default + x_offset, y_start, z_up);
wait_all_reach();
set_site(0, turn_x1 - x_offset, turn_y1, z_default);
set_site(1, turn_x0 - x_offset, turn_y0, z_default);
set_site(2, turn_x1 + x_offset, turn_y1, z_default);
set_site(3, turn_x0 + x_offset, turn_y0, z_up);
wait_all_reach();
/*
- spot turn to right
- blocking function
- parameter step steps wanted to turn
---------------------------------------------------------------------------*/
void turn_right(unsigned int step)
{
move_speed = spot_turn_speed;
while (step-- > 0)
{
if (site_now[2][1] == y_start)
{
//leg 2&0 move
set_site(2, x_default + x_offset, y_start, z_up);
wait_all_reach();
/*
- go forward
- blocking function
- parameter step steps wanted to go
---------------------------------------------------------------------------*/
void step_forward(unsigned int step)
{
move_speed = leg_move_speed;
while (step-- > 0)
{
if (site_now[2][1] == y_start)
{
//leg 2&1 move
set_site(2, x_default + x_offset, y_start, z_up);
wait_all_reach();
set_site(2, x_default + x_offset, y_start + 2 * y_step, z_up);
wait_all_reach();
set_site(2, x_default + x_offset, y_start + 2 * y_step, z_default);
wait_all_reach();
move_speed = body_move_speed;
move_speed = leg_move_speed;
move_speed = body_move_speed;
move_speed = leg_move_speed;
/*
- go back
- blocking function
- parameter step steps wanted to go
---------------------------------------------------------------------------*/
void step_back(unsigned int step)
{
move_speed = leg_move_speed;
while (step-- > 0)
{
if (site_now[3][1] == y_start)
{
//leg 3&0 move
set_site(3, x_default + x_offset, y_start, z_up);
wait_all_reach();
set_site(3, x_default + x_offset, y_start + 2 * y_step, z_up);
wait_all_reach();
set_site(3, x_default + x_offset, y_start + 2 * y_step, z_default);
wait_all_reach();
move_speed = body_move_speed;
move_speed = leg_move_speed;
move_speed = body_move_speed;
move_speed = leg_move_speed;
// add by RegisHsu
void body_left(int i)
{
set_site(0, site_now[0][0] + i, KEEP, KEEP);
set_site(1, site_now[1][0] + i, KEEP, KEEP);
set_site(2, site_now[2][0] - i, KEEP, KEEP);
set_site(3, site_now[3][0] - i, KEEP, KEEP);
wait_all_reach();
}
void body_right(int i)
{
set_site(0, site_now[0][0] - i, KEEP, KEEP);
set_site(1, site_now[1][0] - i, KEEP, KEEP);
set_site(2, site_now[2][0] + i, KEEP, KEEP);
set_site(3, site_now[3][0] + i, KEEP, KEEP);
wait_all_reach();
}
void hand_wave(int i)
{
float x_tmp;
float y_tmp;
float z_tmp;
move_speed = 1;
if (site_now[3][1] == y_start)
{
body_right(15);
x_tmp = site_now[2][0];
y_tmp = site_now[2][1];
z_tmp = site_now[2][2];
move_speed = body_move_speed;
for (int j = 0; j < i; j++)
{
set_site(2, turn_x1, turn_y1, 50);
wait_all_reach();
set_site(2, turn_x0, turn_y0, 50);
wait_all_reach();
}
set_site(2, x_tmp, y_tmp, z_tmp);
wait_all_reach();
move_speed = 1;
body_left(15);
}
else
{
body_left(15);
x_tmp = site_now[0][0];
y_tmp = site_now[0][1];
z_tmp = site_now[0][2];
move_speed = body_move_speed;
for (int j = 0; j < i; j++)
{
set_site(0, turn_x1, turn_y1, 50);
wait_all_reach();
set_site(0, turn_x0, turn_y0, 50);
wait_all_reach();
}
set_site(0, x_tmp, y_tmp, z_tmp);
wait_all_reach();
move_speed = 1;
body_right(15);
}
}
void hand_shake(int i)
{
float x_tmp;
float y_tmp;
float z_tmp;
move_speed = 1;
if (site_now[3][1] == y_start)
{
body_right(15);
x_tmp = site_now[2][0];
y_tmp = site_now[2][1];
z_tmp = site_now[2][2];
move_speed = body_move_speed;
for (int j = 0; j < i; j++)
{
set_site(2, x_default - 30, y_start + 2 * y_step, 55);
wait_all_reach();
set_site(2, x_default - 30, y_start + 2 * y_step, 10);
wait_all_reach();
}
set_site(2, x_tmp, y_tmp, z_tmp);
wait_all_reach();
move_speed = 1;
body_left(15);
}
else
{
body_left(15);
x_tmp = site_now[0][0];
y_tmp = site_now[0][1];
z_tmp = site_now[0][2];
move_speed = body_move_speed;
for (int j = 0; j < i; j++)
{
set_site(0, x_default - 30, y_start + 2 * y_step, 55);
wait_all_reach();
set_site(0, x_default - 30, y_start + 2 * y_step, 10);
wait_all_reach();
}
set_site(0, x_tmp, y_tmp, z_tmp);
wait_all_reach();
move_speed = 1;
body_right(15);
}
}
/*
- microservos service /timer interrupt function/50Hz
- when set site expected,this function move the end point to it in a straight
line
- temp_speed[4][3] should be set before set expect site,it make sure the
end point
move in a straight line,and decide move speed.
---------------------------------------------------------------------------*/
void servo_service(void)
{
sei();
static float alpha, beta, gamma;
rest_counter++;
}
/*
- set one of end points' expect site
- this founction will set temp_speed[4][3] at same time
- non - blocking function
---------------------------------------------------------------------------*/
void set_site(int leg, float x, float y, float z)
{
float length_x = 0, length_y = 0, length_z = 0;
if (x != KEEP)
length_x = x - site_now[leg][0];
if (y != KEEP)
length_y = y - site_now[leg][1];
if (z != KEEP)
length_z = z - site_now[leg][2];
if (x != KEEP)
site_expect[leg][0] = x;
if (y != KEEP)
site_expect[leg][1] = y;
if (z != KEEP)
site_expect[leg][2] = z;
}
/*
- wait one of end points move to expect site
- blocking function
---------------------------------------------------------------------------*/
void wait_reach(int leg)
{
while (1)
if (site_now[leg][0] == site_expect[leg][0])
if (site_now[leg][1] == site_expect[leg][1])
if (site_now[leg][2] == site_expect[leg][2])
break;
}
/*
- wait all of end points move to expect site
- blocking function
---------------------------------------------------------------------------*/
void wait_all_reach(void)
{
for (int i = 0; i < 4; i++) wait_reach(i); } /* - trans site from cartesian to
polar - mathematical model 2/2 -------------------------------------------------
--------------------------*/ void cartesian_to_polar(volatile float &alpha,
volatile float &beta, volatile float &gamma, volatile float x, volatile
float y, volatile float z) { //calculate w-z degree float v, w; w = (x >= 0 ?
1 : -1) * (sqrt(pow(x, 2) + pow(y, 2)));
v = w - length_c;
alpha = atan2(z, v) + acos((pow(length_a, 2) - pow(length_b, 2) + pow(v,
2) + pow(z, 2)) / 2 / length_a / sqrt(pow(v, 2) + pow(z, 2)));
beta = acos((pow(length_a, 2) + pow(length_b, 2) - pow(v, 2) - pow(z, 2)) /
2 / length_a / length_b);
//calculate x-y-z degree
gamma = (w >= 0) ? atan2(y, x) : atan2(-y, -x);
//trans degree pi->180
alpha = alpha / pi * 180;
beta = beta / pi * 180;
gamma = gamma / pi * 180;
}
/*
- trans site from polar to microservos
- mathematical model map to fact
- the errors saved in eeprom will be add
---------------------------------------------------------------------------*/
void polar_to_servo(int leg, float alpha, float beta, float gamma)
{
if (leg == 0)
{
alpha = 90 - alpha;
beta = beta;
gamma += 90;
}
else if (leg == 1)
{
alpha += 90;
beta = 180 - beta;
gamma = 90 - gamma;
}
else if (leg == 2)
{
alpha += 90;
beta = 180 - beta;
gamma = 90 - gamma;
}
else if (leg == 3)
{
alpha = 90 - alpha;
beta = beta;
gamma += 90;
}
servo[leg][0].write(alpha);
servo[leg][1].write(beta);
servo[leg][2].write(gamma);
}
Bluetooth Connection:
The pins of the bluetooth module are connected to the COM part
on the sensor shield. Connection pins:
Arduino Bluetooth
RX————-TX
TX————-RX
VCC———–VCC
GND———-GND
Android App:
The application will be installed when you open the file from
your phone by dropping the Spider.apk file contained in the
download file to any folder on your phone. If Allow unknown
sources is set and you allow the settings, the application will be
installed without problems.
You will be out for the Bayram vacation but are you worried
about your fish in the aquarium?
learn how to feed your fish with Arduino when you are not at
home.
like Arduino and products which are very easy to prepare the
project give us the chance to
Required Hardware:
► Arduino (Uno-Duemilanove-Leonardo-Mega)
► One Servo Motor
► A-B Usb Cable
► 9V battery
► Cable
Schematic of power:
easy. We connect the black wire to the ground (GND), the red
wire to + 5V and the yellow
wire to the 9th pin. We did not need to install the circuit on the
breadboard because we did not
Construction Stages
4-) When we attach the end of the servo motor to the motor, the
hardware part of our project is completed and finally we connect
the USB cable to Arduino and my computer to connect with the
computer.
So the hardware part is now in the software part.
Deviation Codes:
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(9); // servo pin 9
}
void loop()
{
myservo.write(90);
delay(10000);
myservo.write(55);
delay(300); // kapakların açık olacağı süre.
}
Required Hardware:
1- Arduino UNO
2- EMG sensor
3- Servo motor shild
4- Robotic Hand
Schematic of power:
Deviation Codes:
#include <Servo.h>
#define LITTLE 1
#define RING 2
#define MIDDLE 3
#define INDEX 4
#define THUMB 5
int finger;
finger++){closeFinger(finger);}}
void openFinger(int finger){
void setup(){
Serial.begin(115200);
digital pin 3
pin 6
pin 9
pin 10
}//end setup
void loop() {// Nothing to do here, all is done in the interrupt function
if(value>THRESHOLD)
{closehand();}
Serial.println(value);
https://www.thingiverse.com/thing:17773
NECESSARY MATERIALS
Arduino UNO
Tower Pro Servo Motor 9g
HCSR-04 Ultrasonic Sensor
Jumper Cable
Devastation project scheme:
After installing the project, connect your arduino card with usb,
then run the processing program when you see the connection id,
and if you give the program com port error, you wrote the
wrong port. So you have to enter your own port.
The arduino codes of the project are below and you need to copy
these codes and install your arduino card.
#include <Servo.h>.
const int trigPin = 10;
long duration;
int distance;
Servo myServo;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
void loop() {
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
int calculateDistance(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
return distance;
Process the proce- ding codes, here line 23, set the com port
to your own, type in which port your Arduino card is
communicating with.!!!!!!!
import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
Serial myPort;
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance;
int index1=0;
int index2=0;
PFont orcFont;
void setup() {
myPort.bufferUntil('.');
void draw() {
fill(98,245,31);
noStroke();
fill(0,4);
fill(98,245,31);
drawRadar();
drawLine();
drawObject();
drawText();
data = myPort.readStringUntil('.');
data = data.substring(0,data.length()-1);
index1 = data.indexOf(",");
iAngle = int(angle);
iDistance = int(distance);
void drawRadar() {
pushMatrix();
translate(683,700);
noFill();
strokeWeight(2);
stroke(98,245,31);
arc(0,0,1300,1300,PI,TWO_PI);
arc(0,0,1000,1000,PI,TWO_PI);
arc(0,0,700,700,PI,TWO_PI);
arc(0,0,400,400,PI,TWO_PI);
line(-700,0,700,0);
line(0,0,-700*cos(radians(30)),-700*sin(radians(30)));
line(0,0,-700*cos(radians(60)),-700*sin(radians(60)));
line(0,0,-700*cos(radians(90)),-700*sin(radians(90)));
line(0,0,-700*cos(radians(120)),-700*sin(radians(120)));
line(0,0,-700*cos(radians(150)),-700*sin(radians(150)));
line(-700*cos(radians(30)),0,700,0);
popMatrix();
void drawObject() {
pushMatrix();
translate(683,700);
strokeWeight(9);
stroke(255,10,10);
pixsDistance = iDistance*22.5;
if(iDistance<40){ line(pixsDistance*cos(radians(iAngle)),-
pixsDistance*sin(radians(iAngle)),700*cos(radians(iAngle)),-
700*sin(radians(iAngle))); } popMatrix(); } void drawLine() {
pushMatrix();
line(0,0,700*cos(radians(iAngle)),-700*sin(radians(iAngle)));
popMatrix();
else {
fill(0,0,0);
noStroke();
fill(98,245,31);
textSize(25);
text("10cm",800,690);
text("20cm",950,690);
text("30cm",1100,690);
text("40cm",1250,690);
textSize(40);
if(iDistance<40) {
textSize(25);
fill(98,245,60);
translate(390+960*cos(radians(30)),780-960*sin(radians(30)));
rotate(-radians(-60));
text("30°",0,0);
resetMatrix();
translate(490+960*cos(radians(60)),920-960*sin(radians(60)));
rotate(-radians(-30));
text("60°",0,0);
resetMatrix();
translate(630+960*cos(radians(90)),990-960*sin(radians(90)));
rotate(radians(0));
text("90°",0,0);
resetMatrix();
translate(760+960*cos(radians(120)),1000-
960*sin(radians(120)));
rotate(radians(-38));
text("120°",0,0);
resetMatrix();
translate(840+900*cos(radians(150)),920-
960*sin(radians(150)));
rotate(radians(-60));
text("150°",0,0);
popMatrix();
The infrared rays of many sensors are used in the mz80, the
infrared sensor and
many other sensors and modules. We will use this day to find the
sensor and the
control set very suitable for internet. But if you take this from the
land, it will
these binary sets work very well because they are designed
exactly to each other.
The project we do is a project that does not have much on the
internet. Usually there are LEDs
and car videos for these two sets, but we will set the servos'
ratings today. If you want to
replace the if and else if sections that I write in the code, you can
write the project you want to
do. The first day I will show you two alternative codes today is
to increase the degree with 4
keys and the other way to decrease it, that is, to set the degree
with numbers.
NOTE: both codes can read both the project and the HEX
number. The HEX number is the
value that comes up when the key is pressed. Before you try,
change your HEX codes with
mine because chances of not being the same are very high.
NECESSARY MATERIALS
One infrared control and sensor;
One Arduino
One servo
Jumper cables
5v breadboard to replicate
Connections = sensor 11 servo 9;
#include <Servo.h>
#include <IRremote.h>
Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
servo.attach(9);
Serial.begin(9600);
irrecv.enableIRIn();
servo.write(0);
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
if(results.value==0xC101E57B){
servo.write(0);
}
else if(results.value==0x9716BE3F){
servo.write(10);
else if(results.value==0x3D9AE3F7){
servo.write(20);
else if(results.value==0x6182021B){
servo.write(30);
else if(results.value==0x8C22657B){
servo.write(40);
else if(results.value==0x488F3CBB){
servo.write(50);
else if(results.value==0x449E79F){
servo.write(60);
}
else if(results.value==0x32C6FDF7){
servo.write(70);
else if(results.value==0x1BC0157B){
servo.write(80);
else if(results.value==0x3EC3FC1B){
servo.write(90);
delay(10);
}
7-) DIGITAL METER CONSTRUCTION
WITH ARDUINO
NECESSARY MATERIALS
Arduino Nano
16 × 2 LCD I2C Display
Ultrasonic Sensor
9v Jack Cable
Mini Breadboard
3D Printing Parts (download)
Why Ultrasonic Sensor? Ultrasonics is reliable in any lighting
environment and can be used
#include <NewPing.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
void setup() {
lcd.begin();
lcd.backlight();
lcd.print("distance :");
void loop() {
delay(50);
lcd.setCursor(0,1);
lcd.print(sonar.ping_cm() );
lcd.print(" cm");
}
<pre>
8-) Arduino Shaking Tea Machine
The shaking tea machine project allows you to drip your tea in
your special cup of tea
according to the tea type you choose, and when it is over time
you will not be able to give a
little taste by lifting your tea tea from the bacon.You have to stop
in a 1.5 min cup for a nice
black tea brew.
Our project was designed not to make our life easier but to add
more color. The materials
used in the project consist of the materials found in the boxes of
many makers.
NECESSARY MATERIALS
Arduino UNO
16 × 2 LCD Display I2C
Servo-motor
buzzer
Potentiometer
Led
Button
3D Printing Parts (Tea Maker)
Scheme showing the links of our Project
Deviation Codes
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <Wire.h>
Servo servoMotor;
int screenLED = 6;
int servoPin = 7;
int startButton = 8;
int buzzer = 9;
int oldTimer = 0;
long idleTime = 0;
void setup() {
pinMode(screenLED, OUTPUT);
pinMode(servoPin, OUTPUT);
pinMode(startButton, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
servoMotor.attach(servoPin);
servoMotor.write(servoHighPosition);
if (!diagnosticBit){
Serial.println("Sistem Tamam");
lcd.begin();
lcd.backlight();
lcd.print("Cay Makinesi");
lcd.setCursor(0, 1);
lcd.print("Proje Hocam");
fadeLightOn(screenLED);
clearScreen();
if (!diagnosticBit){
updateIdleTime();
}
void loop() {
fadeLightOff(screenLED);
idleTime = 2147483647;
Serial.println(idleTime);
Serial.println(millis());
Serial.println("");
if (millis() % 30 == 0){
oldTimer = timer;
timer = rawToTime(analogRead(teaPot));
if (oldTimer != timer){
lcd.setCursor(0, 0);
lcd.print(teaName(rawToTime(analogRead(teaPot))));
lcd.setCursor(3, 1);
lcd.print(timeString(0));
lcd.setCursor(8, 1);
lcd.print(timeString(timer));
delay(300);
updateIdleTime();
}
}
if (!digitalRead(startButton)){
inProcess = HIGH;
servoMotor.write(servoLowPosition);
updateIdleTime();
delay(300);
if (inProcess == HIGH){
Serial.println("inProcess is HIGH");
lcd.setCursor(3, 1);
lcd.print(timeString(i));
delay(1000);
servoMotor.write(i);
delay(servoSpeed);
}
for (int i = 0; i < 3; i ++){
servoMotor.write(servoHighPosition);
delay(200);
if (!diagnosticBit){
servoMotor.write(servoMidPosition);
delay(servoLowPosition);
servoMotor.write(servoHighPosition);
updateIdleTime();
inProcess = LOW;
NECESSARY MATERIALS
Arduino UNO
16 × 2 LCD Display
DC Motor
LM393 Speed Sensor
L298N Motor Driver
Mini Breadboard
Potentiometer
Jumper Cable
Deviation Codes
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int in2 = 5;
int ena = 6;
int rpm;
boolean currentstate;
boolean prevstate;
void setup()
Serial.begin(9600);
lcd.begin();
lcd.backlight();
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(ena, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
pinMode(dataIN,INPUT);
prevmillis = 0;
prevstate = LOW;
void loop()
currentstate = digitalRead(dataIN);
rpm = (6000000/duration);
prevmillis = micros();
}
}
prevstate = currentstate;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Motor Hizi");
lcd.setCursor(0,1);
lcd.print("RPM = ");
lcd.print(rpm);
lcdrefresh = millis();
analogWrite(ena, motor_hizi);
}
10) REMOTE CONTROL
APPLICATION WITH ARDUINO
AND NRF24L01
TRANSMITTER RECEIVER
CIRCUIT
nRF24L01 Arduino Uno
VCC 3.3 V
GND GND
CS 7
CE 8
MOSI 11
MISO 12
SCK 13
pot=A0 servo=9
Deviation Codes
#include <SPI.h>
#include "RF24.h"
int msg[1];
//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8
RF24 radio(8,7);
int potpin = 0;
int val;
void setup(void){
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(void){
val = analogRead(potpin);
msg[0] = val;
radio.write(msg, 1);
#include <Servo.h>
#include <SPI.h>
#include "RF24.h"
Servo myservo;
//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 7//CE -> 8
RF24 radio(8,7);
int msg[1];
void setup()
myservo.attach(9);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
if (radio.available()){
while (!done){
myservo.write (msg[0]);
#define TRIGGER_PIN 2
#define ECHO_PIN 3
#define LED_PIN 4
#define MAX_DISTANCE 200
//#define IRPin 8
// 4 servos
Servo leftFootServo;
Servo leftHipServo;
Servo rightFootServo;
Servo rightHipServo;
const int offset = 20; //how many degrees we want to move the servos
// Servo positions
// Left foot servo
const int leftFootC = 92; // centered
const int leftFootD = leftFootC+offset; // foot down
const int leftFootU = leftFootC-offset-6; // foot up
byte isTurning = 0;
Turning turning;
unsigned long turningStarted;
unsigned long turningDuration;
byte isMovingBackwards = 0;
int movingBackwardsDuration = 10000;
unsigned long movingBackwardsStarted;
State state;
LED led(LED_PIN);
PowerLEDController powerLEDController(LED_PIN);
void setup()
{
//Serial.begin(9600);
randomSeed(analogRead(0));
leftHipServo.attach(9);
rightHipServo.attach(10);
leftFootServo.attach(11);
rightFootServo.attach(12);
leftHipServo.write(leftHipC);
rightHipServo.write(rightHipC);
leftFootServo.write(leftFootC);
rightFootServo.write(rightFootC);
turning.Avoiding = 3000;
turning.Wandering = 1250;
led.on();
delay(250);
led.off();
delay(250);
led.on();
delay(250);
led.off();
delay(250);
led.on();
delay(250);
led.off();
wakeUp();
}
void loop()
{
switch(state)
{
case Walking:
updateDirection();
powerLEDController.update();
break;
case Sleeping:
if (millis() - startCurrentState > 2000)
{
delay(10000);
}
break;
}
updateCurrentState();
led.update();
walk();
}
void updateCurrentState()
{
if (millis() > startCurrentState + currentStateDuration)
{
startCurrentState = millis();
switch(state)
{
case Walking:
sleep();
break;
case Sleeping:
wakeUp();
break;
}
led.flash();
}
void updateDirection()
{
unsigned int dist;
updateWandering();
switch(direction)
{
case 1: // forward
dist = moveForward();
updateWandering();
break;
case 2: // backward
led.flash();
moveBackwards();
break;
case 3: // left
case 4: // right
led.flash();
makeTurn();
break;
}
previousDist = dist;
}
return dist;
}
void makeTurn()
{
if (isTurning)
{
if (millis() - turningStarted > turningDuration)
{
isTurning = false;
direction = 1;
previousDist = 9999;
}
}
else
{
isTurning = true;
turningStarted = millis();
}
}
void moveBackwards()
{
if (isMovingBackwards)
{
if(millis() - movingBackwardsStarted > movingBackwardsDuration)
{
isMovingBackwards = false;
if(random(2) == 0)
{
direction = 4;
}
else
{
direction = 3;
}
}
}
else
{
isMovingBackwards = true;
movingBackwardsStarted = millis();
}
}
void walk()
{
SuperTurboMillis = millis();
legInStep = legInStep + 1;
if (legInStep == steps + 1){
legInStep = 1;
}
if (legInStep == 1)
{
leftFootStep = (leftFootPos - leftFootPosInt) / steps;
leftHipStep = (leftHipPos - leftHipPosInt) / steps;
rightFootStep = (rightFootPos - rightFootPosInt) / steps;
rightHipStep = (rightHipPos - rightHipPosInt) / steps;
}
if (SuperTurboStep == 5)
{
leftHipPos = leftHipR;
rightHipPos = rightHipL;
}
if (SuperTurboStep == 6)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
}
if (SuperTurboStep == 2)
{
leftHipPos = leftHipR;
rightHipPos = rightHipL;
}
if (SuperTurboStep == 3)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
if (SuperTurboStep == 4)
{
leftFootPos = leftFootD;
rightFootPos = rightFootU;
}
if (SuperTurboStep == 5)
{
leftHipPos = leftHipL;
rightHipPos = rightHipR;
}
if (SuperTurboStep == 6)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
}
if (direction == 3) // left walking gait
{
if (SuperTurboStep == 1)
{
leftFootPos = leftFootU;
rightFootPos = rightFootD;
}
if (SuperTurboStep == 2)
{
leftHipPos = leftHipL;
rightHipPos = rightHipL;
}
if (SuperTurboStep == 3)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
if (SuperTurboStep == 4)
{
leftFootPos = leftFootD;
rightFootPos = rightFootU;
}
if (SuperTurboStep == 5)
{
leftHipPos = leftHipR;
rightHipPos = rightHipR;
}
if (SuperTurboStep == 6)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
}
if (direction == 4) // right walking gait
{
if (SuperTurboStep == 1)
{
leftFootPos = leftFootU;
rightFootPos = rightFootD;
}
if (SuperTurboStep == 2)
{
leftHipPos = leftHipR;
rightHipPos = rightHipR;
}
if (SuperTurboStep == 3)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
if (SuperTurboStep == 4)
{
leftFootPos = leftFootD;
rightFootPos = rightFootU;
}
if (SuperTurboStep == 5)
{
leftHipPos = leftHipL;
rightHipPos = rightHipL;
}
if (SuperTurboStep == 6)
{
leftFootPos = leftFootC;
rightFootPos = rightFootC;
}
}
leftFootServo.write(leftFootPosInt);
leftHipServo.write(leftHipPosInt);
rightFootServo.write(rightFootPosInt);
rightHipServo.write(rightHipPosInt);
}
int readDistance()
{
int uS = sonar.ping();
int uScm = uS / US_ROUNDTRIP_CM;
if (uScm == 0)
{
uScm = 9999;
}
return uScm;
}
void updateWandering()
{
if (millis() > startWander + nextWander)
{
makeRandomTurn(turning.Wandering);
startWander = millis();
nextWander = getNextWander();
led.flash();
}
}
void sleep()
{
state = Sleeping;
direction = 0;
currentStateDuration = random(60000, 5 * 60000);
}
void wakeUp()
{
startWander = millis();
nextWander = getNextWander();
state = Walking;
currentStateDuration = random(40000, 120000);
speed = random(20, 40);
timer = millis();
direction = 1;
led.flash();
}
12) ARDUİNO FUZZY LOGIC TEMPERATURE
MOISTURE PROJECT
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16, 2);
#define DHTPIN 2
#define DHTTYPE DHT11
const int fansogut=9;
const int enablesogut=3;
const int fanisit=10;
const int enableisit=5;
int fanhiz;
int fanhiz2;
int mavi=13;
int kirmizi=12;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("Bulanik Mantik");
pinMode(fansogut,OUTPUT);
pinMode(enablesogut, OUTPUT);
pinMode(fanisit,OUTPUT);
pinMode(enableisit, OUTPUT);
pinMode(mavi, OUTPUT);
pinMode(kirmizi, OUTPUT);
dht.begin();
lcd.begin();
lcd.backlight();
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h))
{
Serial.println("DHT Hatası");
}
else
{
float CokSoguk = 0;
float Soguk = 0;
float Konforlu = 0;
float Sicak = 0;
float CokSicak = 0;
float CokDusuk = 0;
float Dusuk = 0;
float Normal = 0;
float Yuksek = 0;
float CokYuksek = 0;
float Kapali_max = 0;
float Yavas_max = 0;
float OrtaHalli_max = 0;
float AzHizli_max = 0;
float TamHizli_max = 0;
lcd.setCursor(0,0);
lcd.print("S:");
lcd.print(t);
lcd.setCursor(9,0);
lcd.print("N:");
lcd.print(h);
if ( t <= 24) {
AzHizli[0] = AND(CokDusuk, CokSoguk);
OrtaHalli[0] = AND(CokDusuk, Soguk);
Kapali[0] = AND(CokDusuk, Konforlu);
lcd.setCursor(0,1);
lcd.print("IsitF:");
lcd.print(cikis);
fanhiz = ((cikis/100)*255);
analogWrite(enableisit,fanhiz);
digitalWrite(fanisit,HIGH);
digitalWrite(kirmizi,HIGH);
digitalWrite(mavi,LOW);
}
else {
lcd.setCursor(0,1);
lcd.print("SogutF:");
lcd.print(cikis2);
fanhiz2 = ((cikis2/100)*255);
analogWrite(enablesogut,fanhiz2);
digitalWrite(fansogut,HIGH);
digitalWrite(kirmizi,LOW);
digitalWrite(mavi,HIGH);
}
delay(1000);
}
// setup servo
int servoPin = 8;
int PEN_DOWN = 170; // angle of servo when pen is down
int PEN_UP = 80; // angle of servo when pen is up
Servo penServo;
This robot is very hard to stand on the level and balance. This is
why the developed PID algorithm was used in coding. In this
type of robot, the motor is normally used with encoder, but we
didn't choose this motors because they are expensive. materials
from a hardware store
As the control card, the Arduino UNO, the L298N model for the
motor drive was preferred. This model responds to the signals
very well. It is also on the market and cheap.
NECESSARY MATERIALS
Arduino UNO
MPU6050 Accelerometer Gyro
L298N Motor driver board
4 Pcs M3 Gijon (Stud) + 24 M3 Nuts
2 Pcs Dagu motor + wheel set
Lipo battery
First try to create a similar frame by looking at the pictures
below. Try to place the motors in the equilibrium center.
Cut three plastic layers of 20 × 8 cm in size. Then cut the gijon
into 20 cm lengths. Insert the gins by drilling through the corners
of the plastic sheets and adjust your robot to 3 bold.
After you have prepared the mechanical part of the project, you
need to add the electronic part. When inserting the cards, such as
the arduino, motor drive, place it again, paying attention to the
center of gravity.
Scheme showing the links of our Project
Then attach the 3 potentiometers to the gijons with silicone and
connect them to the inputs A0, A1 and A2 in the potentiometer
arduino. KP, KD and KI values change when we play with
settings.
#include <PID_v1.h>
#include <LMotorController.h>
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#define LOG_INPUT 0
#define MANUAL_TUNING 0
#define LOG_PID_CONSTANTS 0
#define MOVE_BACK_FORTH 0
#define MIN_ABS_SPEED 30
//MPU
MPU6050 mpu;
// MPU control/status vars
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 =
success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
// orientation/motion vars
Quaternion q; // [w, x, y, z] quaternion container
VectorFloat gravity; // [x, y, z] gravity vector
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and
gravity vector
//PID
#if MANUAL_TUNING
double kp , ki, kd;
double prevKp, prevKi, prevKd;
#endif
double originalSetpoint = 174.29;
double setpoint = originalSetpoint;
double movingAngleOffset = 0.3;
double input, output;
int moveState=0; //0 = denge ; 1 = geri ; 2 = ileri
#if MANUAL_TUNING
PID pid(&input, &output, &setpoint, 0, 0, 0, DIRECT);
#else
PID pid(&input, &output, &setpoint, 70, 240, 1.9, DIRECT);
#endif
//MOTOR SURUCU
int ENA = 3;
int IN1 = 4;
int IN2 = 8;
int IN3 = 5;
int IN4 = 7;
int ENB = 6;
long time1Hz = 0;
long time5Hz = 0;
void setup()
{
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION ==
I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// initialize device
Serial.println(F("I2C Kuruluyor..."));
mpu.initialize();
// verify connection
Serial.println(F("Suruculer test ediliyor..."));
Serial.println(mpu.testConnection() ? F("MPU6050 baglanti basarili") :
F("MPU6050 baglanti basarisiz"));
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
// make sure it worked (returns 0 if so)
if (devStatus == 0)
{
// turn on the DMP, now that it's ready
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
// set our DMP Ready flag so the main loop() function knows it's okay
to use it
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
//setup PID
pid.SetMode(AUTOMATIC);
pid.SetSampleTime(10);
pid.SetOutputLimits(-255, 255);
}
else
{
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually the code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
void loop()
{
// if programming failed, don't try to do anything
if (!dmpReady) return;
// check for overflow (this should never happen unless our code is too
inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024)
{
// reset so we can continue cleanly
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
// otherwise, check for DMP data ready interrupt (this should happen
frequently)
}
else if (mpuIntStatus & 0x02)
{
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); //
read a packet from FIFO mpu.getFIFOBytes(fifoBuffer, packetSize); //
track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an
interrupt)
fifoCount -= packetSize;
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
#if LOG_INPUT
Serial.print("ypr\t");
Serial.print(ypr[0] * 180/M_PI);
Serial.print("\t");
Serial.print(ypr[1] * 180/M_PI);
Serial.print("\t");
Serial.println(ypr[2] * 180/M_PI);
#endif
input = ypr[1] * 180/M_PI + 180;
}
}
void loopAt1Hz()
{
#if MANUAL_TUNING
setPIDTuningValues();
#endif
}
void loopAt5Hz()
{
#if MOVE_BACK_FORTH
moveBackForth();
#endif
}
void moveBackForth()
{
moveState++;
if (moveState > 2) moveState = 0;
if (moveState == 0)
setpoint = originalSetpoint;
else if (moveState == 1)
setpoint = originalSetpoint - movingAngleOffset;
else
setpoint = originalSetpoint + movingAngleOffset;
}
void readPIDTuningValues()
{
int potKp = analogRead(A0);
int potKi = analogRead(A1);
int potKd = analogRead(A2);
void loop()
{
digitalWrite(ledpin,HIGH);
val0 = analogRead(potpin0);
val0 = map(val0, 0, 1023, 0, 179);
myservo0.write(val0);
Serial.println(val0);
delay(15);
val1 = analogRead(potpin1);
val1 = map(val1, 0, 1023, 0, 179);
myservo1.write(val1);
Serial.println(val1);
delay(15);
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 179);
myservo2.write(val2);
Serial.println(val2);
delay(15);
val3 = analogRead(potpin3);
val3 = map(val3, 0, 1023, 0, 179);
myservo3.write(val3);
Serial.println(val3);
delay(15);
}
Our robot is carried out on a tracked kit, the reason for choosing
a crawler kit is that it can be easily moved in difficult terrain. The
robot arm mounted on it is a two-axis and simple piece. It only
moves down and up and left and the third servo runs the holder.
NECESSARY MATERIALS
Arduino Uno
Servo motor 3
Battery
Scheme showing the links of our Project
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial BT(52, 53); //set TX and RX on bluetooth to pin 52 and 53
respectively
Servo servo1;
Servo servo2;
Servo servo3;
char command;
void setup() {
BT.begin (9600);
Serial.begin (9600);
pinMode(motorPin, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
servo1.attach(5);
servo1.write(pos1);
servo2.attach(6);
servo2.write(pos2);
servo3.attach(7);
servo3.write(pos3);
void stop() {
digitalWrite(motorPin, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
void forward(){
digitalWrite(motorPin, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
void backward() {
digitalWrite(motorPin, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
void turnLeft() {
digitalWrite(motorPin, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
void turnRight() {
digitalWrite(motorPin, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}
void open() {
void close() {
void clockwise() {
void up () {
void loop() {
if (BT.available() > 0) {
command = BT.read();
switch (command) {
case 'w':
forward();
break;
case 'x':
backward();
break;
case 'a':
turnLeft();
break;
case 'd':
turnRight();
break;
case 's':
stop();
break;
case 'y':
open();
break;
case 'u':
close();
break;
case 'h':
antiClockwise();
break;
case 'j':
clockwise();
break;
case 'n':
up();
break;
case 'm':
down();
break;
}
}
}
NECESSARY MATERIALS
(x1) Output of SRT files (3D Printer)
(x1) Arduino Nano
(x2) Servo motor
(x1) 40-pin socket
(x4) Pencils
Print out the project from the printer. The printing time varies
according to the performance of your printer. I'm guessing you
can print in an average of 10 hours.
Scheme showing the links of our Project
Deviation Codes
#include <Servo.h>
Servo myservo;
Servo myservo1;
//Balans ayarları
int backRight = BackCentered - 20;
int backLeft = BackCentered + 20;
void setup()
{
myservo.attach(8);
myservo1.attach(9);
myservo1.write(FrontBalanced);
myservo.write(BackCentered);
delay(2000);
}
void loop()
{
//Düz yürü
goStraight();
for(int walk = 10 ; walk >= 0; walk -=1) {
walkOn();
}
//Sağa dön
goRight();
for(int walk = 10 ; walk >= 0; walk -=1) {
walkOn();
}
//Düz yürü
goStraight();
for(int walk = 10 ; walk >= 0; walk -=1) {
walkOn();
}
//Sola dön
goLeft();
for(int walk = 10 ; walk >= 0; walk -=1) {
walkOn();
}
//Yürüme fonksiyonu
void walkOn(){
myservo.write(BackCentered + 30);
delay(1000);
myservo.write(BackCentered - 30);
delay(1000);
}
Deviation Codes
#include <Servo.h>
Servo rightfoot;
Servo righthigh;
Servo leftfoot;
Servo leftthigh;
int pos;
void setup()
{
rightfoot.attach(3);
righthigh.attach(5);
leftfoot.attach(9);
leftthigh.attach(6);
}
void loop()
{ int pos=120;
rightfoot.write(90);
righthigh.write(90);
leftfoot.write(90);
leftthigh.write(90);delay(500);
leftfoot.write(55);delay(400);
for(int i=90;i<=115;i++)
{rightfoot.write(i);delay(12);}
leftfoot.write(120);delay(100);
leftthigh.write(120);delay(100);
delay(500);
for(int i=90;i<=120;i++)
{righthigh.write(i);delay(12);
leftthigh.write(i);delay(12);}
leftfoot.write(90);delay(300);
for(int i=115;i>=90;i--)
{rightfoot.write(i);delay(12);}
delay(500);
rightfoot.write(120);delay(300);
leftfoot.write(65);
righthigh.write(60);
for(pos=120;pos>=60;pos--)
{leftthigh.write(pos);delay(7);}
rightfoot.write(60);
delay(500);
rightfoot.write(90);delay(300);
leftfoot.write(90);delay(300);
leftthigh.write(60);delay(300);
righthigh.write(60);delay(300);
delay(500);
}
#include "Servo8bit.h"
#define trigPin 0
#define echoPin 3
int ir_pin = 4;
int motorPinL = 1;
int motorPinR = 2;
int key;
int start_bit = 2000;
int bin_1 = 1000;
int bin_0 = 400;
unsigned long stoptimer;
boolean autoMode;
Servo8Bit motorL, motorR;
void setup() {
pinMode(ir_pin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
motorL.attach(motorPinL);
motorR.attach(motorPinR);
//Serial.begin(9600);
digitalWrite(0, HIGH);
}
void loop() {
key = getIRKey();
if (key != -1) {
//Serial.println(key);
if (key < 755 && key > 750){moveMotors(160, 160);} //up
if (key < 2805 && key > 2795){moveMotors(10, 10);} //down
if (key < 725 && key > 715){moveMotors(10, 160);} //left
if (key < 3285 && key > 3275){moveMotors(160, 10);} //right
if (key < 2677 && key > 2667){
autoMode = !autoMode;
moveMotors(94, 85);
delay(400);
}
if (key < 2710 && key > 2695){
motorL.detach();
motorR.detach();
}
}
stoptimer = millis();
}
int getIRKey() {
int data[12];
while(pulseIn(ir_pin, LOW, 20000) < 2200) {
if(stoptimer+20 < millis() && !autoMode) moveMotors(94, 85);
if(autoMode){
if(getDistance() < 10){
moveMotors(94, 20);
delay(400);
}
else{
moveMotors(120, 120);
}
}
key = 0;
}
stoptimer = millis()+1000;
data[0] = pulseIn(ir_pin, LOW);
data[1] = pulseIn(ir_pin, LOW);
data[2] = pulseIn(ir_pin, LOW);
data[3] = pulseIn(ir_pin, LOW);
data[4] = pulseIn(ir_pin, LOW);
data[5] = pulseIn(ir_pin, LOW);
data[6] = pulseIn(ir_pin, LOW);
data[7] = pulseIn(ir_pin, LOW);
data[8] = pulseIn(ir_pin, LOW);
data[9] = pulseIn(ir_pin, LOW);
data[10] = pulseIn(ir_pin, LOW);
data[11] = pulseIn(ir_pin, LOW);
for(int i=0;i<=11;i++) {
for(int i=0;i<=11;i++) {
if(data[i] > 1) {
return -1;
}
}
int result = 0;
int seed = 1;
for(int i=11;i>=0;i--) {
if(data[i] == 1) {
result += seed;
}
seed = seed * 2;
}
return result;
}
int getDistance(){
long duration;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
return (duration/2) / 29.1;
}
In our project, the tb752a1 card was used as a motor drive. Also
with atmega328 processor speed will add speed. A 3.7volt lipo is
used as a power supply in the robot, both small and lightweight.
But I have used the DC-DC converter to amplify the voltage
because the 3.7 volts voltage is insufficient for the robot
NECESSARY MATERIALS
1- Baby Orangutan B-328
2- Pololu 10: 1 Geared Motor x2
3-QTR-8A line tracing sensor
4- Pololu 32 × 7 mm wheel
5- 3/8 ″ drunk wheel
6- 2.5-9.5V converter
7- 3.7 volt lipo battery
//Leds. Salidas.
#define LEDR PORTB1
#define LEDV PORTB2
//Interruptores. Entradas.
#define PULSADOR PORTB0
//Sensores. Entradas y salidas.
#define D3 PORTD7
#define D2 PORTC5
#define D1 PORTC4
#define D0 PORTC3
#define I0 PORTC2
#define I1 PORTC1
#define I2 PORTC0
#define I3 PORTD4
#define LED_ON PORTD2
void inicializar_puertos(void);
void reset(void);
void M1_forward(unsigned char pwm);
void M1_reverse(unsigned char pwm);
void M2_forward(unsigned char pwm);
void M2_reverse(unsigned char pwm);
void motors_init(void);
int obtener_errorp(void);
void inicializar_timer1(void);
int obtener_errord(void);
char pulsador = 1;
inicializar_puertos();
motors_init();
reset();
while(pulsador != 0 )
{
pulsador = PINB & (1<<PULSADOR);
}
_delay_ms(500);
inicializar_timer1();
while ( 1 )
{
}
return 0;
}
void inicializar_puertos(void)
{
DDRD=0x6C; //0110 1100
PORTD=0x00;
DDRB=0x26; //0010 0110
PORTB=0x00;
DDRC=0x00; //0000 0000
PORTC=0x00;
}
void reset(void)
{
PORTB |= (1<<LEDV);
PORTB |= (1<<LEDR);
_delay_ms(300);
PORTB |= (1<<LEDV);
PORTB |= (1<<LEDR);
_delay_ms(300);
PORTB |= (1<<LEDV);
PORTB |= (1<<LEDR);
}
int obtener_errorp(void)
{
char errorp=0;
static char ultimo_errorp=0;
char contador_sensor=0;
if(contador_sensor != 0)
{
errorp = errorp / contador_sensor;
ultimo_errorp = errorp;
return(Kp * (int)errorp);
}
else
{
if(ultimo_errorp < 0)
errorp = -0x09;
else
errorp = 0x09;
ultimo_errorp = errorp;
return((int)errorp * Kp);
}
}
int obtener_errord(void)
{
int error = 0;
static int error_old = 0;
static int errord=0;
static int errord_old = 0;
static int tic = 1; // 1
static int tic_old = 1; //
int diferencia = 0;
if(((PINC & 0x04) != 0) && ((PINC & 0x08) != 0))
error=0;
else
{
if (error_old < 0) error = -9; else if(error_old > 0)
error = 9;
}
}
else
{
tic++;
diferencia = error - error_old;
errord = Kd*(diferencia)/tic; //error medio
errord_old = errord;
tic_old=tic;
tic=0;
}
error_old = error;
return(errord);
}
ISR(TIMER1_COMPA_vect)
{
int errort=0;
int proporcional = obtener_errorp();
int derivativo = obtener_errord();
else
{
M2_forward(velocidad);
M1_forward(velocidad);
PORTB &= ~(1<<LEDR);
PORTB &= ~ (1<<LEDV);
}
TIFR1 |= (1<<OCF1A);
}
#include <Servo.h>
#include <NewPing.h>
#define LeftMotorForward 9
#define LeftMotorBackward 10
#define RightMotorForward 11
#define RightMotorBackward 12
#define USTrigger 6
#define USEcho 7
#define MaxDistance 100
#define LED 13
Servo servo;
NewPing sonar(USTrigger, USEcho, MaxDistance);
void setup()
{pinMode(LeftMotorForward, OUTPUT);
pinMode(LeftMotorBackward, OUTPUT);
pinMode(RightMotorForward, OUTPUT);
pinMode(RightMotorBackward, OUTPUT);
pinMode(LED, OUTPUT);
servo.attach(4);
}
void loop()
{
delay(500);
servo.write(90);
scan();
FrontDistance = distance;
if(FrontDistance > 40 || FrontDistance == 0)
{
moveForward();
}
else
{
moveStop();
servo.write(167);
delay(500);
scan();
LeftDistance = distance;
servo.write(0);
delay(500);
scan();
RightDistance = distance;
if(RightDistance < LeftDistance)
{
moveLeft();
delay(500);
}
else if(LeftDistance < RightDistance)
{
moveRight();
delay(500);
}
else
{
moveBackward();
delay(200);
moveRight();
delay(200);
}
}
}
void moveForward()
{
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(RightMotorForward, HIGH);
}
void moveBackward()
{
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
}
void moveLeft()
{
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(RightMotorForward, HIGH);
void moveRight()
{
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
}
void moveStop()
{
digitalWrite(LeftMotorBackward, LOW);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
}
void scan()
{
delay(50);
Time = sonar.ping();
distance = Time / US_ROUNDTRIP_CM;
}
Arduino
Arduino Uno
QTR-8RC Infrared Sensor
L293D Motor Driver Board
Robot Kit
#include <AFMotor.h>
#include <QTRSensors.h>
#define KP .2
#define KD 5
#define M1_minumum_hiz 120
#define M2_minumum_hiz 120
#define M1_maksimum_hiz 210
#define M2_maksimum_hiz 210
#define MIDDLE_SENSOR 3
#define NUM_SENSORS 5
#define TIMEOUT 2500
#define EMITTER_PIN 2
#define DEBUG 0
void setup()
{
delay(1500);
manual_calibration();
set_motors(0,0);
}
int lastError = 0;
int last_proportional = 0;
int integral = 0;
void loop()
{
unsigned int sensors[5];
int position = qtrrc.readLine(sensors);
int error = position - 2000;
void manual_calibration() {
int i;
for (i = 0; i < 250; i++)
{
qtrrc.calibrate(QTR_EMITTERS_ON);
delay(20);
}
if (DEBUG) {
Serial.begin(9600);
for (int i = 0; i < NUM_SENSORS; i++)
{
Serial.print(qtrrc.calibratedMinimumOn[i]);
Serial.print(' ');
}
Serial.println();
In this project, we will talk about how the tank robot is made.
With Arduino you can do many projects in a simple way. Due to
the fact that it is an open source library, arduino has been used
too much. This project includes a tracked tank made with
Arduino Nano.
NECESSARY MATERIALS
#include <Servo.h>
Servo leftDrive;
Servo rightDrive;
int pos = 0;
void setup()
{
leftDrive.attach(11);
rightDrive.attach(10);
}
void loop()
{
}
void turnRight()
{
leftDrive.write(0);
rightDrive.write(180);
delay(450);
}
void driveBackward()
{
leftDrive.write(0);
rightDrive.write(0);
delay(1000);
}
24) SUMO ROBOT PROJECT WITH ARDUiNO
In this article, we will program and run the sumo robot chassis
we created with 3D printing in arduino. This robot, which is
prepared with the most basic and cheapest materials, will be able
to make your own in your home easily.NECESSARY
MATERIALS
Arduino Uno
L298N motor drive
Sumo robot chassis
MZ80 distance sensor
100 rpm micro motor (2 pcs)
Micro motor compatible wheel
7.4v lipo battery
First, solder the jumper cable to the motors. Then place the
motors with hot silicone into the chassis as shown in the picture.
Make sure the engines are level. After the silicones have dried,
mount the MZ80 distance sensor in the front slot, using the
screw on the end of the sensor and insert it into the slot.
Finally, screw a flat plate onto the chassis or attach it to the
silicone. You will place the arduino and motor drive on the plate.
Scheme showing the links of our Project
Deviation Codes
void setup()
{
Serial.begin(9600);
pinMode(ileri,OUTPUT);
pinMode(geri,OUTPUT);
pinMode(sag,OUTPUT);
pinMode(sol,OUTPUT);
pinMode(inputPin, INPUT);
void loop(){
val = digitalRead(inputPin);
Serial.println(val);
if (val == 1) {
digitalWrite(ileri, HIGH);
digitalWrite(sag, HIGH);
digitalWrite(geri, LOW);
digitalWrite(sol, LOW);
}
else if (val == 0) {
digitalWrite(geri, HIGH);
digitalWrite(sol, HIGH);
digitalWrite(ileri, LOW);
digitalWrite(sag, LOW);
}
}
NECESSARY MATERIALS
1 pcs arduino uno
1 pcs l298n motor driver
1 IR sensor
1 control
2 pcs robot and battery for arduino
1 pcs robot kit or toy car
#include <IRremote.h>
int RECV_PIN = 11;
int sagileri = 2;
int saggeri = 3;
int solileri = 4;
int solgeri = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(sagileri, OUTPUT);
pinMode(saggeri, OUTPUT);
pinMode(solileri, OUTPUT);
pinMode(solgeri, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[1] = 0;
} else {
digitalWrite(sagileri, HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[1] = 1;
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[2] = 0;
} else {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, HIGH);
digitalWrite(solgeri, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[3] = 0;
} else {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, HIGH);
digitalWrite(solgeri, LOW);
itsONled[3] = 1;
}
break;
case code4:
if(itsONled[4] == 1) {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[4] = 0;
} else {
digitalWrite(sagileri,HIGH);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, HIGH);
itsONled[4] = 1;
}
break;
case code5:
if(itsONled[5] == 1) {
digitalWrite(sagileri, LOW);
digitalWrite(solileri, LOW);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
itsONled[5] = 0;
} else {
digitalWrite(sagileri,HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, HIGH);
digitalWrite(solgeri, HIGH);
itsONled[4] = 1;
}
break;
}
Serial.println(value);
irrecv.resume();
}
}
26) ARDUiNO ANDROID CONTROLLED RC CAR
PROJECT
You can easily perform many operations with your Android
phones. At the end of this project you will have an android
controlled rc car. You can make yourself a car by following the
steps below. The purpose of the project is to control your car via
bluetooth as you wish, thanks to the program you install on your
mobile phone.
NECESSARY MATERIALS
1- Arduino UNO
2-L293B Motor Driver
3- HC-06 Bluetooth Module
4- RC Toy Car
void setup()
{
Serial.begin(9600);
pinMode(pinileri, OUTPUT);
pinMode(pingeri, OUTPUT);
pinMode(pinsol, OUTPUT);
pinMode(pinsag, OUTPUT);
}
void loop()
{
det = check();
while (det == 'F')
{
digitalWrite(pinileri, HIGH);
det = check();
}
while (det == 'B')
{
digitalWrite(pingeri, HIGH);
det = check();
}
{
digitalWrite(pinsol, HIGH);
det = check();
}
while (det == 'R')
{
digitalWrite(pinsag, HIGH);
det = check();
}
while (det == 'G')
{
digitalWrite(pinileri, HIGH);
digitalWrite(pinsol, HIGH);
det = check();
}
while (det == 'I')
{
digitalWrite(pinileri, HIGH);
digitalWrite(pinsag, HIGH);
det = check();
}
while (det == 'H')
{
digitalWrite(pingeri, HIGH);
digitalWrite(pinsol, HIGH);
det = check();
}
while (det == 'J')
{
digitalWrite(pingeri, HIGH);
digitalWrite(pinsag, HIGH);
det = check();
}
while (det == 'S')
{
digitalWrite(pinileri, LOW);
digitalWrite(pingeri, LOW);
digitalWrite(pinsol, LOW);
digitalWrite(pinsag, LOW);
det = check();
}
}
int check()
{
if (Serial.available() > 0)
{
dataIn = Serial.read();
if (dataIn == 'F')
{
determinant = 'F';
}
else if (dataIn == 'B')
{
determinant = 'B';
}
else if (dataIn == 'L')
{
determinant = 'L';
}
else if (dataIn == 'R')
{
determinant = 'R';
}
else if (dataIn == 'G')
{
determinant = 'G';
}
else if (dataIn == 'I')
{
determinant = 'I';
}
else if (dataIn == 'H')
{
determinant = 'H';
}
else if (dataIn == 'J')
{
determinant = 'J';
}
else if (dataIn == 'S')
{
determinant = 'S';
}
}
return determinant;
}