Skip to content

11. Input devices

At the begining, we have done the group assignement here. My part is the other signals part.

Hero shot

Temperature

To test the temperature, I took one of my old boards and added connectors:

I then connected a DTH11 to the right pins and implemented this code:

#include <DHT.h>

#define DHTPIN 2      
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println(F("Echec de la lecture du capteur DHT !"));
    return;
  }
  Serial.print(F("Humidity : "));
  Serial.print(humidity);
  Serial.print(F("%\t"));
  Serial.print(F("Temperature : "));
  Serial.print(temperature);
  Serial.println(F("C"));
  delay(2000); 
}

At first I had a problem reading it intermittently.

I first suspected a faulty sensor, but when I replaced it the problem persisted. I rechecked my soldering and it was fine. Changing the wires stopped the problem.

light sensor

I connected the light sensor to my board, adding a pin to A0.

The result wasn’t very accurate, with a lot of unexplained variation. I’ll have to switch to more sophisticated sensors in the future.

The code I used :

const int pinSensorLight = A0;

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

void loop() {
  int valueLight = analogRead(pinSensorLight);
  float luminosity = map(valueLight, 0, 1023, 0, 100);

  Serial.print(F("Luminosity : "));
  Serial.print(luminosity);
  Serial.println(F("%"));

  delay(1000); 
}

4. The files

Here you can find the DHT11 file

Here you can find the light sensor file

Here you can find the KiCad file 1, file 2, file 3