Lab 3: Analog Sensor Box
This lab explores analog input and output using variable resistors. You will learn to read sensor values to the serial monitor and utilize pulse width modulation (PWM) and frequency modulation to affect outputs.
Part 1: Variable Input and Output
For part 1 of the lab, I used a potentiometer and a force sensor as two analog inputs, and had LEDs as analog outputs. Now that I'm more familiar with using the serial monitor, it was pretty simple to print out the values of the potentiometer as well as the force sensor.
Schematic for Part 1
![sch.jpg](https://static.wixstatic.com/media/1e7b3a_a5b12d01077448de9a9f9b562c95b735~mv2.jpg/v1/fill/w_339,h_250,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/sch.jpg)
![IMG_1984.HEIC](https://static.wixstatic.com/media/1e7b3a_850832a92b1d4fe7bedb9d34fe7458c1~mv2.png/v1/fill/w_341,h_250,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_1984_HEIC.png)
This circuit was just to test out my potentiometer. I connected to power, ground, and the middle pin to an analog input pin. Then I looked at the serial monitor to see my output values, which ranged from 0 to 1023.
![IMG_1986.HEIC](https://static.wixstatic.com/media/1e7b3a_72fb3633daf34201888b6375595570fb~mv2.png/v1/fill/w_339,h_254,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_1986_HEIC.png)
![IMG_1987.HEIC](https://static.wixstatic.com/media/1e7b3a_b56ecc9b90ef404e8bcfbef6efbadbcf~mv2.png/v1/fill/w_340,h_255,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_1987_HEIC.png)
Then I added my force sensor and two LEDs to the circuit. I connected the force sensor to an analog pin as well, and then I connected each of the LEDs to PWM pins (9 and 10) as analog outputs.
I made each input turn on both of the LEDs, but if I wanted to turn on one LED for each different input, then it would be a simple change to the code and delete one of the analogWrite functions under each sensor. I found this part to be fairly straightforward and very useful for the third part of the lab.
Code for Part 1
Part 2: Tone Output
The aim of part 2 of the lab was to utilize two photoresistors and a speaker within a circuit. I tested my speaker out first using the photoresistors, then I decided to create an array of frequencies that would end up playing one of two songs, depending on which photoresistor I covered up.
![schm.jpg](https://static.wixstatic.com/media/1e7b3a_58069dbb2e6e4c5ca07211144958437d~mv2.jpg/v1/fill/w_333,h_250,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/schm.jpg)
Schematic for Part 2
![IMG_1993.HEIC](https://static.wixstatic.com/media/1e7b3a_c44f9acb13cf4a099a9f7fa9e977b196~mv2.png/v1/fill/w_333,h_250,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_1993_HEIC.png)
![IMG_1995.HEIC](https://static.wixstatic.com/media/1e7b3a_935dd53c1b1942d184a3858c5b468165~mv2.png/v1/fill/w_333,h_250,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_1995_HEIC.png)
I connected both of my photoresistors from power, then I had both of their other legs along the same rows so that I could connect both of them to one analog pin on the microcontroller. This creates a voltage divider circuit. Then I connected the speaker from the breadboard to a PWM pin on the microcontroller, and had the other end connect to a resistor to the ground. Reading the values on the serial monitor was a little more tricky, but once I got the circuit correct, it was easy to see that the values on the serial monitor would change if either photoresistor is affected.
Each photoresistor gives off a different range of values when covered, so I programmed two songs, one for each resistor. When the first photoresistor is covered, then the beginning of Old McDonald Had a Farm plays, then when the second one is covered, the beginning of Fur Elise plays.
Code for Part 2
Part 3: Laser Cut Sensor Box
For part three, my partner and I decided to make a conceptual microwave. The concept is generally a microwave, although it doesn't heat anything up. We decided that it would be best to choose which analog inputs and which outputs we would want first. So we chose a potentiometer and a force sensor as our inputs, and chose NeoPixels, a alphanumeric display, and a speaker as our outputs. Then we decided to make our box using an online box maker, then go into Illustrator and add holes for some of our inputs and outputs.
![IMG_2012.jpg](https://static.wixstatic.com/media/1e7b3a_8cc1681ed45e46a0886c103079b1b9cc~mv2.jpg/v1/fill/w_339,h_254,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_2012.jpg)
Schematic for Part 3
![lasercut1.heic](https://static.wixstatic.com/media/1e7b3a_387fd7f0cf6d4219b14b40156455b67c~mv2.png/v1/fill/w_339,h_254,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/lasercut1_heic.png)
![lasercut2.jpg](https://static.wixstatic.com/media/1e7b3a_5343daf827be4787a7c0f279601cae2c~mv2.jpg/v1/fill/w_340,h_255,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/lasercut2.jpg)
Laser cutting our box out (the laser didn't go through the first time and the wood moved a little, so our cuts were off by a little). Our measurements were pretty accurate and we didn't have any issues fitting any of our inputs or output.
![IMG_2002.HEIC](https://static.wixstatic.com/media/1e7b3a_32b0a965d1e342e6a0bf0a4aea1df82b~mv2.png/v1/fill/w_339,h_254,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/IMG_2002_HEIC.png)
This is the acrylic being cut. Again, this took a couple of passes to get cut through, but the acrylic wasn't moved this time, so the cut was very clean in the end. We ended up cutting out a simple rectangle to place behind the main window for the microwave.
This video shows how the potentiometer works, and how it changes the alphanumeric display from 1, 2, and 3 dashes, where each number of dashes was coded to a certain number of values within the potentiometer.
This shows the general functionality of our microwave. You change the 'time' or the number of dashes, the press the force sensor, then the speaker and lights will turn on corresponding to the number of dashes.
This is the rough final copy of our microwave. Everything works the way we want it to at this point, just not everything visually is complete at this point. We still need to glue some more of the panels and get the acrylic put in.
![inside2.jpg](https://static.wixstatic.com/media/1e7b3a_77101a3ff32744bea208904269c0bd22~mv2.jpg/v1/fill/w_343,h_257,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/inside2.jpg)
![inside3.jpg](https://static.wixstatic.com/media/1e7b3a_d8d8a942b50c4ba3ae04d26eaaecc9a1~mv2.jpg/v1/fill/w_343,h_257,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/inside3.jpg)
![inside1.jpg](https://static.wixstatic.com/media/1e7b3a_11f329de853045a69676ae1d1e7368c9~mv2.jpg/v1/fill/w_341,h_256,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/inside1.jpg)
This shows the inside of our complete box. The acrylic is finally put in and is just hot glued to the inside of the box. The top left is the breadboard holding the display. A breadboard was easiest to use because there were a ton of pins to wire with it, which ultimately saved us a ton of time. Then we have a second breadboard where every other component is hooked up. Then we finally have the Arduino, which has two inputs and three outputs. On the back panel, we made a hole so that our power cord could have a place to stick through. I was worried that the acrylic would be too thick to see the NeoPixels through, but it ended up looking really good in the end.
This is our final box. We were able to execute pretty much everything that we wanted to, and the outcome is exactly, if not better, than what we were expecting. You can see the light from the NeoPixels really well, and I think the speaker sounds pretty good too. The speaker could maybe be a little louder, so holes for the sound to come out of might be something to consider for the next time.
Code for Part 3
![pot1.jpg](https://static.wixstatic.com/media/1e7b3a_a60771c3bd1a4e2ca7f993e0be7b3d2e~mv2.jpg/v1/fill/w_339,h_254,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/pot1.jpg)
![pot2.jpg](https://static.wixstatic.com/media/1e7b3a_3a7933da59d24b7fb23d0a2201776346~mv2.jpg/v1/fill/w_339,h_254,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/pot2.jpg)
This is the potentiometer soldered to a breakout board. This made it easier to place it where we wanted to inside the box. ****We had the NeoPixels done already, and the speaker and alphanumeric display were placed on a breadboard (see next video).