Вы находитесь на странице: 1из 17

NOTA KURSUS :

BENGKEL ASAS ROBOTIK BERASASKAN ARDUINO UNO

TEMPAT:
DEWAN SRI TUNJONG
JPN KELANTAN

TARIKH:
3 DAN 4 JULAI 2018

PENCERAMAH KURSUS:
1. NIK NOR HISHAMUDDIN BIN NIK MUSTAPHA(019-9757282)

2. RAMLI BIN MOHAMED (013-9270378)

1
FIG 1 - COMPLETE CIRCUIT FOR SUMO ROBOT WIRELESS CONTROL USING BLUETOOTH

2
FIG 2 – LED CIRCUIT

FIG 3 – HOW TO MAKE LED ON AND OFF

3
//PROG1: ALL LEDS BLINKING EVERY 1 SECOND
void setup() {
pinMode(8,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
digitalWrite(8,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(8,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(1000);
}
//END

EXERCISE:

1. Write a program to make a running light

4
FIG 4 – COMMON CATHODE 7-SEGMENT

FIG 5 – COMMON CATHODE 7-SEGMENT PIN CONFIGURATION

5
SEGMENT A B C D E F G NUMBER
PIN NO: 7 8 11 12 13 6 1 DISPLAY
HIGH HIGH HIGH HIGH HIGH HIGH LOW 0
LOW HIGH HIGH LOW LOW LOW LOW 1
2
3
4
5
6
7
8
9
TABLE 1 – LOGIC LEVEL FOR COMMON CATHODE 7-SEGMENT (pls FILL IN THE BLANK)

//PROG2: DISPLAY NUMBER 0 TO 1 ON 7-SEGMENT COMMON CATHODE


void setup() {
pinMode(1,OUTPUT);
pinMode(6,OUTPUT);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
}
//display number ‘0’
void loop() {
digitalWrite(1,LOW);//g
digitalWrite(6,HIGH);//f
digitalWrite(13,HIGH);//e
digitalWrite(12,HIGH);//d
digitalWrite(11,HIGH);//c
digitalWrite(8,HIGH);//b
digitalWrite(7,HIGH);//a
delay(1000);//delay 1000 milli secs

6
//display number ‘1’
digitalWrite(1,LOW);//g
digitalWrite(6,LOW);//f
digitalWrite(13,LOW);//e
digitalWrite(12,LOW);//d
digitalWrite(11,HIGH);//c
digitalWrite(8,HIGH);//b
digitalWrite(7,LOW);//a
delay(1000); //delay 1000 milli secs
}//END

EXERCISE:
1. Display your phone number on 7-segment using 1 second delay in between
numbers.

7
FIG 6 – SUMO ROBOT RIGHT & LEFT MOTOR PIN CONNECTION

FIG 7 – SUMO ROBOT DIAGRAM


LEFT MOTOR LEFT RIGHT MOTOR RIGHT ROBOT
5 4 MOTOR 3 2 MOTOR DIRECTION
DIRECTION DIRECTOR
LOW HIGH FORWARD LOW HIGH FORWARD FORWARD
HIGH LOW REVERSE HIGH LOW REVERSE REVERSE
LOW HIGH FORWARD LOW LOW STOP TURN RIGHT
LOW LOW STOP LOW HIGH FORWARD TURN LEFT
SPIN CW
SPIN CCW
STOP
TABLE 2 – CONTROL SIGNAL (LOGIC LEVEL) FOR SUMO ROBOT (pls
FILL IN THE BLANK)

8
//PROG3: ROBOT FORWARD
void setup() {
pinMode(2,OUTPUT);//RIGHT MOTOR
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);//LEFT MOTOR
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);//SPEED CONTROL RIGHT MOTOR
pinMode(10,OUTPUT);//SPEED CONTROL LEFT MOTOR
}
void loop() {
analogWrite(9,255);//speed maxima RIGHT motor
analogWrite(10,255);//speed maxima LEFT motor
digitalWrite(2,HIGH); //RIGHT MOTOR FORWARD
digitalWrite(3,LOW);
digitalWrite(4,HIGH); //LEFT MOTOR FORWARD
digitalWrite(5,LOW);
}//END

//PROG4: ROBOT REVERSE


void setup() {
pinMode(2,OUTPUT);//RIGHT MOTOR
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);//LEFT MOTOR
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);//SPEED CONTROL RIGHT MOTOR
pinMode(10,OUTPUT);//SPEED CONTROL LEFT MOTOR
}

