If {something}, then do {something}

I'm making a device that senses temperature below a certain level and then turns a red LED if the temperature is below that level. There is a screenshot of my virtual model on TinkerCad in this post.

If I want to I want to turn on the LED IF the temperature sensor senses temperature below the level. How do I write this in the code? Sorry if this is a simple question :blush: , I am new to electronics.

Thanks a lot!

First of all: your connections are wrong.

What type of temperature sensor do you have? It will probably need a resistor, and maybe also an opamp.It must be connected to an analog input pin (A0 .. A5).

The led must have a series resistor, with a value of 470 .. 1000 ohm, and be connected between a GPIO pin (2 .. 12) and GND.

The code is simple:

if (temp < 18)
  {
    digitalWrite(ledPin, HIGH);
  }
  else 
  {
    digitalWrite(ledPin, LOW);
  }

But I think you should first experiment with some of the example sketches in the IDE, to get some understanding of the programming code for an Arduino.

get the temperature sensor working first

Thanks a lot johnerrington, and I gave you karma!

Also, Erik_Baas, when I try to run the code, it says a lot of errors. Look in the attachement. Please help!

Of course. It was not a complete sketch. Again:

Erik_Baas:
But I think you should first experiment with some of the example sketches in the IDE, to get some understanding of the programming code for an Arduino.

You will not be able to finish this project if you don't know how to program an Arduino. We can help you if there is a problem, but you must do (most of) it yourself.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.