Ceci est une ancienne révision du document !
Last month, I showed you what I had of my automated chicken coop door. Well, as ever, I managed to fix one problem – and then introduce twice as much complexity. My system has now gone from a simple servo and LDR to a full servo, LDR, humidity sensor and LCD screen. A servo normally goes from zero degrees to 180 degrees and, in the code, we can specify which angle we want the servo to move to. A full servo is (as far as I can gather) somewhere between a motor and a servo. You treat it like a servo in the code, but it’s more like a motor in that it will turn 360 degrees, but you can not specify an angle. This posed quite a problem when I had to run the servo forward to raise the door, then in reverse to lower the door. I eventually solved that problem by a bit of a botch using the open command: myServo.write(openDoor); and using a map command to throw reversed numbers at it: reverse=map(openDoor,0,1023,180,0); myServo.write(reverse); It’s not elegant by any means, but it works.
You know the LCD screen from the laser trip-wire project. Implementing that was pretty much a copy/paste job, but with the added complexity of the humidity sensor. The humidity sensor is a DHT11 model; simply use an include for the dht11 library. If you don’t have it, the relevant files and info are at: http://playground.arduino.cc/main/DHT11Lib. Implementing the humidity and temperature functions were a bit tricky as it uses some pretty complex maths to convert the usual numbers into something we can read as ⁰C. I’m not even going to pretend I know what these functions are doing. I copied and pasted them from other code I found on the DHT11 page, and on some Google searches. The loop() has a chk where we give it the pin that the sensor is on: int chk = DHT11.read(DHT11PIN); Later, we run a switch command to check for the sensor being online (again, not my code). There are several lines for printing the converted values to the screen: Serial.print(“Humidity (%): ”); Serial.println((float)DHT11.humidity, 2); Serial.print(“Temperature (°C): ”); Serial.println((float)DHT11.temperature, 2); I kept this in as it’s a good check to see if the sensor is working prior to adding the LCD. At the end, it’s the same LCD print commands from the laser trip wire, but with the humidity values inserted. lcd.setCursor(0, 1); lcd.print(“Temp. ('C): ”); lcd.print(DHT11.temperature); Now that I have the prototype made, I just need to put the Arduino Nano (with breadboard) in a plastic tub, and run longer wires out to place the LCD and sensor somewhere convenient. My final code for this is at: http://pastebin.com/ES421PHV.