Outils pour utilisateurs

Outils du site


issue93:arduino

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.

Le mois dernier, je vous ai montré ce que j'ai fait de ma porte automatique de poulailler. Bien ! Comme toujours, quand je m'arrange pour règler un problème, il en surgit deux autres de plus grande complexité. Mon système est passé d'un simple servo et un LDR [photorésistance] à un servo complet, une LDR, un détecteur d'humidité et un écran LCD.

Un servo tourne en général de zéro à 180° et, dans le code, nous pouvons spécifier jusqu'à quel angle nous voulons que le servo bouge. Un servo complet est (pour ce que j'ai pu comprendre) quelque part entre un moteur et u servo. Vous le traitez comme un servo dans le code,mais c'est plutôt comme un moteur car il tourne sur 360° et vous ne pouvez pas spécifier un angle. Ceci me posa un bon problème quand j'ai dû lever la porte, puis à l'inverse pour baisser la porte. J'ai finalement résolu ce problème avec une bidouille en utilisant la commande open :

myServo.write(openDoor);

et la commande map pour lui envoyer les nombres à l'envers :

reverse=map(openDoor,0,1023,180,0);

myServo.write(reverse);

Ce n'est vraiment pas élégant, mais ça marche.

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.

issue93/arduino.1426529834.txt.gz · Dernière modification : 2015/03/16 19:17 de d52fr