9
void loop() {
analogWrite(9,255);//speed maxima RIGHT motor
analogWrite(10,255);//speed maxima LEFT motor
digitalWrite(2,LOW); //RIGHT MOTOR REVERSE
digitalWrite(3,HIGH);
digitalWrite(4,LOW); //LEFT MOTOR REVERSE
digitalWrite(5,HIGH);
}//END

//PROG5: ROBOT SPIN CLOCKWISE


void setup() {
pinMode(2,OUTPUT);//RIGHT MOTOR
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);//LEFT MOTOR
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);//SPEED CONTROL RIGHT MOTOR
pinMode(10,OUTPUT);//SPEED CONTROL LEFT MOTOR
}
void loop() {
analogWrite(9,255);//speed maxima RIGHT motor
analogWrite(10,255);//speed maxima LEFT motor
digitalWrite(2,LOW); //RIGHT MOTOR REVERSE
digitalWrite(3,HIGH);
digitalWrite(4,HIGH); //LEFT MOTOR FORWARD
digitalWrite(5,LOW);
}

10
//PROG6: ROBOT SPIN CONTER-CLOCKWISE
void setup() {
pinMode(2,OUTPUT);//RIGHT MOTOR
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);//LEFT MOTOR
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);//SPEED CONTROL RIGHT MOTOR
pinMode(10,OUTPUT);//SPEED CONTROL LEFT MOTOR
}
void loop() {
analogWrite(9,255);//speed maxima RIGHT motor
analogWrite(10,255);//speed maxima LEFT motor
digitalWrite(2,HIGH); //RIGHT MOTOR FORWARD
digitalWrite(3,LOW);
digitalWrite(4,LOW); //LEFT MOTOR REVERSE
digitalWrite(5,HIGH);
}//END

11
//PROG7: ROBOT USING BLUETOOTH
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A4,A5); // RX, TX
char state;

void setup() {
Serial.begin(9600);
mySerial.begin(9600); // initialize serial communication:
pinMode(2,OUTPUT);//RIGHT MOTOR
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);//LEFT MOTOR
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);//SPEED CONTROL RIGHT MOTOR
pinMode(10,OUTPUT);//SPEED CONTROL LEFT MOTOR
}

void loop(){
if(mySerial.available() > 0)
state = mySerial.read();
if(state=='A')
forward();
if(state=='B')
reverse();
if(state=='C')
turnLeft();
if(state=='D')
turnRight();
if(state=='E')
stopRobot();

12
if(state=='F')
spinCW();
if(state=='G')
spinCCW();
}

void forward()
{
Serial.println("Forward");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,HIGH);//RIGHT FORWARD
digitalWrite(3,LOW);
digitalWrite(4,HIGH);//LEFT FORWARD
digitalWrite(5,LOW);
}

void reverse()
{
Serial.println("reverse");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,LOW); //RIGHT REVERSE
digitalWrite(3,HIGH);
digitalWrite(4,LOW); //LEFT RESERVE
digitalWrite(5,HIGH);
}

13
void turnLeft()
{
Serial.println("Turn Left");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,HIGH); //RIGHT FORWARD
digitalWrite(3,LOW);
digitalWrite(4,LOW); //LEFT STOP
digitalWrite(5,LOW);
}
void turnRight()
{
Serial.println("Turn Right");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,LOW); //RIGHT STOP
digitalWrite(3,LOW);
digitalWrite(4,HIGH); //LEFT FORWARD
digitalWrite(5,LOW);
}
void stopRobot()
{
Serial.println("stop");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,LOW); //RIGHT STOP
digitalWrite(3,LOW);
digitalWrite(4,LOW); //LEFT STOP
digitalWrite(5,LOW);
}

14
void spinCW()
{
Serial.println("spinCW");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,LOW); //RIGHT REVERSE
digitalWrite(3,HIGH);
digitalWrite(4,HIGH); //LEFT FORWARD
digitalWrite(5,LOW);
}

void spinCCW()
{
Serial.println("spinCCW");
analogWrite(9,255);//speed maxima RIGHT motor( 0 MIN 255 MAX)
analogWrite(10,255);//speed maxima LEFT motor( 0 MIN 255 MAX)
digitalWrite(2,HIGH); //RIGHT FORWARD
digitalWrite(3,LOW);
digitalWrite(4,LOW); //LEFT REVERSE
digitalWrite(5,HIGH);
}

15
NOTES:

16
NOTES:

17