For my Arduino project with multiple inputs and outputs, I used the three tools we learned: a potentiometer, momentary switch, and a light sensor. I set each one to light up a different LED. For simplicity’s sake, I used red, green, and blue LEDs. The schematic looked as so:
I used a mix of analog and digital commands to account for the fact that the light sensor and potentiometer allow for it, while the digital command was saved for the switch. To avoid over-cluttering on the breadboard, I used short cables to connect the + and – columns on each side of the breadboard and give me more options for cable management. Even with all that, however, the full setup ended up looking like a mess:
As the schematic shows, the button controls the blue light; the light sensor controls the green light; and the potentiometer controls the red light.
I didn’t set it all up at once, however. I started with the switch, then the light sensor, and then the potentiometer. I was having trouble with the program not reading the different names I gave to integers. Reading tutorials, however, I figured out that the problem was in the positioning. Putting the integers in the setup didn’t allow for the loop to read it, but putting it before worked.
Later, considering the fact that the light sensor and the potentiometer send an input from 0-1023 and the LEDs take values of 0-255, I tried using a map command on both the constant integer assigned to the sensor and the variable assigned to the sensor’s reading, but neither of them worked. So I wrote the Write command with the value and divided it by 4 to make up for the difference.
I couldn’t figure out a way to embed the code, but you can access it by clicking here.