Playing with
Arduino + Robotis Parts
i recommend watch this video on youtube for better quality:
https://www.youtube.com/watch?v=xmYYOmiEVDI
https://www.youtube.com/watch?v=xmYYOmiEVDI
Security Gates
In this post i just use serial monitor and keyboard.
This is really simple tutorial. Its take around 30minutes.
In this tutorial, i use:
-Arduino Mega 2560
-Robotis Play600 parts.
In this tutorial, i use:
-Arduino Mega 2560
-Robotis Play600 parts.
-Motor Driver L293D
-Red and Green LED.
-Breadboard
-Jumper Cables
Actually Robotis Play600 Pets looks so boring, then i just wanna make it become more interesting by using Arduino. I think this robotis play600 cheaper than other robotis model. I dont know how much because i got this for free. I got this during lucky draw Fira Roboworld Cup. I'm so lucky. So i make this during my weekend......
1. Open the body and solder two female jumper cables at the battery casing.
Like this!
-Unscrew the screw and open this part
-Solder the jumper cables to DC motor cables(at battery casing). I do this because i want to
drive the DC motor inside using a motor driver.
Maybe this image can help you to understand what i mean :)
drive the DC motor inside using a motor driver.
Maybe this image can help you to understand what i mean :)
After finish, assemble and screw them up!
2. Wiring between Arduino, Motor Driver, and Robotis
Connect the wiring like this.
In my video i use only 5V power supply to power up the motor. I'm not using any battery, i use from Arduino 5V pin.
Make sure your circuit is correct.
In my video i use only 5V power supply to power up the motor. I'm not using any battery, i use from Arduino 5V pin.
Make sure your circuit is correct.
Dont forget to include the Green and Red LED in the circuit!
3. Assemble your Robotis Parts
-Assemble them as creative as creative can.
this is mine.
4. Arduino Code
Once you've finished, now you ready to upload the code!
This is my code. You can copy and paste or directly download here .
String password_input;
String pass = "zaki";
int gateup = 7;
int gatedown = 8;
int stopp = 9;
int go = 10;
void setup()
{
Serial.begin(9600); //baud rate
pinMode(gateup, OUTPUT); //pin for gate up
pinMode(gatedown, OUTPUT); //pin for gate going down
pinMode(stopp, OUTPUT); //red led pin
pinMode(go, OUTPUT); //green led
Serial.println("Enter Password");
}
void loop()
{
digitalWrite(stopp, HIGH);
if (Serial.available() > 0)
{
password_input = Serial.readString(); //password key in by user
if (password_input == pass) //if password is correct
{
digitalWrite(stopp, LOW); //red led OFF
delay(500);
digitalWrite(go, HIGH); //green led is high
Serial.print("Password Received: "); //print on serial monitor
Serial.println(password_input);
delay(500);
analogWrite(gateup, 180); //open the gate
Serial.println("Gate Open");
delay(2500);
digitalWrite(gateup, LOW); //gate open for 2 seconds
Serial.println("delay 2 seconds......");
delay(1500);
digitalWrite(go, LOW); //green led OFF
delay(500);
digitalWrite(stopp, HIGH); //red led high
delay(500);
Serial.println("Gate Closed!");
analogWrite(gatedown, 150); //close the gate until get the correct password
delay(650);
digitalWrite(gatedown, LOW);
delay(500);
Serial.println("Please Enter Password"); //ask user to key in the password again
}
else
{
Serial.print("Password Received: "); //if the password is invalid
Serial.println(password_input);
Serial.println("Invalid Password!");
Serial.println("Please enter the password again");
}
}
}
Code Explaination
String password_input;
-this string use for storing the password that user key in
String pass = "zaki";
-this string is the password. User need to key in "zaki" at serial monitor to open the gate.
-you can change the password with modify this string like this:
-you can change the password with modify this string like this:
String pass = "the password you want";
example:
example:
String pass = "vnsicxx34kjx";
int gateup = 7;
-pin on arduino that i use to open the gate.
int gatedown = 8;
-pin on arduino that i use to close the gate.
int stopp = 9;
-pin on arduino that i use to Red LED.
int go = 10;
-pin on arduino that i use to Green LED.
Serial.begin(9600);
-baud rate
pinMode(gateup, OUTPUT);
-Set pin gateup as output
pinMode(gatedown, OUTPUT);
-Set pin gatedown as output
pinMode(stopp, OUTPUT);
-set red led pin as output
pinMode(go, OUTPUT);
-set green led pin as output
Serial.println("Enter Password");
-ask user to enter the password on serial monitor
digitalWrite(stopp, HIGH);
-Red LED always ON because gate always close
if (Serial.available() > 0)
-If serial communication with Arduino is available(check), all code ready to execute. If not, code
never to execute
never to execute
password_input = Serial.readString();
-read the password that key in by user in string
-read the password that key in by user in string
if (password_input == pass)
{
digitalWrite(stopp, LOW); //red led OFF
delay(500);
digitalWrite(go, HIGH); //green led is high
Serial.print("Password Received: "); //print on serial monitor
Serial.println(password_input);
delay(500);
analogWrite(gateup, 180); //open the gate
Serial.println("Gate Open");
delay(2500);
digitalWrite(gateup, LOW); //gate open for 2 seconds
Serial.println("delay 2 seconds......");
delay(1500);
digitalWrite(go, LOW); //green led OFF
delay(500);
digitalWrite(stopp, HIGH); //red led high
delay(500);
Serial.println("Gate Closed!");
analogWrite(gatedown, 150); //close the gate until get the correct password
delay(650);
digitalWrite(gatedown, LOW);
delay(500);
Serial.println("Please Enter Password"); //ask user to key in the password again
}
-All of this code will be execute if the user enter the correct password
else
{
Serial.print("Password Received: "); //if the password is invalid
Serial.println(password_input);
Serial.println("Invalid Password!");
Serial.println("Please enter the password again");
}
-this code will be executed if user enter the incorrect password
-print "Invalid Password" and "Please enter the password again"
-print "Invalid Password" and "Please enter the password again"
If you have any problem with wiring, you can refer my older post about L293D and Blink More Than 1 LEDs
No comments:
Post a Comment