Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Tuesday, 10 March 2015

Last Laboratory Session

On Friday we had our last laboratory session. A lot of this time was spent neatening the circuit by shortening wires, making sure everything was on veroboard and soldered correctly ready to be placed inside the submarine body.



Testing and altering the sonar took most of the laboratory session we had to calculate the speed of sound underwater compared to air, this was approximately ¼ of the speed and so we have to alter the Arduino UNO code. However with these calculations and changing other variables within the code we still struggled to get the sonar working underwater. It is too late to get another component but the team agreed we should have got a sonar device specifically for underwater use rather than choosing a cheaper component.

The rest of the session was spent adding the circuit into the UAV and sealing it in and waterproofing it. Due to the sonar problems it has been left out of the circuit and we have put the backup code on the Arduino.



Finished result:



Unfortunately we have had problems with buoyancy and hoping to sort them out before the bench inspection.

Wednesday, 25 February 2015

AUV Arduino Code




Due to not having a variety of sensors and only one ultrasound, the AUV is coded so when it encounters a wall it will reverse and then turn right. Below is the code which was developed for the Arduino UNO. Resources used to develop code has been listed in the references at the bottom of the post.

--------------------------------------------------------------------------------------


#define LogicR1 2 // Defining the h-bridge pins to digital outputs on the arduino
#define LogicR2 3
#define LogicL1 4
#define LogicL2 5
#define trigger 13 // defining the sensor's trigger and echo pin
#define echo 12
#define LogicX1 7
#define LogicX2 8

void setup()
{
Serial.begin(9600); //9600 bits per seconds.A default setting for arduino
pinMode(echo,INPUT); // configuring the echo pin to act as an input 
pinMode(LogicR1,OUTPUT); // configuring all the other defined pins to act as outputs.
pinMode(LogicR2,OUTPUT);
pinMode(LogicL1,OUTPUT);
pinMode(LogicL2,OUTPUT);
pinMode(trigger,OUTPUT);
pinMode(LogicX1,OUTPUT);
pinMode(LogicX2,OUTPUT);
}


void loop()
{
 
long Time;
long distance; // defining the terms distance and time as long integer
  digitalWrite(trigger, LOW);  //sets the trigger pin off
  delayMicroseconds(4); // delays for 4 microseconds
 
  digitalWrite(trigger, HIGH); // http://arduino.cc/en/Reference/DelayMicroseconds
  delayMicroseconds(9);
 
  digitalWrite(trigger, LOW); // This process configures the trigger pin to work as an output. Reference websit above.
 
  Time = pulseIn(echo, HIGH); //pulseIn reads the pulse when the echo pin is high and sets the value as Time. 
 
  distance = (Time/2) / 29.1; // 29.1 is the speed of sound in a kilometer
  if (distance < 6) { 
    STOP();
    Back(3000); // the AUV goes back for 3 seconds before turning right for seconds.
    Turn_Right(2000);
    Go_Forward();
   
}
  else {
    Go_Forward();
  }
  if (distance >= 220 || distance <= 0){ // if the distance is far, the AUV is set to turn left and then go straight.
    Serial.println("The AUV can't detect anything");
   
   Turn_Left(2000);
   Go_Forward();
  
  }
  else {
    Serial.print(distance);
    Serial.println(" cm"); // prints the distance to the object in centimeters.
  }
  delay(400); // delays for 4 milliseconds



}




void Go_Forward()
{
Serial.println("The AUV is going forward!");
digitalWrite(LogicR1,LOW);  // H-bridge configuration for the AUV to go forward
digitalWrite(LogicR2,HIGH);
digitalWrite(LogicL1,LOW);
digitalWrite(LogicL2,HIGH);

}


void STOP() 
{
Serial.println ("STOPPPPP!!!"); // H-bridge configuration for the AUV to go stop

digitalWrite(LogicR1,LOW);
digitalWrite(LogicR2,LOW);
digitalWrite(LogicL1,LOW);
digitalWrite(LogicL2,LOW);

}


void Turn_Right(int Enter_Time)
{
Serial.println ("The AUV turns right"); // H-bridge configuration for the AUV to go right

digitalWrite(LogicR1,LOW);
digitalWrite(LogicR2,HIGH);
digitalWrite(LogicL1,HIGH);
digitalWrite(LogicL2,LOW);

delay(Enter_Time);

digitalWrite(LogicR2,LOW);
digitalWrite(LogicL1,LOW);

}


