Digital Input and Output
In video 1, the pushbuttons are the digital inputs, and the LED lights are the digital outputs. So, in Arduino IDE, they should be defined clearly in response to the pin number the wire connects to. In video 2, I made a switch with two wires and some conducting tapes. In Figure 1, I changed one of the outputs to a 4 ohms speaker. For the code, I used tone() and delay() to make the speaker work.
Video 1: Arduino connected to pushbutton and two LEDs
Video 2: Arduino connected to switch that I made with two wires and two LEDs
Figure 1: Arduino connected to switch that one speaker and LED
Combination Lock
I made a combination lock circuit (see the video and code below). When I press button 1 and button 2, green LED lights up. When I press button 2 and button 4, red LED lights up. Other sequence won't work. The problem I encountered was that LED lights keep flashing in low light when nothing is pressed. I haven't figured out why that happens.
Analog In with an Arduino
Connect the potentiometer to analog in pin 0 of the module and its outer connections to voltage and ground (see Video 2). When I run the analog code according to the website, the LED dimmed up and down as I turn the pot, and the brightness showed up.
Video 2: a potentiometer connected to analog in o of an Arduino and LED connected to pin 9
Then, I replaced the LED with a force-sensing resistor. As I put more and more pressure on the sensor, the voltage went up. Because I set the voltage for the Arduino for 3.3V, the voltage for force-sensing resister didn't go above 3.3V.
Finding Sensor Range
Using the same setup with the force-sensing resistor, I can read the serial analog, which means the microcontroller is doing the analog to digital conversion. It's converting the changing voltage to a digital number (see Video 3).
Video 3
On serial monitor, when I add "float voltage = sensorReading * (5.0/1024.0); Serial.print(voltage);", it will print voltage value as well. As I was trying to find out the range by using map(), Arduino stopped responding (see Figure 2). I'm not sure what caused it. I'll keep troubleshooting it. In the mean time, this is the code for finding the range (Figure 3).
Figure 2
Figure 3
Comments