Get information from at least one analog sensor and at least one digital sensor (switch), and use this information to control at least two LEDs, one in a digital fashion and the other in an analog fashion, in some creative way. Include a hand-drawn schematic in your documentation.
Hand-drawn schematic:
I decided to test my design and code in Tinkercad before implementing it into the actual Arduino board to ensure there is no issues with the connectivity or code to help with the debugging. I am glad that I did that because it seems that I made error and when running the simulation is short circulated and showed an image or animation of an explosion, when clicking the push button.
How this code is made:
I added constants for the pins, which represent fixed connections between the Arduino and the components. I also defined lightLimit and darkLimit to set the range where the LDR reading is mapped into LED brightness. In the loop, the LDR value is read and converted into a brightness level using map(), then constrained to stay within 0–255. This makes the LED respond smoothly to changes in light. When the button is pressed, a random jitter is added to the brightness to create a fluctuating effect. Otherwise, the LED follows the normal smooth brightness based on the sensor. The serial monitor is used to track the sensor values and output for debugging.
The part I am most proud of :
// jitter Button
if(buttonPressed){
// Multiply the jitter
// We pick a random number between negative base and positive base
// to create extreme fluctuations around the current brightness level.
int jitterAmount = random(-baseBrightness, 255);
int finalOutput = constrain(baseBrightness + jitterAmount, 0, 255);
analogWrite(ledPin, finalOutput);
// Very fast delay to make the jitter
delay(random(5, 30));
}else{
// Normal smooth operation
analogWrite(ledPin, baseBrightness);
delay(30);
}
Reflection and Future Improvements:
I also tried my project wiring, connections, and code on the Tinkercad before the physical board, because I was worried about burning my board. Overall, I liked my project and I think it has a lot potential and there is a lot I could add to it . I think I might use it for next week’s assignment musical instruments to make like an orchestra with LED lights. I think it will be a really fun experiment.
