Class 17 – Code

float x =100;
float y = 350;
float speedX = 5;
float speedY = 3;

void setup() {
  size(602, 505);
  background(255);
  //for (int i=0; i<20; i=i+1) {
  //   }
}
void draw() {

  if (mousePressed) {
    float red = random(255);
    float green = random(255);
    float blue = random(255);
    face(random(width), random(height), random(20, 200), color(red, green, blue));
  }
  if (keyPressed) {
    background(255);
  }

  //face(348, 52, 150, color(255, 255, 0));
  //face(87, 183, 40, color(255, 0, 255));
  
  // move the face
  //x = x + speedX;
  //y = y + speedY;

  //// check the edges
  //if (x > width || x< 0) {
  //  speedX = -speedX;
  //}
  //if (y > height || y< 0) {
  //  speedY = -speedY;
  //}
}
void face(float u, float v, float size, color c) {
  // display ball
  noStroke();
  fill(c);
  ellipse(u, v, size, size);
  fill(255);
  ellipse(u-size*0.3, v-size*0.1, 0.05*size, 0.05*size);
  ellipse(u+size*0.3, v-size*0.1, 0.05*size, 0.05*size);
  arc(u, v, size*0.6, size*0.6, 0, PI);
}

test post with code

I can’t embed github code 🙁

int size = 0;
int increment = 3;
void setup() {
size(400, 400);
}
void draw() {
background(255);
noFill();
strokeWeight(20);
ellipse(width/2,height/2, size, size);
size = size + increment;
if ( size > 300){
increment = -increment;
}if((size<150) && (increment<0)){
increment = -increment;
}
}

IxLab Test Post

Lab Date: Feb 17, 2017
Instructor: Marcele
Lab Partner:
 Tyler

Aim of Today’s Lab: Complete 4 sets of circuits using the DFRobot Beginner Kit for Arduino.

Exercise 1: Traffic Lights

Materials used: 220 ohm resistor * 5, 10k ohm resistor, green LED * 2, red LED * 2, yellow LED, switch, wires, breadboard, DFRduino

I started off this lab by collecting all the materials that I needed to make the traffic light. Everything I needed was in my DFRobot Beginner Kit for Arduino. I received the printed out copies of the 4 sets of circuits we were going to make for the lab today. It looked pretty straightforward, because the circuit diagrams showed exactly how all the components were connected on the breadboard.



When I was done with connecting all the wires like how it was on the circuit diagram, it looked a lot messier than I had imagined it would be. I thought I was ready with my circuit, so I copy-pasted the code my professor provided me with on the Arduino IDE and uploaded the code to my DFRduino.

But it didn’t seem like it was working as it was supposed to! No matter how many times I pressed the switch, nothing happened. I asked professor Dan, if he could take a look at it, and eh told me that I had used a 220 resistor instead of a 10k resistor for the switch! But even after I did that, nothing changed. I was pretty sure that I had correctly connected everything, just like the printed out diagram, but just to make sure, I started to double-check everything carefully. That’s when I found out that I had connected my LEDs to the wrong digital pins! This is when I realized that connecting the components to the correct digital pins is very important, because the Arduino code specifies what digital signals to send out to specific pins.

After I rewired my circuit by paying attention to which LED is connected to each of the digital pins, I succeeded in creating a traffic light!

Exercise 2: Temperature Alarm

Materials used: LM35 Temperature Sensor, Buzzer, wires, breadboard, DFRduino

Just by looking at the diagram, I could see that this circuit was a lot simpler than the traffic light circuit. One important thing Fellow Luis told me to keep in mind was the orientation of the LM35 temperature sensor. He told me that I needed to use the flat side of the sensor as the front side, and connect the wires in front of the sensor.

Fellow Luis told me that had I plugged in the temperature sensor in the wrong direction, it would have become very, very hot. I touched the sensor really carefully and thankfully found the sensor not hot at all. Since I couldn’t see anything that could be wrong, I uploaded the Arduino code for the temperature alarm to my DFRduino.

And it works! I was very surprised at how loud the buzzer was. Also, I noticed that it takes a little while for the temperature sensor to cool down and for the alarm to stop ringing.

Exercise 3: Ambient Light Controlled LED

