We continued to experiment with Arduino and 1Sheeld. This time I tried to the orientation shield but it didn't work,. So I experimented with the microphone shield which picks up sound from my mobile phone's microphone and then turn the LED on. I was struggling with other complicate set up for the 1Sheeld experiment, partly because the tutorial doesn't provide a schematic and I am not experienced enough to come up with my own.
Tutorial We continued to experiment with Arduino and 1Sheeld. This time I tried to the orientation shield but it didn't work,. So I experimented with the microphone shield which picks up sound from my mobile phone's microphone and then turn the LED on. I was struggling with other complicate set up for the 1Sheeld experiment, partly because the tutorial doesn't provide a schematic and I am not experienced enough to come up with my own. Anyway, today the Halloween Arduino project was due. Here's my video:
0 Comments
I directly uploaded the code through the sketch on the website. Select "Arduino Uno" in the left bar below the sketch, and then select the port and upload the code (using bluetooth may drain your phone battery really fast). Go to the camera shield in the app, and now when you push the button, the camera on your phone should snap a photo! (I don't know why mine and my classmates' phone camera continuously snapped photos even though we only pressed the button once. It worked well for Mr. Robert's phone though). The quality of the photos are not that good and every time the camera snaps the flash used (I don't know why flash is turned on; perhaps it is automatic?). Below are some random photos I took using this experiment.
The Graph is used to show how to send a byte of data from Arduino to a personal computer and graph the result. The graph is displayed through the program Processing, while the actual set up uses the program Arduino. Although my set up didn't work, I got a chance to try and play around with my classmate's set up. Turning the potentiometer (POT) left and right changes the graph's appearance (I think it's called the frequency?). My classmate played with it until the POT broke and turned the graph into weird alignments. I didn't take a photo or a video for this experiment, but on the right is a photo (from the tutorial website) of how the graph should look like. In the tutorial, the codes for Processing and Arduino are combined together, however, I separated them below so that it'll be easier to use. Processing Code: // Graphing sketch // This program takes ASCII-encoded strings // from the serial port at 9600 baud and graphs them. It expects values in the // range 0 to 1023, followed by a newline, or newline and carriage return // Created 20 Apr 2005 // Updated 24 Nov 2015 // by Tom Igoe // This example code is in the public domain. import processing.serial.*; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float inByte = 0; void setup () { // set the window size: size(400, 300); // List all the available serial ports // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { // draw the line: stroke(127, 34, 255); line(xPos, height, xPos, height - inByte); // at the edge of the screen, go back to the beginning: if (xPos >= width) { xPos = 0; background(0); } else { // increment the horizontal position: xPos++; } } void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: inByte = float(inString); println(inByte); inByte = map(inByte, 0, 1023, 0, height); } } /* Max/MSP v5 patch for this example ----------begin_max5_patcher---------- 1591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6 Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz 1IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1 nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv HE0Ft7AvIvvgvIwO23jBdUkYOuSvIFSiNcjFhiSsUB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4B5xe9EymDvebK0eMfW6+NIsNlE2m eqRyJ0utRq13+RjmqYKN1e.4d61jjdsauXe3.2p6jgi9hsNIv97CoyJ01xzl c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a 53L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES 1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd. HJ5hhnng3h9HPj4lud02.1bxGw. -----------end_max5_patcher----------- */ Arduino Code:
/* Graph A simple example of communication from the Arduino board to the computer: the value of analog input 0 is sent out the serial port. We call this "serial" communication because the connection appears to both the Arduino and the computer as a serial port, even though it may actually use a USB cable. Bytes are sent one after another (serially) from the Arduino to the computer. You can use the Arduino serial monitor to view the sent data, or it can be read by Processing, PD, Max/MSP, or any other program capable of reading data from a serial port. The Processing code below graphs the data received so you can see the value of the analog input changing over time. The circuit: Any analog input sensor is attached to analog in pin 0. created 2006 by David A. Mellis modified 9 Apr 2012 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Graph */ void setup() { // initialize the serial communication: Serial.begin(9600); } void loop() { // send the value of analog input 0: Serial.println(analogRead(A0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(2); } Tutorial Although it is a simple set up using only one LED, a few jumper wires, a resistor, and an Arduino board, I couldn't get mine to work because my laptop is a MAC, not a PC (My classmate's laptops were all PC so their set up went well). For this one and the next, you'll need to download the program "Processing." In the original website, the given codes for Arduino and Processing are not separated. I've separated them below for easier use. After uploading the codes to both programs, you can use your laptop cursor to control the LED by dragging it left and right on the gradient scale on Processing in order to dim the LED. Processing Code: // Dimmer - sends bytes over a serial port // by David A. Mellis //This example code is in the public domain. import processing.serial.*; Serial port; void setup() { size(256, 150); println("Available serial ports:"); // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. port = new Serial(this, Serial.list()[0], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); } void draw() { // draw a gradient from black to white for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } // write the current X-position of the mouse to the serial port as // a single byte port.write(mouseX); } /* Max/MSP v5 patch for this example ----------begin_max5_patcher---------- 1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2 uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA 4r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6 WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9 FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7 3WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ +wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8 ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS xqZqbd3ZLdera1iPqYxOm++v7SUSz -----------end_max5_patcher----------- */ Arduino Code:
/* Dimmer Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED. The circuit: LED attached from digital pin 9 to ground. Serial connection to Processing, Max/MSP, or another serial application created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Dimmer */ const int ledPin = 9; // the pin that the LED is attached to void setup() { // initialize the serial communication: Serial.begin(9600); // initialize the ledPin as an output: pinMode(ledPin, OUTPUT); } void loop() { byte brightness; // check if data has been sent from the computer: if (Serial.available()) { // read the most recent byte (which will be from 0 to 255): brightness = Serial.read(); // set the brightness of the LED: analogWrite(ledPin, brightness); } } The ASCII Table demonstrates Arduino's advanced serial output functions but generating on the serial monitor. This one is very simple. All you need was the Arduino board, then connect it to your laptop to upload the code. Here is the Tutorial.
IR Distance Sensor
IR Distance sensor code: // Declare the used sensor pin <br>int sensorPin = A0; int LED = 13; // Declare the connected LED void setup(){ // Start the Serial connection Serial.begin(9600); } void loop(){ // Read the analog value of the sensor int val = analogRead(A0); // Print the value over Serial Serial.println(val); // Write the value to the LED using PWM analogWrite(LED, val); // Wait a little for the data to print delay(100); } After you've uploaded the code, open up either the serial monitor or the serial plotter to see if you've completed the circuit. I played around with the distance, and also tried using other sizes LED. I have also tried putting two tiny LED together. The only difficult thing is to figure out how I will adapt the set up to my Halloween project. And what exactly will I make? To answer that question, I tried duplicating a simple Halloween project. Halloween Spooky SkullFollowing this tutorial, we'll be using the Fade code. However, it didn't give me the result I wanted (I doesn't 'fade'-- the result was more like the one from Blink code. ). Materials: 1. Arduino board 2. RGB LED So I tried to follow this tutorial instead of the fade one -- in which I'm not even going to post the link for the fade one because it doesn't work and there's no point to sharing the link if we won't make any good use out of it. However, I'll post the code to the fade one that I've tried. I didn't really understand how the fading work with that code. Even though I modified the numbers, it seemed like the LED turn on duration is just shorter. I tried everything but there was no 'fade effect.' Code: int ledPin = 13; void setup() { } void loop() { for(int fadeValue = 0 ; fadeValue <= 10; fadeValue +=10) { analogWrite(ledPin, fadeValue); delay(60); } for(int fadeValue = 255 ; fadeValue >= 10; fadeValue -=10) { analogWrite(ledPin, fadeValue); delay(200); } } The tutorial hyperlinked above have a schematic, but I didn't follow the schematic. I modified the code a little. You'll also need two paper clips and an A4 paper, and a pair of scissors to cut out the eyes on the paper. Put the RGB LED in the following pins: Gnd, 13, 12, 11. Then just plugged in the USB cable to your laptop and upload the code below. Put the crafted paper spooky skull on top of the RGB, run the code, and voila!
The fade effect works! But I have one problem-- the sequence didn't include red light when it should. I tried modifying things and changing the code, but I couldn't find out what was wrong. I am however, satisfied with the result and the modification I've made. Halloween Spooky Skull Code: // RGB LED Light Up and Cycle Colors // From Interactive Art Session at 757 Makerspace on October 17, 2015 // Design by Akin Yildiz and Beau Turner // Global Variables Go Here const int redPin = 13; const int greenPin = 12; const int bluePin = 11; // The setup section runs one time at the start of the program void setup() { setColorRgb(0,0,0); // Set the the LED to off } //The loop section repeats over and over void loop() { unsigned int rgbColor[3]; rgbColor[0] = 255; // Start Red rgbColor[1] = 0; rgbColor[2] = 0; // Cycle colors + & - for (int decColor = 0; decColor < 3; decColor += 1) { int incColor = decColor == 2 ? 0 : decColor + 1; // Cross-fade colors for(int i = 0; i < 255; i += 1) { rgbColor[decColor] -= 1; rgbColor[incColor] += 1; setColorRgb(rgbColor[0], rgbColor[1], rgbColor[2]); delay(5); } } } void setColorRgb(unsigned int red, unsigned int green, unsigned int blue) { analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); } |
Mimi K. Mimi created this blog as a portfolio and to keep track and share her artwork from Graphic Design2, Drawing2, and her class work from Intro to Computer Programming, and Philosophy classes. Archives
May 2017
Categories
All
|