Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Report Robotic programming using Arduino

274 views

Published on

  • Be the first to comment

  • Be the first to like this

Report Robotic programming using Arduino

  1. 1. LIGHT SENSOR ROBOT USING ARDUINO MACHINE LEARNING CSC NAME: A’INUR A’FIFAH BT AMRI MATRIC NO: 1117372 INSTRUCTOR: MADAM AMELIA RITAHANI
  2. 2. ABSTRACT The report explains the basic usage of Arduino board and how to program it the way the programmers wanted. Step by step approach of Arduino programming is briefly explained in the report, starting by the blinking of LED, the movement of the motor and eventually a robot that sense and move towards the light. INTRODUCTION Arduino is a single-board microcontroller to make using electronics in multidisciplinary projects more accessible. It is an important tool for inventors around the world because of its flexibility that allows anyone to program anything using the Arduino board to achieve their own goals. In this report, the goal is to program a robot that moves toward strong intensity of light. The approach is simple, do a step-by-step programming and eventually put them together. MATERIALS AND METHOD The materials needed are very basic as well, which are the Arduino board, a few LED lights, motors and the assembled robot. As mentioned previously, the method is baby steps, where the program is from a blinking LED to a moving robot.
  3. 3. RESULTS 1. LED blinking program int led = 13; int led2 = 10; int led3 = 7; int led4 = 4; void setup() { pinMode(led, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); delay(100); digitalWrite(led2, HIGH); delay(100); digitalWrite(led2, LOW); delay(100); digitalWrite(led3, HIGH); delay(100); digitalWrite(led3, LOW); delay(100); digitalWrite(led4, HIGH); delay(100); digitalWrite(led4, LOW); delay(100); }
  4. 4. 2. LED blinking with light sensor int led = 13; int led2 = 10; int led3 = 7; int led4 = 4; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(led, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0);
  5. 5. Serial.println(sensorValue); if(sensorValue < 500) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(100); digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led3, LOW); // turn the LED off by making the voltage LOW delay(100); } else { digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW delay(100); digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(led4, LOW); // turn the LED off by making the voltage LOW delay(100); } } Before
  6. 6. After 3. Single motor movement #include <Stepper.h> const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor Stepper myStepper(stepsPerRevolution, 24,10,9,11); void setup() { myStepper.setSpeed(60); // initialize the serial port: Serial.begin(9600); } void loop() { // step one revolution in one direction: Serial.println("clockwise"); myStepper.step(1); }
  7. 7. 4. Light robot int E1 = 5; int M1 = 4; int E2 = 6; int M2 = 7; int value; // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(M1, OUTPUT); pinMode(M2, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); int sensorValue1 = analogRead(A1); // print out the value you read: Serial.print(sensorValue); Serial.print(" : "); Serial.println(sensorValue1); delay(10); // delay in between reads for stability stp(); if(sensorValue >850 && sensorValue1 >900 ) {
  8. 8. fwd(); } else if(sensorValue > 850 && sensorValue1 < 900 ) { left(); } else if(sensorValue < 850 && sensorValue1 > 900 ) { right(); } } void fwd(){ for(value = 0 ; value <= 1; value++) { digitalWrite(M1,LOW); digitalWrite(M2, LOW); analogWrite(E1, 150); //PWM Speed Control analogWrite(E2, 150); //PWM Speed Control delay(30); }} void right(){ for(value = 0 ; value <= 1; value++) { digitalWrite(M1,LOW); digitalWrite(M2, LOW); analogWrite(E1, 0); //PWM Speed Control analogWrite(E2, 150); //PWM Speed Control delay(30); }} void left(){ for(value = 0 ; value <= 1; value++) { digitalWrite(M1,LOW); digitalWrite(M2, LOW); analogWrite(E1, 150); //PWM Speed Control analogWrite(E2, 0); //PWM Speed Control delay(30); }}
  9. 9. void stp(){ for(value = 0 ; value <= 1; value++) { digitalWrite(M1,LOW); digitalWrite(M2, LOW); analogWrite(E1, 0); //PWM Speed Control analogWrite(E2, 0); //PWM Speed Control delay(30); }} Without light With light
  10. 10. DISCUSSION The experiment was proven to be successful. A robot that moves towards the light was programmed. The step by step approach gave an understandable insight for a beginner in programming for Arduino board. The experiment went smoothly since it uses the basic programming structure, although there were some difficulties encountered during the phase of rotating the motor. The limitation of the final goal was that even though the robot achieved the goal of moving towards light, it could have more special features like implementing the buzzer or LED light blinking when it goes to the light. CONCLUSION
  11. 11. The conclusion of the project is that there are some difficulties occurred despite the smooth flow of the mini experiments. However, the goal was achieved. Recommended improvement could be some bonus features to the robot besides moving towards the light, such as buzzer sound and LED blinking simultaneously. REFERENCES 1. 123d.org 2. Jeremy Blum tutorials

×