void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
const int sensorPin = A0;
const float baselineTemp = 19;
float voltage = (sensorVal / 1024.0) * 5.0;
float temperature = (voltage - 0.5) * 100;
delay(1000); // in milliseconds
The digital pins on an Arduino can act as both inputs and outputs.
The Arduino’s digital pins can only read two states: when there is voltage on an input pin, and when there’s not. This kind of input is normally called digital (or binary, for two states). These states are commonly referred to as HIGH and LOW.
// Goes in setup()
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH); // 5V
digitalWrite(2, LOW); // 0V
digitalRead(2); // Needs an argument for which pin to read from
Analog pins can report a value between 0-1023, which maps to a range from 0 to 5 volts.
Make sure you open the serial monitor to see the output: Tools > Serial Monitor
void setup() {
Serial.begin(9600); // open a serial port, 9600 bits/s
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
Serial.print("index=");
Serial.print(index);
Serial.println(); // moves cursor to a new line
}
if (true) {
// if true code here
}
if (true) {
// if true code here
} else {
// if false code here
}
if (true) {
// if true code here
} else if (true) {
// if false code here
} else {
// if false code here
}
for(int pinNumber = 2; pinNumber<5; pinNumber++){
// Loop code goes here
}