issue107:arduino
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue107:arduino [2016/04/06 09:05] – d52fr | issue107:arduino [2016/04/08 14:49] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
**WARNING: This month we’re heading into the big league with controlling household voltage devices. It should go without saying, but I’ll say it anyway, you must make sure your 110/240V devices are unplugged before chopping cables, and double-check your wiring before you do put that plug back into the wall outlet.** | **WARNING: This month we’re heading into the big league with controlling household voltage devices. It should go without saying, but I’ll say it anyway, you must make sure your 110/240V devices are unplugged before chopping cables, and double-check your wiring before you do put that plug back into the wall outlet.** | ||
- | ATTENTION : ce mois-ci, nous passons en première division en pilotant des appareils sous tension domestique. Il va sans dire, mais je le dis quand même, que vous devez vous assurer que vos appareils sont débranchés avant de couper des câbles, et vérifier deux fois votre câblage avant de remettre la fiche dans la prise murale. | + | ATTENTION : ce mois-ci, nous passons en première division en pilotant des appareils sous tension domestique. Il va sans dire, mais je le dis quand même, que vous devez vous assurer que vos appareils sont débranchés avant de couper des câbles et vérifier deux fois votre câblage avant de remettre la fiche dans la prise murale. |
**In previous articles, I used an LCD screen which, while it worked, would need about a dozen wires and a potentiometer to control the screen brightness (see photo, top board). This time, I’ve managed to get some much simpler LCD screens that require only four wires (same photo, bottom board). The wires are VCC, GND, SDA and SCL. These should be marked on your Arduino, but on UNO boards, I believe it’s A4 and A5. On my MEGA, it’s 20 and 21 and they’re marked as such. But you need to put both those lines through a 4.7K resistor from 5V. | **In previous articles, I used an LCD screen which, while it worked, would need about a dozen wires and a potentiometer to control the screen brightness (see photo, top board). This time, I’ve managed to get some much simpler LCD screens that require only four wires (same photo, bottom board). The wires are VCC, GND, SDA and SCL. These should be marked on your Arduino, but on UNO boards, I believe it’s A4 and A5. On my MEGA, it’s 20 and 21 and they’re marked as such. But you need to put both those lines through a 4.7K resistor from 5V. | ||
Ligne 9: | Ligne 9: | ||
Before adding LCD code, we need to do a scan of the LCD screen to get its I2C address. Different models have different addresses. So, grab the code from: http:// | Before adding LCD code, we need to do a scan of the LCD screen to get its I2C address. Different models have different addresses. So, grab the code from: http:// | ||
- | Dans les articles précédents, | + | Dans les articles précédents, |
- | Ces nouveaux écrans LCD sont I2C ce qui signifie qu'ils ont une petite carte de pilotage au dos. Cela signifie aussi qu'ils besoin d'une nouvelle bibliothèque (https:// | + | Ces nouveaux écrans LCD sont I2C ce qui signifie qu'ils ont une petite carte de pilotage au dos. Cela signifie aussi qu' |
Avant d' | Avant d' | ||
Ligne 45: | Ligne 45: | ||
#include < | #include < | ||
- | Définissez plusieurs picots (les éléments I2C que vous n' | + | Définissez plusieurs picots (des éléments I2C que vous n' |
#define I2C_ADDR | #define I2C_ADDR | ||
- | < | + | < |
#define BACKLIGHT_PIN | #define BACKLIGHT_PIN | ||
Ligne 61: | Ligne 61: | ||
LiquidCrystal_I2C | LiquidCrystal_I2C | ||
- | Dans mon paramétrage, | + | Dans mon paramétrage, |
**lcd.begin (16, | **lcd.begin (16, | ||
Ligne 89: | Ligne 89: | ||
delay(2000); | delay(2000); | ||
- | La plupart de ces commandes | + | La plupart de ces commandes |
- | Maintenant, j'ai la température, | + | Maintenant, j'ai la température, |
**lcd.setCursor(0, | **lcd.setCursor(0, | ||
Ligne 119: | Ligne 119: | ||
Relais statique | Relais statique | ||
- | Disons d' | + | Disons d' |
- | Avant de couper le câble de ma chère couverture chauffante, je veux être sûr que le circuit fonctionne. Aussi, à la place, je vais tailler dans une lampe de bureau inutilisée. | + | Avant de couper le câble de ma chère couverture chauffante, je veux être sûr que le circuit fonctionne. Aussi, à la place, je vais sacrifier |
- | Après l' | + | Après l' |
**The solid state relay (SSR for short) has two DC inputs (in the photo, at the bottom left, is the red +5v and blue ground). It also has (depending on your SSR) one or more channels. My SSR has two channels. This is where your Arduino (yellow wire in the photo) will tell the SSR to go HIGH or LOW. The final two inputs are for the cable you wish to open/close. In this case the live (top wires in the photo) from my lamp. Now, it didn’t help that my inputs are labelled wrongly. The one marked ‘Ch1’ is actually for SSR channel two. So if you try this and it doesn’t work, try switching your wire from Ch1 to Ch2. You should see a light come on on the SSR to show which channel is HIGH/LOW. | **The solid state relay (SSR for short) has two DC inputs (in the photo, at the bottom left, is the red +5v and blue ground). It also has (depending on your SSR) one or more channels. My SSR has two channels. This is where your Arduino (yellow wire in the photo) will tell the SSR to go HIGH or LOW. The final two inputs are for the cable you wish to open/close. In this case the live (top wires in the photo) from my lamp. Now, it didn’t help that my inputs are labelled wrongly. The one marked ‘Ch1’ is actually for SSR channel two. So if you try this and it doesn’t work, try switching your wire from Ch1 to Ch2. You should see a light come on on the SSR to show which channel is HIGH/LOW. | ||
Ligne 139: | Ligne 139: | ||
const long interval= 1000;** | const long interval= 1000;** | ||
- | Le relais statique (RS pour faire court) a deux entrées en courant continu (sur la photo, en bas à gauche, le +5V est rouge et la masse bleue). Il comporte aussi (suivant votre RS) plusieurs canaux. Le mien en a deux. C'est par ici que votre Arduino (fil jaune sur la photo) alimentera ou non votre RS. Les deux dernières entrées sont pour le câble que vous souhaitez ouvrir/ | + | Le relais statique (RS pour faire court) a deux entrées en courant continu (sur la photo, en bas à gauche, le +5V est rouge et la masse bleue). Il comporte aussi (suivant votre RS) un ou plusieurs canaux. Le mien en a deux. C'est par ici que votre Arduino (fil jaune sur la photo) alimentera ou non votre RS. Les deux dernières entrées sont pour le câble que vous souhaitez ouvrir/ |
- | Une fois tout ceci en place, | + | Une fois tout ceci en place, le moment |
Pour tester le RS, je vais faire clignoter la lampe. Les premières nouvelles lignes de code sont : | Pour tester le RS, je vais faire clignoter la lampe. Les premières nouvelles lignes de code sont : | ||
Ligne 167: | Ligne 167: | ||
as this will be used in the if/then to switch on/off the lamp.** | as this will be used in the if/then to switch on/off the lamp.** | ||
- | Ceci définit le picot 53 de l' | + | Ceci définit le picot 53 de l' |
+ | |||
+ | Je commence avec l' | ||
+ | |||
+ | pinMode(ssr1, | ||
+ | |||
+ | digitalWrite(ssr1, | ||
+ | |||
+ | Dans le paramétrage, | ||
+ | |||
+ | unsigned long currentMillis = millis(); | ||
+ | |||
+ | car il sera utilisé dans la boucle si/alors pour commuter la lampe. | ||
**The only other additional code of note is the switching (top right). CurrentMillis and previousMillis will keep track of how many milliseconds the loop is running for. When it reaches the interval (set up at the start) then the loop ends. Note that this means the code never grinds to a halt like it would with a delay. I can still put stuff to do inside that HIGH/LOW if statement. | **The only other additional code of note is the switching (top right). CurrentMillis and previousMillis will keep track of how many milliseconds the loop is running for. When it reaches the interval (set up at the start) then the loop ends. Note that this means the code never grinds to a halt like it would with a delay. I can still put stuff to do inside that HIGH/LOW if statement. | ||
Ligne 178: | Ligne 190: | ||
With the interval set at 1000 this means the lamp will turn on/off every second.** | With the interval set at 1000 this means the lamp will turn on/off every second.** | ||
+ | |||
+ | La seule addition notable de code est la commutation (en haut à droite). CurrentMillis et PreviousMillis conservent les durées en millisecondes de parcours de la boucle. Quand « interval » est atteint (fixé au début), | ||
+ | |||
+ | Le if/else intérieur contrôle juste l' | ||
+ | • si l' | ||
+ | • si l' | ||
+ | |||
+ | Et, enfin, exécute le Allumé/ | ||
+ | |||
+ | Avec un intervalle réglé à 1000, ça signifie que la lampe va clignoter chaque seconde. | ||
**The only downside of removing the delays is that I’m now hammering ThingSpeak every minute or less, but I’ll fix that later. It’s working. That’s the main thing! | **The only downside of removing the delays is that I’m now hammering ThingSpeak every minute or less, but I’ll fix that later. It’s working. That’s the main thing! | ||
Ligne 195: | Ligne 217: | ||
If the temperature goes above 24, the lamp comes on. If the temperature falls below 24, the lamp goes off.** | If the temperature goes above 24, the lamp comes on. If the temperature falls below 24, the lamp goes off.** | ||
+ | Le seul inconvénient de retirer les délais est que je vais maintenant solliciter ThingSpeak toutes les minutes ou moins, mais je le réglerai plus tard. Ça marche. C'est le principal ! | ||
+ | Le code correspondant est un gist sur mon Github à : https:// | ||
+ | |||
+ | Pour surveiller une température particulière, | ||
+ | |||
+ | if (DHT.temperature > 24 ) { | ||
+ | state=LOW; | ||
+ | } | ||
+ | |||
+ | if (DHT.temperature < 24) { | ||
+ | state=HIGH; | ||
+ | } | ||
+ | |||
+ | Si la température dépasse 24 °C, la lampe s' | ||
Ligne 206: | Ligne 242: | ||
You may need to allow for that event in your code, otherwise, your code will stop working when it occurs. For example. if a “long” is 4 bytes, and if the time unit is actual millisecs, then this code will fail after 49 days operation (at most!).** | You may need to allow for that event in your code, otherwise, your code will stop working when it occurs. For example. if a “long” is 4 bytes, and if the time unit is actual millisecs, then this code will fail after 49 days operation (at most!).** | ||
+ | |||
+ | Notes de Mike K., ingénieur qualifié en électricité (vrai !) et dont un oncle a été électrocuté : | ||
+ | |||
+ | Ronnie écrit : écoutez ce gars. Il en connaît beaucoup plus que moi ! | ||
+ | |||
+ | Dépassement de la temporisation : dans le monde réel, vous ne devriez pas avoir besoin de déterminer la valeur maximale de la variable « currentMillis » parce que, tôt ou tard, elle sera remise à zéro. | ||
+ | |||
+ | Vous pourriez avoir besoin de prévoir cet événement dans votre code ; autrement, votre code s' | ||
**Temperature triggers: In the real world, your temp sensor might be “noisy”, | **Temperature triggers: In the real world, your temp sensor might be “noisy”, | ||
Ligne 212: | Ligne 256: | ||
• If the new temperature is at/above the upper value, and the Device_State is currently ON, then set it OFF, and set Device_State to OFF. | • If the new temperature is at/above the upper value, and the Device_State is currently ON, then set it OFF, and set Device_State to OFF. | ||
• If we can read the current state of the device, then the above “Device_State” variable is not needed. And, reverse the above references to ON/OFF, if appropriate.** | • If we can read the current state of the device, then the above “Device_State” variable is not needed. And, reverse the above references to ON/OFF, if appropriate.** | ||
+ | |||
+ | Seuils de température : dans le monde réel, votre détecteur de température pourrait être « bruité » et, dans ce cas, quand la température est « autour de 24 », la lecture pourrait tourner autour de 23/24/25, avec de nombreux changements. Si ça arrive, le code pourrait devenir fou, commutant le relais à toute vitesse. Pour éviter cela, on peut utiliser deux seuils, juste en dehors de cette zone perturbée ; peut-être 22 et 26 degrés. L' | ||
+ | • Dans le code d' | ||
+ | • Si la nouvelle température est à la valeur basse (ou en-dessous), | ||
+ | • Si la nouvelle température est à la valeur haute (ou au-dessus), et que l' | ||
+ | • Si vous pouvez lire l' | ||
**Wiring: When cutting the mains cable, strip back the outer insulation very slowly and carefully, and do not damage or cut into the wires which are not used by the relay circuit. If there is an earth cable, and if there is an earthing connector in the SSR circuit, then, do not cut the earth cable, but strip about 1-2 cm of it, fold it, and insert it into the earth connector. | **Wiring: When cutting the mains cable, strip back the outer insulation very slowly and carefully, and do not damage or cut into the wires which are not used by the relay circuit. If there is an earth cable, and if there is an earthing connector in the SSR circuit, then, do not cut the earth cable, but strip about 1-2 cm of it, fold it, and insert it into the earth connector. | ||
- | For safety, the SSR circuit must be enclosed in a suitable protective box. If the relays get hot when being used, then ensure there is adequate ventilation in the box, and ensure the box is not placed on soft surfaces such as carpets, duvets, etc - which would inhibit ventilation. | + | For safety, the SSR circuit must be enclosed in a suitable protective box. If the relays get hot when being used, then ensure there is adequate ventilation in the box, and ensure the box is not placed on soft surfaces such as carpets, duvets, etc - which would inhibit ventilation.** |
- | A user might install two relays - one on the positive and one on the negative lines. If a single relay is used - as in this project - it must be connected into the LIVE wire, so that, when the device (lamp, etc) is " | + | Câblage : Quand vous coupez les câbles d' |
- | **Rating of Relays: Ensure that the relay can easily handle the mains voltage (110V AC or 240V AC), and the maximum current that will be used by the devices. For example, a light bulb might use 1.0 Amp current, whereas an electric room heater might use 20+ Amps. | + | Par sécurité, le circuit du RS doit être placé dans une enveloppe protectrice adaptée. Si les relais deviennent chauds à l' |
+ | |||
+ | **A user might install two relays - one on the positive and one on the negative lines. If a single relay is used - as in this project - it must be connected into the LIVE wire, so that, when the device (lamp, etc) is " | ||
+ | |||
+ | Rating of Relays: Ensure that the relay can easily handle the mains voltage (110V AC or 240V AC), and the maximum current that will be used by the devices. For example, a light bulb might use 1.0 Amp current, whereas an electric room heater might use 20+ Amps. | ||
Overall, we should expect that Arduino fans might have kits in their bedrooms, and might decide to control the mains heating, lighting, ventilation, | Overall, we should expect that Arduino fans might have kits in their bedrooms, and might decide to control the mains heating, lighting, ventilation, | ||
+ | |||
+ | L' | ||
+ | |||
+ | Caractéristiques du relais : Assurez-vous que le relais peut facilement supporter la tension secteur (110 V AC ou 240 V AC), ainsi que la courant maximal absorbé par les appareils. Par exemple, une lampe à incandescence pourrait absorber 1 A, alors qu'un radiateur électrique pourrait utiliser 20 A ou plus. | ||
+ | |||
+ | En général, vous pouvez vous attendre à ce que des fans d' |
issue107/arduino.1459926347.txt.gz · Dernière modification : 2016/04/06 09:05 de d52fr