Workshop #5 - RObotics 

This is the arduino microcontroller. It is the brains of our project. We will connect things to it and upload code to make it do cool stuff!  You will need to download the Arduino software here: https://www.arduino.cc/en/Main/Software Once you download the software, copy and paste the code below into the Aduino software: 

This is the arduino microcontroller. It is the brains of our project. We will connect things to it and upload code to make it do cool stuff! 

You will need to download the Arduino software here: https://www.arduino.cc/en/Main/Software

Once you download the software, copy and paste the code below into the Aduino software: 

int trigPin = 11; //Trig - green Jumper
int echoPin = 12; //Echo - yellow Jumper
long duration, cm, inches;

void setup() {
Serial.begin (9600);

//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

pinMode(3, OUTPUT);
pinMode(2, OUTPUT);

}

void loop()
{

// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

// convert the time into a distance
cm = (duration/2) / 29.1;
inches = (duration/2) / 74;

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

if (inches > 15 && inches < 35)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}

delay(10);

if (inches < 15)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
}

else
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}

delay(250);

//convert the inches measurement into a frequency,
//the closer the reading the higher the pitch. (0-40 inches)

int pitch = map(inches, 0, 40, 4000, 50);

//play the converted # on the speaker connected to pin 8 for 20 milliseconds

tone(8, pitch, 20);
delay(10);

}

__________________________________________________________________________________

The plastic grid with holes is called the breadboard. We use this to make connections. 

STEP 1: Connect the 5V pin on the arduino to a row on the breadboard. Connect the GND pin to another row. 

This little mechanism is a sonar sensor. It sends out pings, or ultrasonic blips, and listens to how long it takes the sound to return. We use it to sense distances. 

This little mechanism is a sonar sensor. It sends out pings, or ultrasonic blips, and listens to how long it takes the sound to return. We use it to sense distances. 

STEP 2: Plug the Sonar sensor into the breadboard 

STEP 2: Plug the Sonar sensor into the breadboard 

STEP 3: Connect the power row from the sensor to the same row that you connected the 5v to, and the ground to the ground. 

STEP 3: Connect the power row from the sensor to the same row that you connected the 5v to, and the ground to the ground. 

STEP 4: Connect the row called Trigger to pin 11 on the Arduino. Connect the row called Echo to pin 12. 

STEP 4: Connect the row called Trigger to pin 11 on the Arduino. Connect the row called Echo to pin 12. 

Now the sensor is ready to go!  The next piece of hardware is called a piezo speaker. 

Now the sensor is ready to go! 

The next piece of hardware is called a piezo speaker.