For this assignment, I had to combine a switch that doesn’t require the use of hands as well as produce multiple inputs and/or outputs. The main challenge for me was actually settling on a concept for the project. I went over several iterations of the project before deciding on building a scale-like structure that acts as an indicator for the water level. The circuit included a tilt center, which acts as a switch or trigger for the code to run. The code then alternates between blinking red and blue lights, depending on which side is tilted. The first iteration of the model included a simple wooden structure with the breadboard attached to one side. There was a certain flaw in the balance of the structure, however, as the side with the breadboard kept leaning to the side. The only solution at the time was to place random objects on the opposite end of the wooden panel, and that didn’t seems like a very efficient solution.
The final iteration of the project included a plastic cup attached to the side opposing the breadboard with hot glue. Pouring water into that cup would allow the wooden piece to lean to the other side, so the effect of the tilt sensor can be observed in its full glory.
int tilt = 2; int redled = 6; int blueled = 7; void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // make the pushbutton's pin an input: pinMode(tilt, INPUT); pinMode(redled,OUTPUT); pinMode(blueled,OUTPUT); } // the loop routine runs over and over again forever: void loop() { // read the input pin: int buttonState = digitalRead(tilt); if (buttonState){ digitalWrite(redled,HIGH); digitalWrite(blueled,LOW); } else { digitalWrite(redled,LOW); digitalWrite(blueled,HIGH); } if(buttonState){ digitalWrite(redled,HIGH); delay(500); digitalWrite(redled, LOW); delay(500); } else { digitalWrite(blueled,HIGH); delay(500); digitalWrite(blueled, LOW); delay(500); } // print out the state of the button: Serial.println(buttonState); delay(1); // delay in between reads for stability }