Nicholas’ Portfolio

My name is Nicholas and I’m in 3rd grade. I am 10 years old. I live in San Diego, California. I learned how to make an ultrasonic range finder to find how much distance is between it and an object! I also learned how to make a speaker make sound that came from the computer! Our class learned a lot and I really liked this camp. I wish I could come he next year!  My Arduino range finder code:
#include <Wire.h>
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>

Adafruit_7segment matrix = Adafruit_7segment();

int triggerPin=5;
int echoPin=7;
long duration=0;
float cm=0;

void setup() {
matrix.begin(0x70);
pinMode(triggerPin,OUTPUT);
pinMode(echoPin,INPUT);
}

void loop(){
digitalWrite(triggerPin,LOW);
delayMicroseconds(5);
digitalWrite(triggerPin,HIGH);
delayMicroseconds(5);
digitalWrite(triggerPin,LOW);
delayMicroseconds(5);

duration=pulseIn(echoPin,HIGH);

cm = duration /29.0 /2.0;

matrix.print(cm);
matrix.writeDisplay();
matrix.print(cm);
matrix.writeDisplay();
delay(300);
}

My Smoothing code:

Reads repeatedly from an analog input, calculating a running average
and printing it to the computer. Keeps ten readings in an array and
continually averages them.

The circuit:
* Analog sensor (potentiometer will do) attached to analog input 0

Created 22 April 2007
By David A. Mellis <dam@mellis.org>
modified 9 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/Smoothing

This example code is in the public domain.
*/
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 30;

int readings[numReadings]; // the readings from the analog input

int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0;

int led=2;// the average
int led2=3;
int led3=4;
int led4=5;
int led5=6;
int led6=7;

int inputPin = A0;

void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}

void loop() {
// subtract the last reading:
total= total – readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;

// if we’re at the end of the array…
if (index >= numReadings)
// …wrap around to the beginning:
index = 0;

// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);

if(readings[index]>average){
if(readings[index]> (3*average) ){
digitalWrite(led,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
}
Else{
digitalWrite(led,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led3,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);

}
else{
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6,LOW);
}

delay(15);
}

im2