## Heat meter – Arduino

This is another basic exercise form the arduino starter kit, in this case I am using a temperature sensor to measure room temperature, as the temperature rises (by touching the sensor), lights are turned on.

This is the code:

```/*We set two constants, one with the name of the analog pin and
another for the ambient temperature
*/
const int sensorPin =A0;
/* to adjust the right temperature, you should check the initial
value that the micropocessor sends back in the variable volts
*/
const float tempAmbient = 22.0;

void setup() {
Serial.begin(9600);
//with this loop, we set ports 2 to 4 to work as output and make shure the lights are off
for(int pinNumber = 2; pinNumber<5; pinNumber ++){
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber,LOW);
}
}

void loop() {
/*with this loop we constantly check and print the values returned from the temperature
sensor, the volts (with a little math) on that pin and the temperature.
*/
Serial.print("Value of the sensor: ");
Serial.print(sensorVal);
float volts = (sensorVal/1024.0)*5;
Serial.print(", Volts: ");
Serial.print(volts);
Serial.print(", Degrees C: ");
/*the values used for this equation are particular to the sensor provided in the kit,
this is how whe calculate the temperature.
*/
float temperature = (volts- .5)*100;
Serial.println(temperature);
//this conditional structure allows to determine mow many lights need to be turned on
if(temperature < tempAmbient){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if(temperature >= tempAmbient+1 && temperature < tempAmbient+2){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
else if(temperature >= tempAmbient+2 && temperature < tempAmbient+3){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
else if(temperature >= tempAmbient+3){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}
```

This is how it looks on the monitor

This is how the circuit works

## Button and lights – Arduino

Today  started working whit Arduino (again), but this time I have a good excuse to use it so I hope this will be integrated with future work, around march this year I did a couple of tutorials using Arduino, but I did not document them, now I am going to do it as an exercise for my memory and also to tidy up mi knowledge on this matter, it is worth to mention that recently I started to study C# and my goal is to be able to connect both VR and Arduino through Unity.

This first example is just a simple circuit that allows me to change the order for the lights to turn on, so I am using a push button to do this, if the button is not pressed (LOW), the lights will be turned on in an specific order, otherwise, if the button is pressed (HIGH) the order will change (this is an exercise form the Arduino starter kit)

This is the code:

```//this is te variable that is going to store the two values for the bush button
int switchState=0;
void setup() {
//we use the pinMode function to set the pins to be either for input or for output
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);

}

void loop() {
//we loop to check if the button is pressed
//if the button is not pressed then the lights get turned on in this sequence
if(switchState == LOW){
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); //wait for a quarter of a second
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); //wait for a quarter of a second
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(250); //wait for a quarter of a second
//if the button is pressed then the lights are turned on in this sequence
} else {

digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(250); //wait for a quarter of a second
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); //wait for a quarter of a second
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); //wait for a quarter of a second
}
}

```

This is the circuit being tested