Arduino Coding

WEEK 9 – Arduino LED Blink:


For this week, we were given the task of making an LED within an Arduino Uno to blink and mainly learning about Arduino coding. We were all given an Arduino kit that consisted of different types of tools needed for the Arduino. To begin, we had to connect the USB cable from the Arduino port to a USB port in the computer. After this we had to open up the Arduino software to begin our coding.

This is the code we used to make the LED in our Arduino blink. Once we had a normal blink going in or Arduino, we were tasked the change the code slightly so that the LED would blink faster. I did this by changing the line of code delay (1000) to delay (100). Because the delay is measured in milliseconds, I reduced the delay from 1000 ms to 100 ms. This would make the LED blink faster as the delay in the code is shorter.

WEEK 10 – Arduino Stepper Motor:


For this week, our task was to program a stepper motor to move. A stepper motor is an electronic direct current (DC) component that moves in very small steps. They have multiple coils that are organised in groups called Phases. By energising each phase in sequence, the motor will rotate, one step at a time.

WEEK 11 – Arduino Display:


For this week, our session was focused on coding a display to show a message from an Arduino code. To start things off, I got out my Arduino and connected it to the computer, making sure I’ve selected the right port. Once my Arduino was connected, we were told to open up a zip file on student central marked LCD_Serial_dec15a. We needed to save this file in our libraries so we could open it into Arduino. Once saved, I opened this zip file into the Arduino software and code appeared in the screen.

To display a message of my own, I had to change the part of the code which states the message to be displayed. To begin with, the default code is programmed to display the message ‘University of Brighton – Hello World’. To make sure that code actually works, I uploaded the default code into the Arduino and I wanted the display to say University of Brighton – Hello World, and it did, meaning the Arduino was working as well as the code. To change the message, all I did was simply change the part of the code which says the display text to a different text. I changed the display code from’University of Brighton – Hello World’ to ‘LUCAS MOURA – absolute scenes’. To make sure the display shows this, I uploaded the code into the Arduino and eventually, the displayed showed my changed display code.

Our next task was the use a sensor to measure the range of an object close to it and to show that range in the display. To accomplish this, two codes were required. One is the display code we already have and the other is the code to measure distances with the sensor supplied to us. To make the code work together, I opened both the display code and the sensor code into the same program. To make them work together however was a different task. To make sure that the sensor code was working, I uploaded the code into the Arduino and placed my hand next to the sensor. At first, I wasn’t sure how to see if the sensor was working, then with some teacher assistance, he showed a part of the software where I could see the numbers change as I moved my hand around the sensor.

The next task was to show these numbers into the display. To do this, I had to insert some part of the display code into the sensor code. I copied the part of the display code which displays the message into a certain place of the sensor code. Once this was done, the code should work in a way in which when my hand gets near the sensor, the display should show the distance. Which it did.

 

 

 

 

 

 

 

 

 

WEEK 12 – Arduino Robotics:


For this week, our final Arduino task was to create a functioning robot in which we will be doing in groups. To begin, we needed to get the parts required for the task in hand. The parts required were a chassis for all the components to be applied to, 2 wheels and 2 motor connectors in which where the wheels will be connected. We also needed two motors (one from each group member) to drive the wheels in our desired direction according to our code. To program our robot we need an Arduino and a Programming component (shown as the green component), these will be placed on top of each other. Lastly, we need all the nuts and screws to screw everything together (13 of each required). Once all the components required were all together, me and my group could begin on the actual physical making of the robot.

Using some of the screws and nuts, we attached them to the chassis by inserting the screws into certain holes in the chassis and then inserting the nuts underneath.

Once all the screws and nuts we attached, we then had to attach the Arduino the the chassis using the same screws we placed in at first. Our next job was to place and screw the green programming component of the Arduino as shown below:

Next we need to screw the motor connectors onto to the chassis by using screws (inserting them aside the motor connectors) and nuts to hold it in place. Then we needed to attach the actual motor inside the motor connector. The same process applied for the other side of the chassis.

Once all the components were attached, we could then make a start on the coding part of this task. This is the code we used to program our robot to make it move forwards, backwards, left and right.

// the setup function runs once when you press reset or power the board
void setup()
{
// initialize digital coil A as an output.
pinMode(10, OUTPUT);
// initialize digital coil B as an output.
pinMode(11, OUTPUT);
// initialize digital coil C as an output.
pinMode(12, OUTPUT);
// initialize digital coil D as an output.
pinMode(13, OUTPUT);
//motor 2
pinMode(6, OUTPUT);
// initialize digital coil B as an output.
pinMode(7, OUTPUT);
// initialize digital coil C as an output.
pinMode(8, OUTPUT);
// initialize digital coil D as an output.
pinMode(9, OUTPUT);

}

int i=0;

void loop() {

while(i < 1000){
right();
i++;

}
}

void forward()
{
//STEP 1
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 3
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 4
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(2); // delay

//motor2
//STEP 1
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(2); // delay
//STEP 3
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(2); // delay
//STEP 4
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(2); // delay
}

void backward()
{
//STEP 1
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 3
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 4
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(2); // delay


//motor2
//STEP 1
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
delay(2); // delay
//STEP 3
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
delay(2); // delay
//STEP 4
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
delay(2); // delay
}


void right()
{
//STEP 1
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
delay(2); // delay
//STEP 3
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
delay(2); // delay
//STEP 4
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(2); // delay


//motor2
//STEP 1
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
delay(2); // delay
//STEP 3
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, LOW);
delay(2); // delay
//STEP 4
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
delay(2); // delay
}


void left()
{
//STEP 1
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 3
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(2); // delay
//STEP 4
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(2); // delay


//motor2
//STEP 1
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(2); // delay
//STEP 2
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(2); // delay
//STEP 3
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(2); // delay
//STEP 4
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(2); // delay
}

Once the program was uploaded we noticed that nothing was happening. We investigated the code and saw nothing wrong it and then looked into our robot and we couldn’t see anything wrong. After a while of investigations, we found that the problem was that our robot was short circuited, meaning it won’t work. By replacing some of the components and re srewing carefully. Our robot was finally working. I was moving forwards, backwards, left and right.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *