analog input & output

For this assignment I had to get info from at least one analog and one digital sensor using two LEDs. There were different attempts to do this, as well as various outcomes. I experimented with using some methods to connect the LEDs to the sensor as well as the LEDs to the switch button.

A few resources I have found useful:
https://www.youtube.com/watch?v=4fN1aJMH9mM
https://www.youtube.com/watch?v=0p1B74TosTs

The challenge for me was to connect the LEDs to the sensor when I pressed the button and also if I waved over the sensor, it would react on actions. I managed to do it separately for the button and the sensor.

Video:
IMG_5987

Code:


int LDR = 0;
void setup() {
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop() {
LDR = analogRead(A0);
Serial.println(LDR);
if(LDR < 512) { digitalWrite(12, 1); digitalWrite(13, 1); } else { digitalWrite(12, 0); digitalWrite(13, 0); } }

However, I could not connect the sensor and the button because the light sensor stopped working when I connected the button. I tried redoing my circuit completely, but it was not quite working. It seemed that the button and the light sensor worked together when I could turn the LEDs on with a movement over the sensor and turn them off with the button, but as it turned out later, this was a glitch in the program, not the final result.
In reflection of this, next time I would like to work and understand the code better, so that I could fix the issue I had in this task.

Leave a Reply