So we had to make a love machine or something similar. I decided to take the traditional path and work on a love-o-meter using a temperature sensor. The sensor, connected to an analog input, gave me numbers that I couldn’t read, so I used arbitrary numbers after playing around and exposing it to several temperatures. Depending on the values received a different number of LEDs would turn on. The hotter the more LEDs turned on.
Here’s how it looked:
Afterwards I revisited the code and looked at this example from the Arduino.cc tutorials
const int sensorPin = A0; const float baselineTemp = 20.0; void setup() { Serial.begin(9600); for (int pinNumber = 2; pinNumber < 5; pinNumber++) { pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, LOW); } } void loop() { int sensorVal = analogRead(sensorPin); Serial.print("sensor Value: "); Serial.print(sensorVal); float voltage = (sensorVal / 1024.0) * 5.0; Serial.print(", Volts: "); Serial.print(voltage); Serial.print(", degrees C: "); float temperature = (voltage - .5) * 100; Serial.println(temperature); if (temperature < baselineTemp + 2) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); } else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) { digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); else if (temperature >= baselineTemp + 6) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); } delay(1); }
I downloaded, it made sense and worked. No puppies cried, but only one light went on.