i need code for the robot this robot have 6 IR sensor for read line
the line have black white and white black and i use 1 color sensor to read color red,yellow and blue after that the robot bring the cube to P position
and one more i have to use 6 button how to make the button as input like bluetooth command sending a text to call a case?
the primary function of button is the cube object must be taken by order that 6 order
i want to make each button to call case for take the cube by order
button 1 = BLUE,YELLOW,RED
button 2 = BLUE,RED,YELLOW
button 3 = YELLOW,BLUE,RED
button 4 = YELLOW,RED,BLUE
button 5 = RED,BLUE,YELLOW
button 6= RED,YELLOW,BLUE
anyone can help me?
Seems like school work.
What have you tried ?
Installation and Troubleshooting is for Problems with the Arduino itself NOT your project. It says so in the description of the section. Therefore I have moved your post here. Please be more careful where you post in future.
You may want to read this before you proceed:-
how to get the best out of this forum
Help in this project will require more information:
- What is the hardware involved (type of processor / board)?
- Do you already have information/drawing of your electrical configuration? If yes, post it please.
- Do you already have source code available that solves some of the requirements? If yes, please post it (using the code tags which you get by pressing this button on top of the editor window
and then place your code between the characters that appear as shown here
Is your question
- just concerning how to use buttons to create commands or
- are you expecting someone to assist you to fulfill the complete task from commands via button to moving the robot along black or white lines, fetching coloured boxes and placing them at certain fields?
The first task is easy and requires less information, the second will surely take longer time and needs much more data ...
i still make the robot this is for competition and i need the robot can work by order with out control it manually because if i control it it break the rule of competition
yes that my question i still make the robot and work in 6 order that why i need button but now i can use bluetooth and phone as button emulation to call a case
for now i have made manual transporter robot
this is the link running robot
and this is the robot
//servo
#include <Servo.h>
Servo capitkiri;
Servo capitkanan;
//pin L298N
int KECEPATAN1 = 11; //speed motor a
int in1 = 2; //motor a = +
int in2 = 3; //motor a = -
int in3 = 4; //motor b = -
int in4 = 9; //motor b = +
int KECEPATAN2 = 6; //speed motor b
//lifter
int KECEPATAN3 = 5 ;
int lifternaik = 10 ;//motor a = +
int lifterturun = 7 ; //motor a = -
int command; //Int to store app command state.
int Speed = 255;
int Speedsec ;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 20; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int remonoff = 1; //electronic brake nyala jika 1 normal jika 0
int pos = 90; //mengembalikan posisi servo semula
void setup() {
//driver motor
pinMode(KECEPATAN1, OUTPUT);
pinMode(KECEPATAN2, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
//driver lifter
pinMode(lifternaik, OUTPUT);
pinMode(lifterturun, OUTPUT);
//servo
capitkiri.attach(12);
capitkanan.attach(8);
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read();
Stop(); //Initialize with motors stoped.
switch (command) {
//kendali
case 'F':
maju();
break;
case 'B':
mundur();
break;
case 'L':
kiri();
break;
case 'R':
kanan();
break;
case 'G':
majukiri();
break;
case 'I':
majukanan();
break;
case 'H':
mundurkiri();
break;
case 'J':
mundurkanan();
break;
//lifter
case 'U':
naik();
break;
case 'D':
turun();
break;
//capit
case 'q':
capitkiri.write (135);
capitkanan.write (45);
break;
case 'e':
capitkiri.write (90);
capitkanan.write (90);
break;
//kecepatan
case '0':
Speed = 50;
break;
case '1':
Speed = 75;
break;
case '2':
Speed = 100;
break;
case '3':
Speed = 125;
break;
case '4':
Speed = 150;
break;
case '5':
Speed = 175;
break;
case '6':
Speed = 200;
break;
case '7':
Speed = 225;
break;
case '8':
Speed = 235;
break;
case '9':
Speed = 255;
break;
}
Speedsec = Turnradius;
if (remonoff == 1) {
brakeOn();
} else {
brakeOff();
}
}
}
//kendali
void maju() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speed);
}
void mundur() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speed);
}
void kiri() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speed);
}
void kanan() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speed);
}
void majukiri() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(KECEPATAN1, Speedsec);
analogWrite(KECEPATAN2, Speed);
}
void majukanan() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speedsec);
}
void mundurkanan() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(KECEPATAN1, Speed);
analogWrite(KECEPATAN2, Speedsec);
}
void mundurkiri() {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(KECEPATAN1, Speedsec);
analogWrite(KECEPATAN2, Speed);
}
void Stop() {
analogWrite(in1, 0);
analogWrite(in2, 0);
analogWrite(in3, 0);
analogWrite(in4, 0);
}
//lifter
void naik() {
digitalWrite(lifternaik, HIGH);
digitalWrite(lifterturun, LOW);
analogWrite(KECEPATAN3, Speed);
}
void turun() {
digitalWrite(lifterturun, HIGH);
digitalWrite(lifternaik, LOW);
analogWrite(KECEPATAN3, Speed);
}
void brakeOn() {
//Here's the future use: an electronic braking system!
// read the pushbutton input pin:
buttonState = command;
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == 'S') {
if (lastButtonState != buttonState) {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
analogWrite(lifterturun, LOW);
analogWrite(lifternaik, LOW );
delay(brakeTime);
Stop();
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}
void brakeOff() {
}
and now the committeen of the competition grant me use bluetooth as button emultion
Just Google for arduino Bluetooth serial.
You can use a Bluetooth terminal on Android phone to connect to it. It works like a serial terminal but uses Bluetooth.
For that i know how to use it but i just want it like just button to order line follower work order by order bring the box in right place
Wait you mean make a terminal that upload code everytime ?
No. I understood that you want to use Bluetooth instead of a pushbutton. That can be solved easily by Bluetooth Serial.
Unfortunately it is not clear to me what you really want (or have) to do...
The sketch you provided will not work with a real pushbutton. The machine is controlled by external serial commands only. There is no code that really reads a physical button state.
You can use Bluetooth to go from serial cable to a radio controlled version but this will not change the behavior of your sketch.
So what is the real goal of your request?=
My real goal is make line follower transporter that follow the color order from the rule at first post when i press the button that will run follow the line and pick the correct color cube combination there is 6 color combination that why i use 6 button when pressed that will take cube with same color order that my goal bro the competition start at friday 18
Ok. If the maze doesn't change you may code the way from start position to the different box positions by rules like "go forward along black line until you reach the second black crossing line. Turn left 90 deg. Go forward until you reach next black crossing line. Turn right 90 deg." and so on for each different task.
That's tedious but save as long as your robot knows where it is. Otherwise you could create a map of the lines in an array of data. For this you can cut the terrain into pieces of the minimum size to go (left, right, up, down) and code the possible directions in bits per field.
Yeah that right what you say i want like that routing line for robot and that I don't know how to route that can you give me example or one logic to route it ?
why are you participating in this competition if you don't know how to handle such code ? seems way above your capabilities for the time being.
and having the forum offer code for this is like cheating... It would not be your work.
For fisrt time i just made manual transporter like the video ,when visitation the comittee say one team must be have 2 robot and i have big problem about line follower
Doesn't problem it say cheating or else because the comittee doesnt care about it just join the comeptition and complete the mission and done
I hope you can help i really need help i must test the robot tomorrow to make sure ready
if you want the robot to be smart and the code to be generic (for any maze) it's a lot of work, using graph theory to calculate the shortest path etc. seems out of reach.
Hardwiring the 6 possible path in a program could be less difficult but you would still need a lot of work.
You would need to write functions for the primitives actions,
for example moving along the line (regardless of contrast) without changing direction:
goToNextCrossing();
goToBox(boxColor);
pickBox();
goToParking(boxColor);
dropBox();
and then two direction functions
turnLeft(angle);
turnRight(angle);
Once you have that you can hardwire a path: for example to grab the red cube from the start position and drop it you would have to hardcode the following instructions:
assuming your start being centered on the line
goToNextCrossing(); // (1)
turnLeft(90);
goToNextCrossing();
goToNextCrossing(); // (2)
turnLeft(90);
goToNextCrossing();
turnRight(90);
goToBox(red);
pickBox(); // (4)
turnRight(180); // (5)
goToNextCrossing(); // (6)
turnLeft(90°);
goToNextCrossing();
goToNextCrossing();
goToNextCrossing(); // mind the color change (7)
turnLeft(90°);
goToNextCrossing(); // (8)
turnRight(90);
goToNextCrossing(); // (9)
goToNextCrossing();
goToNextCrossing();
goToNextCrossing();
goToNextCrossing();
goToParking(red);
dropBox(); // (10)
you would have to hardcode then going from the red parking to the next box and again for the last box.
and then do the same for the 5 other possibilities.
of course Murphy says that if something can go bad, it will...
If you are unable to write the basic primitives, then this is just not a task for you. No point faking it. let the people who have done their work win...
Okey i will try it first doesnt matter i lose or not is about the robot run well for 1 cube and i learn from it that will be good for me and my school thx for the code i will try it