Materials used: 220 ohm resistor, 10k ohm resistor, ambient light sensor, red LED, wires, breadboard, DFRduino



I gained some confidence after having completed the temperature alarm exercise in one go. So I completed the circuit for the ambient light pretty quickly.

I felt like the traffic light exercise that I completed  first was the hardest one out of the 4 circuits we were creating for the lab today. Again, I found the Arduino code for the ambient light exercise and uploaded to my DFRduino.

But when I uploaded the code, I was confused as to what I was supposed to do to the light sensor to turn off the LED. I tried covering the light sensor, but nothing happened, but then Fellow Luis told me that I was supposed to shine light onto the sensor. So I was using the flashlight on my phone to shine light onto the light sensor, but I noticed that it was not very reactive. It took a very long time for the light sensor to turn off the LED. So I asked professor Marcela, if this was what was supposed to happen, but she told me that I must have done something wrong in my circuit and helped me review my connections on the breadboard.

Professor Marcela asked me what resistor I was using for my light sensor, and I said I thought I was using the 220 ohm resistor. She told me that’s what my problem was! I was supposed to use the 10k ohm resistor, but I was using the 220 ohm resistor. The circuit diagram didn’t have a very clear distinction between a 220 resistor and a 10k resistor, so I didn’t know that they were different! I also realized that the resistors themselves look very very much alike, with exception of the color of some of the stripes on them. Professor told me that consequently I was giving the sensor more voltage than I was supposed to and that this is a way that I was shortening the life of the sensor.

After I replaced the resistor for the light sensor from the 220 ohm one to the 10k one, I saw that the sensor was a lot more reactive to my flashlight!

Exercise 4: RGB Light

Materials used: 220 ohm resistor * 3, RGB LED, potentiometer * 3, wires, breadboard, DFRduino

This exercise looked just as complicated as the traffic lights exercise I did first. Each of the potentiometer had 3 legs, and the RGB LED had 4 legs instead of 2, like a standard LED that I was using for the previous exercises.

By carefully following the diagram, I finished connecting my circuit. One thing that was different from the other previous exercises was that instead of connecting the potentiometers to the digital pins, I connected the middle legs of them to analog pins. Fellow Luis explained to me that it was because potentiometers were sending analog signals to the DFRduino, as opposed to the switch, which had a digital output signal (0 for off, 1 for on). As soon as the Arduino code was uploaded, the RGB LED lit up!

We were able to control the red value of the color using the first potentiometer, the green value using the second one and the blue value using the third one. I filmed my partner Tyler testing the circuit!

Conclusion:
I learned how to follow the diagram to create different circuits.
It is very crucial to pay attention and double check which resistor I should be using. Two of my three mistakes during this lab were caused by the fact that I was using the wrong resistor. For the LEDs I need to use the 220 ohm resistor and for the switch and the light sensor, I need to use the 10k resistor.

The third mistake was caused because I didn’t pay close attention to the circuit diagram. It is important to pay attention to whether the components are connected to the correct digital / analog pins! It’s because the Arduino code tells specific pins what to do, so if you want your circuit to behave how your Arduino code wants it do, you NEED to connect them to the correct pins!
The circuits we created at this week’s lab was a lot more dynamic than those we created last week, because we could tell the actuators such as LEDs and buzzers to react in sequence (as with the traffic light exercise) and to more complex digital / analog inputs. This was because we could load code to the DFRduinos, and I can’t wait to learn to create Arduino code myself!

Things learned / to share:
1) It helps if you use different colors for each of different types of connections. For example, using black wires for connections from a component to ground (-), red wires for connections to power (+), green cables for connections to digital pin, and white wires for connections to analog pins.

2) Learning how to use the multimeter is important because you can also check how much voltage is going through at a specific point in the circuit as well as to see if the circuit is complete or not. It is a very important tool when trying to figure out what is wrong with the circuit.

3) It’s really important to pay attention to whether you are using the correct resistor. Using a wrong resistor can lead to shortening of an electrical component. Professor Marcela also told me that if I didn’t use a resistor with an LED, I would have burned it out.

4) When you are having problems and can’t figure it out yourself, there are professors and fellows around for help!