void Turn_Left(int Enter_Time)
{
Serial.println ("The AUV turns left");
digitalWrite(LogicR1,HIGH); // h-bridge pin configuration for turning left
digitalWrite(LogicR2,LOW);
digitalWrite(LogicL1,LOW);
digitalWrite(LogicL2,HIGH);

delay(Enter_Time); // once the time is entered, the AUV turns left for that many seconds.

digitalWrite(LogicR1,LOW); // Stops the motor after turning left.
digitalWrite(LogicL2,LOW);

}



void Back(int Enter_Time)
{
Serial.println ("The AUV is going back");  // H-bridge configuration for the AUV to go backwards
digitalWrite(LogicR1,HIGH);
digitalWrite(LogicR2,LOW);
digitalWrite(LogicL1,HIGH);
digitalWrite(LogicL2,LOW);

delay(Enter_Time);

digitalWrite(LogicR1,LOW);
digitalWrite(LogicL1,LOW);
}

----------------------------------------------------------------------------------------------

In our recent laboratory session we spent time troubleshooting the circuit due to it not working. We have now realised the 5V output of the Arduino was struggling to power the ultrasound, h-bridge and motors. Therefore we will need to include another battery supply in circuit, a switch will also be added. Below are the new circuit diagrams:






In other news the motors have now been waterproofed, work on the shell/case has begun and we have retrieved the tank to test out motor.





A two page sustainability report has also been created talking about the regulatory information that we would need to follow, the implications of the manufacturing the AUV at a large scale, and the ethical implications of the market and follow-on products.
Additionally we have made a start on the final report, this is as we have decided that if we start now we can continuously add to it and improve it, instead of having to do all the work at the end. So far we have done an abstract and discussed our original research and hope to expand on it over the coming weeks.


Tasks for next meeting:

Collect and test Perspex sheet
Continue work on shell/case
Complete circuit testing
Modify water tank for testing
Start planning bench inspection poster design and content


References:
[1] Arduino and HC-SR04 Example, http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/
[2] Arduino Libraries, http://arduino.cc/en/reference/libraries
[3]Arduino Programming Notebook, http://playground.arduino.cc/uploads/Main/arduino_notebook_v1-1.pdf
[4]Measuring a watertank level, http://www.makechronicles.com/2012/06/09/arduino-project-11-2d3d-pictures-measuring-a-water-tank-level-v2-hc-sr04-ultrasonic-rangefinderarduino-uno1-0/
[5]Obstacle Avoidance System for Unmanned Underwater Vehicle Using Fin System, http://www.ijisme.org/attachments/File/v1i9/I0407081913.pdf

Monday, 9 February 2015

It's business time!

We've now had our first lab session!

We began by checking that we had received all of the correct components that we had ordered before Christmas. At first glance it seemed like we had everything that we asked for, however we soon realised that we had ordered the wrong sized thread for the propellers so the motors couldn't be attached and we had also not received the cell holder for the batteries which we had requested. Another problem quickly arose when we realised the Arduino Uno we had ordered did not come with the USB A/B cable needed to connect it to a computer. Thankfully this was soon remedied thanks to the laboratory technicians who kindly found a cable we could borrow.
Once we finished checking the components we began implementing our designs and then subsequently testing them. Starting with the h-bridges (10 pin L293E) on a logic patchboard, we simulated how the motors would work by receiving a high and low voltage. The motors were then attached and operated as intended. Correctly spinning the motors in a certain direction depending on the input to the h-bridge.



By midday we had tested all of our components aside from the Arduino, we installed the Arduino environment on my surface and uploaded an example program to confirm that it operated correctly. This also allowed us to begin getting to grips with the coding language and environment we would use to implement the logic control and the sonar sensor. The example code can be accessed from inside the Arduino environment website and was used to fade in and out a single LED.



We wanted to confirm that the Arduino would work with the previously mentioned h-bridge so we used a sample code from this website to see how the code effected the motors movement and how/if our components worked together[1].
After lunch we separated our tasks: Drawing the circuit diagram and soldering one of the H-bridges, coding the Sonar component for the Arduino, and began soldering the other H-bridge's 10 pin mounts to some veroboard and the connecting wires. I then tested the soldered component on the logic patchboard to ensure it worked as intended. 


The day ended with the soldering of all 10 pins and its wired connections for one H-bridge finished whilst the other requires the wired connections to be added next week. Ideas on propeller solutions and general water proofing were mooted and some of the programming was done. The circuit diagram will be ready for the next lab session.


Our plans for next week:

1.  Likhitha and Steven will test the sonar and begin the main body of coding.
        2.  Both veroboards will be completed and tested with motors.
3.   Motors will be made waterproof.
4.   Buoyancy and infrastructure of submarine will begin. 


References: 
 [1] Arduino two way motor control, http://www.instructables.com/id/Simple-2-way-motor-control-for-the-arduino/#step3, Feb 2014