overview

In this lab we were tasked with making two separate breadboard circuits displaying different uses of analog input and output. The challenge of this lab was using analog sensors to take in input from the physical world and map this input to a feasible range for the given output device. The final step was combining both circuits in an "interactive sensor box" which we were tasked to design and create ourselves.

part 1 - variable input and output

Part 1 of this lab centered around getting comfortable with analog (otherwise known as variable) input and output. We had to use two different analog sensors as dimmer switch for standard LEDs. This challenge is different than what we have done before because the output to the LEDs is variable, meaning there are many different states it can show, rather than just on and off.

materials

The materials I used to create this breadboard are:

IMG_7804.HEIC

schematic

The schematic I drew of this circuit before building it is shown below.

IMG_CE35CA8F2AEF-1.jpeg

creating the breadboard

To create my breadboard, I followed my schematic and made sure all of my components were plugged into the right places. When wiring up the photoresistor, I connected one end to power and the other end to a rail which connected to two places: a pin on the Arduino and back to ground. I used jumper cables in some places for making quick adjustments rather than solid core wire. In the final circuit for this project, the interactive sensor box, I used solid core wire in order to create a resilient circuit.

IMG_7809.HEIC

coding the arduino

Coding analog input and output is different than digital because you are dealing with multiple values rather than just 1 and 0. A fully on LED is denoted by the value 255. A fully off LED is at a value of 0. Therefore, to create a dimmer switch with the POT, I divided the position of the slider, which is always between 0 and 1023, by 4 to set a brightness between 0 and 255. This method worked for the POT because the range never changes, but for the photoresistor sensor, I had to the use the map function. First, I tested the sensor and recorded that it was able to pick up a range of 0 to 30. Then I used the map function to translate this range to 0 to 255, which is used to determine the brightness of the LED.

// declaring variables I will use in this code
int potPin = A1;
int photoPin = A0;
int redLED = 2;
int yellowLED = 3;
int val = 0;
int val2 = 0;
int val3 = 0;

void setup() {
  
  //no need to declare analog as input
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  Serial.begin(9600);

}

void loop() {

  //read and store pot value
  val = analogRead(potPin);

  //write the value divided by 4 create a range of 0-255
  analogWrite(redLED, val/4);

  //read and store the photo value
  val2 = analogRead(photoPin);

  //map this value to a usable range for the LED
  val3 = map(val2, 0, 30, 0, 255);
 
  //write this usable value (between 0-255) to the LED
  analogWrite(yellowLED, val3);
 
}

testing the circuit

The final, working circuit is shown below. I can change the brightness of the Red LED by sliding the POT. The brightness of the Yellow LED is dependent on how much light the Photoresistor receives. When I cover this sensor with my finger, the LED dims. When it is exposed to the full light of the room, the LED gets brighter. I experienced a lot of "noise" with the photoresistor in comparison to the POT, so the yellow LED flickers whereas the red one does not.

https://vimeo.com/636702146

part 2 - tone output

In part 2 of this lab, we used analog sensors to control the frequency of a pitch from a speaker. We had to use two photoresistor for this voltage divider circuit instead of a secondary fixed resistor in order to emulate a musical instrument.

materials

The materials I used to create this circuit are as follows: