Quantcast
Viewing all articles
Browse latest Browse all 18089

Re: Edison + Arduino Expansion + DFRobot I/O Expansion Shield v7: cannot get readings from Digital pins.

Oops, forgot to post the code: Disclaimer - the code is not mine, It's mostly from the examples of the various sensors obtained from manufacturers websites.

 

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <dht11.h>

dht11 DHT;

#define DHT11_PIN 3

#define echoPin 8 // Echo Pin

#define trigPin 7 // Trigger Pin

#define xPin 13

#define bPin 12

#define yPin 11

 

 

LiquidCrystal_I2C lcd(0x27,20,4);

 

 

int maximumRange = 600; // Maximum range needed

int minimumRange = 0; // Minimum range needed

long duration, distance; // Duration used to calculate distance

 

 

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(xPin, INPUT);

pinMode(bPin, INPUT);

pinMode(yPin, INPUT);

    lcd.init();

    lcd.backlight();

    lcd.setCursor(0, 0);

    lcd.print("Hum:(%), Temp:(C)");

}

 

 

void loop() {

/* The following trigPin/echoPin cycle is used to determine the

distance of the nearest object by bouncing soundwaves off of it. */

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

 

 

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

 

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

 

//Calculate the distance (in cm) based on the speed of sound.

distance = duration/58.2;

 

if (distance >= maximumRange || distance <= minimumRange){

//lcd.print("out of range");

}

else {

lcd.print(distance);

}

 

int chk;

  chk = DHT.read(DHT11_PIN);    // READ DATA

  lcd.setCursor(0, 3);

  lcd.print(chk);

  lcd.print(DHT.humidity);

  lcd.println(DHT.temperature);

  delay(1500);

}


Viewing all articles
Browse latest Browse all 18089

Trending Articles