Code Club Electronics 9

So following on from the previous post. I had to look this up to remind myself how to specific a pin.

So my next project, was to try and get the DHT11 temperature and humidity module working. I had a problem with the library for this, so looked at the code, used the section of this that used the LM35 temperature module (which can also be found on the Easy module shield)

float tempC;
int tempPin = 2;
byte temperature = 0;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature

  Serial.print("LM35 - Temperature: "); 
  Serial.print((byte)tempC);
  Serial.println(" Celcius");
  delay(500); // delay 5 seconds
}

So just switched to pin 2 above

int tempPin = 2;

And modified the code to give nicer output. The Arduno IDE allows for both plotting of data on a graph and also just using the serial monitor.

Output looks like this

LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


MastodonPeertubeQoto sign up

Donate using Liberapay