Pages: [1]   Go Down
Author Topic: My First Programme  (Read 559 times)
0 Members and 1 Guest are viewing this topic.
Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all! After moving up to a new school and taking robotics as an option,
I thought I would impress my teacher by building a simple robot for the
first lesson (tee hee!) ;D. With the exception of playing around with the
onboard LED I have never programmed it before though, so, after
scrolling through the examples I added, adapted, written and produced
my own program based on the digital example "button". Here it is:


 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int relayPin =  12;      // the number of the motor reversing pin
const int motorPin =  8;      // the number of the turning pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the motor pin as an output:
  pinMode(motorPin, OUTPUT);
// initialize the relay pin as an output:
  pinMode(relayPin, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn reversing pin on:    
    digitalWrite(relayPin, HIGH);
   delay(500);          
  //wait half a second
   digitalWrite(relayPin, LOW);
  //sends robot forwards
    digitalWrite(motorPin, HIGH);
  //turns robot
    delay(500);
  //pause half a second
    digitalWrite(motorPin, LOW);
  //sends robot forward again
  }
  else {
    // turn LED off:
    digitalWrite(relayPin, LOW);
    digitalWrite(motorPin, LOW);
  }
}



What I was wondering is quite simple: will it work? The idea starts off
similar to the schmatic shown in the example, using a micro swith
 instead of the tactile switch shown. If the robot drives into the wall it
closes the switch. This then activates a DPDT relay wired up as an
always on H-bridge and reverses the motors. After a set period of
time one motor goes forward again as the relay pin goes low, then
motor pin turns one of the motors off, causing the robot to turn. The
motor pin then goes low and the robot sets off in a different direction
to before untill it hits a wall and the whole process starts again. Thats
the idea anyway. Will it work though?

Thanks for your time, Onions.




Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and taking robotics as an option
You must go to a pretty wicked school, I wish I could have taken robotics...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah... me too...

Well done smiley
Logged

Pages: [1]   Go Up
Jump to: