0

members

Easy Arduino Starter Kit: Project 3 LOVE-O-METER

of Arduino in UNO

Arduino Starter Kit: Project 3

Project name: LOVE-O-METER

Discover: analog input, using the serial monitor

Attachments: libraries and sketch

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Jumper cables

3. Resistor 3 pcs (220 Om each)

4. Breadboard half size 

5. LEDs (red) 3 pcs

6. Temperature sensor TMP36 1 pc

7. Arduino IDE ( you can download it from here  )

GENERAL

While switches and buttons are great, there’s a lot more to the physical world than on and off. Even though the Arduino is a digital tool, it’s possible for it to get information from analog sensors to measure things like temperature or light. To do this, you’ll take advantage of the Arduino’s built-in Analog-to-Digital Converter (ADC). Analog in pins A0-A5 can report back a value between 0-1023, which maps to a range from 0 volts to 5 volts. You’ll be using a temperature sensor to measure how warm your skin is. This component outputs a changing voltage depending on the temperature it senses. It has three pins: one that connects to ground, another that connects to power, and a third that outputs a variable voltage to your Arduino. In the sketch for this project, you’ll read the sensor’s output and use it to turn LEDs on and off, indicating how warm you are. There are several different models of temperature sensor. This model, the TMP36, is convenient because it outputs a voltage that changes directly proportional to the temperature in degrees Celsius.

See the specification of TMP36 here.

The Arduino IDE comes with a tool called the serial monitor that enables you to report back results from the microcontroller. Using the serial monitor, you can get information about the status of sensors, and get an idea about what is happening in your circuit and code as it runs.

THE CIRCUIT

In this project, you need to check the temperature of the room before proceeding. You’re checking things manually right now, but this can also be accomplished through calibration. It’s possible to use a button to set the baseline temperature, or to have the Arduino take a sample before starting the loop() and use that as the reference point. Arduino project 6 gets into details about this, or you can look at the Calibration example that comes bundled with the Arduino software:

http://www.arduino.cc/calibration

Wire up your breadboard so you have power and ground. Attach the cathode (short leg) of each of the LEDs you’re using to ground through a 220-ohm resistor. Connect the anodes of the LEDs to pins 2 through 4. These will be the indicators for the project. Place the TMP36 on the breadboard with the rounded part facing away from the Arduino (the order of the pins is important!). Connect the left pin of the flat facing side to power, and the right pin to ground. Connect the center pin to pin A0 on your Arduino. This is analog input pin 0. Create an interface for your sensor for people interact with. 

THE CODE

Constants are similar to variables in that they allow you to uniquely name things in the program, but unlike variables they cannot change. Name the analog input for easy reference, and create another named constant to hold the baseline temperature. For every 2 degrees above this baseline, an LED will turn on. You’ve already seen the int datatype, used here to identify which pin the sensor is on. The temperature is being stored as a float, or floating-point number. This type of number has a decimal point, and is used for numbers that can be expressed as fractions. In the setup you’re going to use a new command, Serial.begin(). This opens up a connection between the Arduino and the computer, so you can see the values from the analog input on your computer screen. The argument 9600 is the speed at which the Arduino will communicate, 9600 bits per second. You will use the Arduino IDE’s serial monitor to view the information you choose to send from your microcontroller. When you open the IDE’s serial monitor verify that the baud rate is 9600. Next up is a for() loop to set some pins as outputs. These are the pins that you atached LEDs to earlier. Instead of giving them unique names and typing out the pinMode() function for each one, you can use a for() loop to go through them all quickly. This is a handy trick if you have a large number of similar things you wish to iterate through in a program. Tell the for() loop to run through pins 2 to 4 sequentially. In the loop(), you’ll use a local variable named sensorVal to store the reading from your sensor. To get the value from the sensor, you call analogRead() that takes one argument: what pin it should take a voltage reading on. The value, which is between 0 and 1023, is a representation of the voltage on the pin. The function Serial.print() sends information from the Arduino to a connected computer. You can see this information in your serial monitor. If you give Serial.print() an argument in quotation marks, it will print out the text you typed. If you give it a variable as an argument, it will print out the value of that variable. With a little math, it’s possible to fgure out what the real voltage on the pin is. The voltage will be a value between 0 and 5 volts, and it will have a fractional part (for example, it might be 2.5 volts), so you’ll need to store it inside a float. Create a variable named voltage to hold this number. Divide sensorVal by 1024.0 and multiply by 5.0. The new number represents the voltage on the pin. Just like with the sensor value, you’ll print this out to the serial monitor. If you examine the sensor’s datasheet, there is information about the range of the output voltage. Datasheets are like manuals for electronic components. They are written by engineers, for other engineers. The datasheet for this sensor explains that every 10 millivolts of change from the sensor is equivalent to a temperature change of 1 degree Celsius. It also indicates that the sensor can read temperatures below 0 degrees. Because of this, you’ll need to create an offset for values below freezing (0 degrees). If you take the voltage, subtract 0.5, and multiply by 100, you get the accurate temperature in degrees Celsius. Store this new number in a floating point variable called temperature. Now that you have the real temperature, print that out to the serial monitor too. Since the temperature variable is the last thing you’re going to be printing out in this loop, you’re goingto use a slightly different command: Serial.println(). This command will create a new line in the serial monitor after it sends the value. This helps make things easier to read in when they are being printed out. With the real temperature, you can set up an if()...else statement to light the LEDs. Using the baseline temperature as a starting point, you’ll turn on one LED on for every 2 degrees of temperature increase above that baseline. You’re going to be looking for a range of values as you move through the temperature scale. The && operator means “and”, in a logical sense. You can check for multiple conditions: “if the temperature is 2 degrees greater than the baseline, and it is less than 4 degrees above the baseline.” If the temperature is between two and four degrees above the baseline, this block of code turns on the LED on pin 3 as well. The Analog-to-Digital Converter can only read so fast, so you should put a small delay at the very end of your loop(). If you read from it too frequently, your values will appear erratic. 

THE START

With the code uploaded to the Arduino, click the serial monitor icon. You should see a stream of values coming out, formatted like this: Sensor: 210, Volts: .75, degrees C: 18. Try to put your fingers around the sensor while it is plugged into the breadboard and see what happens to the values in the serial monitor. Make a note of what the temperature is when the sensor is left in the open air. Close the serial monitor and change the baselineTemp constant in your program to the value you observed the temperature to be. Upload your code again, and try holding the sensor in your fingers. As the temperature rises, you should see the LEDs turn on one by one. Create an interface for several people to test their compatibility with each other. 

THE SUMMARY

You have used analogRead() and the serial monitor to track changes inside your Arduino. It is possible to read a large number of analog sensors and inputs now.

See one of movies on Youtube about it - link here



Other projects of Arduino

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 14-08-2017
Viewed: 914 times