Tag Archives: code

Sound and pitch change with Arduino

Warning: this is a really really annoying little project. If you want to irritate everyone around you, then this project is for you.

My initial idea was to connect more than one pressure sensor to it and make it like a miniature piano. But I could only find one pressure sensor so I made do with it. 

Diagram:

Image

 

The code I used for this is really simple. I used the tone() function to code for what would normally be 5 lines of regular code.

int speakerPin = 12;
int pressurePin = 0;
 void setup()
{
}
 void loop()
{
  int reading = analogRead(pressurePin);
  int pitch = 200 + reading / 4;
  tone(speakerPin, pitch);
}
 
 
When you apply pressure to the sensor, the pitch of the note will change. It’s really annoying though so use with caution. 

Arduino: Robotic Wrist using 2 servos and a speaker

I’m currently working on a robotic arm that I hope will have fine motor control abilities.
So far, I’ve got the wrist movements down: I can move vertically and rotate. This is all controlled by an old SONY TV remote.
The vertical movements are controlled by one servo (in code: servoV) and the rotating movements are controlled by another (in code: servo). I’ve got buttons on the remote that do both macro and micro movements.
The speaker lets me know when I’ve exceeded arbitrarily selected max and min degree values (well not so arbitrary: I selected them because I noticed that the servos struggle past certain degrees).

Watch the Demo here! (less than 2 mins)

I’ve provided download links to all the materials you’ll need, but if for some reason they don’t work, download the files from my fritzing project profile:
Robotic Wrist with Speaker (at work #2)

To recreate my robotic wrist you’ll want to:

1 – copy and adapt my code in Arduino
2 – build the physical robot body with servos
3 – connect the servos, speaker, breadboard, and arduino following my circuit diagram

Parts used:
2 servos
1 IR receiver
1 Piezo Speaker
1 breadboard
1 Arduino
1 IR remote
1 9V battery
extra black and red wires
a USB cord that plugs into the Arduino
Some foam core, tape, and a large one of these clips 
Image

1: Copy and adapt my code in Arduino:
Code: Arduino (.ino) file    or    Code: Java (.java) document
Labelled (with results values) JPG of SONY Remote Control  ** you don’t really need this 
** if you use the Arduino code, make sure you place it in a folder that has the exact same name as the .ino file. If you don’t know what I mean, when you try to open the .ino file, Arduino will ask you if it’s okay to put it in a folder. Let it do that **

2: Build the Physical robot body
Watch the video here (2:30 mins)

3: Connect the pieces
Circuit diagram: fritzing (.fzz) document    or    Circuit diagram: PNG

Image

** note: If you’re using larger servos (like I am), make sure your power supply is sufficient. You’ll know it’s insufficient if the intro to Beethoven’s 5th Symphony repeatedly plays. This is because when the power supply is insufficient, the Arduino will keep rebooting, so it will repeatedly run through the setup.

Measuring temperature with Arduino

Hi guys!

Here’s a fun little thing you can do with your Arduino. If you don’t have a thermometer but would still like to know the temperature in your room, you can build one using the temperature sensor found in the basic kits for Arduino. 

Image

 

I had to turn the sensor around in this diagram so you could actually see where the wires go. For pin 1 (which when the sensor faces you with the flat side is the left most one, but in this it’s the right most one), you will attach your power line (in this case 5V). Pin 2 goes to an analog source (A1 in my case) and number 3 is your ground pin.

Arduino code:

int tempPin =1; //this is the analog pin you’re connected to

void setup()
{Serial.begin(9600); //serial port connection to the computer

}

void loop()
{

int tempRead = analogRead(tempPin); //voltage reading from sensor
Serial.println(tempRead); //puts out the reading in the serial monitor
int tempC = map(tempRead, 0, 1023, -50, 450); //your values will be from 0 to 1024 which you then convert to your degrees using the map function

//10mv correspond to 1 degreeC
Serial.print(“new temp: “);
Serial.println(tempC);

delay(200);
}