So I am trying to figure out how to read sensor data. Like if I want to take temp sensor and if it gets to 80 degrees then a fan will turn on. Or like using a photo cell to do something. Can anyone give me an example of how to do this if possible? Thanks!
P.S does anyone know of a library/interface besides max or processing by which I can make a good looking graphical control interface? Where I can add things like buttons, sliders, info (like what the temp outside is etc)
One of the easiest temperature sensors is the tmp36 .
There is a great tutorial here - Overview | TMP36 Temperature Sensor | Adafruit Learning System -
You need analogRead() to sample it,
convert the reading to milliVolts and then to temperature.
FOr switching on/off a fan you need to use a transistor in between
e.g. - http://medialappi.net/lab/tutorials/controlling-12-v-fan-with-arduino-digital-pin/ -
success!
Here is a customizable fan code
#include <LiquidCrystal.h>
int pin = 0; // analog pin
float tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int i;
const int up =8;
const int down =7;
int high =25;
const int fan =5;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
pinMode(7, INPUT);
pinMode(8, INPUT);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
}
void loop()
{
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}
while(tempc > high) {
analogWrite(fan, 128);
}
tempc = tempc/8.0; // better precision
tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
lcd.setCursor(0, 1);
lcd.print(tempc,DEC);
lcd.print(" Celsius, ");
lcd.setCursor(0, 2);
lcd.print(tempf,DEC);
Serial.print(" fahrenheit -> ");
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
if(digitalRead(up) == HIGH){
lcd.clear();
high= high +1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
if(digitalRead(down) == HIGH){
lcd.clear();
high= high -1;
lcd.print ("High temperature is");
lcd.print (high,DEC);
}
delay (1000);
lcd.clear();
tempc = 0;
}