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/05 19:53] – 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 | + | 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 8: | ||
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, | ||
+ | |||
+ | Ces nouveaux écrans LCD sont I2C ce qui signifie qu'ils ont une petite carte de pilotage au dos. Cela signifie aussi qu'ils ont besoin d'une nouvelle bibliothèque (https:// | ||
+ | |||
+ | Avant d' | ||
**LCD Code | **LCD Code | ||
Ligne 33: | Ligne 38: | ||
In my setup, I initialise the screen as 16X2, turn on the backlight, print a message, and use a delay to allow it to be read.** | In my setup, I initialise the screen as 16X2, turn on the backlight, print a message, and use a delay to allow it to be read.** | ||
+ | |||
+ | Code LCD | ||
+ | |||
+ | J'ai besoin d' | ||
+ | |||
+ | #include < | ||
+ | |||
+ | Définissez plusieurs picots (des éléments I2C que vous n' | ||
+ | |||
+ | #define I2C_ADDR | ||
+ | < | ||
+ | |||
+ | #define BACKLIGHT_PIN | ||
+ | #define En_pin | ||
+ | #define Rw_pin | ||
+ | #define Rs_pin | ||
+ | #define D4_pin | ||
+ | #define D5_pin | ||
+ | #define D6_pin | ||
+ | #define D7_pin | ||
+ | |||
+ | LiquidCrystal_I2C | ||
+ | |||
+ | Dans mon paramétrage, | ||
**lcd.begin (16, | **lcd.begin (16, | ||
Ligne 48: | Ligne 77: | ||
I now have my temperature, | I now have my temperature, | ||
+ | |||
+ | lcd.begin (16, | ||
+ | lcd.setBacklightPin(BACKLIGHT_PIN, | ||
+ | |||
+ | lcd.setBacklight(HIGH); | ||
+ | |||
+ | lcd.home(); | ||
+ | |||
+ | lcd.print(" | ||
+ | |||
+ | delay(2000); | ||
+ | |||
+ | La plupart de ces commandes sont explicites. | ||
+ | |||
+ | Maintenant, j'ai la température, | ||
**lcd.setCursor(0, | **lcd.setCursor(0, | ||
Ligne 56: | Ligne 100: | ||
NOTE: if you don’t see anything on your screen on first run, try turning the potentiometer on the back of the LCD screen to adjust the brightness of the screen.** | NOTE: if you don’t see anything on your screen on first run, try turning the potentiometer on the back of the LCD screen to adjust the brightness of the screen.** | ||
+ | |||
+ | lcd.setCursor(0, | ||
+ | |||
+ | lcd.print(" | ||
+ | |||
+ | lcd.setCursor() sert à positionner le texte à un endroit précis de l' | ||
+ | |||
+ | NOTE : si, au premier démarrage, vous ne voyez rien sur votre écran, essayez de tourner le potentiomètre au dos de l' | ||
**Solid State Relay | **Solid State Relay | ||
Ligne 64: | Ligne 116: | ||
With it unplugged, I chopped through the cable and paired off the two inner cables (live and neutral). I then twisted the two live cables together and left the two neutral cables detached. I also put some electrical tape over that twist to cover it up and keep things somewhat safe.** | With it unplugged, I chopped through the cable and paired off the two inner cables (live and neutral). I then twisted the two live cables together and left the two neutral cables detached. I also put some electrical tape over that twist to cover it up and keep things somewhat safe.** | ||
+ | |||
+ | Relais statique | ||
+ | |||
+ | 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 sacrifier une lampe de bureau inutilisée. | ||
+ | |||
+ | 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 78: | Ligne 138: | ||
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) 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, le moment est venu d' | ||
+ | |||
+ | Pour tester le RS, je vais faire clignoter la lampe. Les premières nouvelles lignes de code sont : | ||
+ | |||
+ | #define ssr1 53 | ||
+ | |||
+ | int state = LOW; | ||
+ | |||
+ | unsigned long previousMillis= 0; | ||
+ | |||
+ | const long interval= 1000; | ||
**This defines pin 53 on the Arduino as the control pin for the SSR. The state is to keep track of whether the lamp is currently on/off. The previousMillis and interval are for the flash. I’m going to try and use millis rather than delays as millis is more preferable to the program halting delay command. | **This defines pin 53 on the Arduino as the control pin for the SSR. The state is to keep track of whether the lamp is currently on/off. The previousMillis and interval are for the flash. I’m going to try and use millis rather than delays as millis is more preferable to the program halting delay command. | ||
Ligne 92: | Ligne 166: | ||
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' | ||
+ | |||
+ | 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 102: | 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 119: | 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 130: | 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 136: | 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.1459878784.txt.gz · Dernière modification : 2016/04/05 19:53 de d52fr