{"id":3476,"date":"2020-04-25T12:45:49","date_gmt":"2020-04-25T10:45:49","guid":{"rendered":"http:\/\/www.ardpylab.fr\/?page_id=3476"},"modified":"2020-05-10T18:03:26","modified_gmt":"2020-05-10T16:03:26","slug":"projet-3-activite-2","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=3476","title":{"rendered":"Projet 3 &#8211; Activit\u00e9 2"},"content":{"rendered":"\n<h2 style=\"text-align: center;\"><strong><em>\u201dAlarme sonore par d\u00e9tection de passage<\/em><\/strong><strong><em>\u201d<u><\/u><\/em><\/strong><\/h2>\n<p>&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3576 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-circuit6.png\" alt=\"\" width=\"521\" height=\"342\"><\/figure>\n<\/div>\n\n\n\n<h4>&nbsp;<\/h4>\n<h4><strong><span style=\"color: #3366ff;\"><br>.&nbsp;<span style=\"text-decoration: underline;\">Objectif<\/span><\/span><\/strong><\/h4>\n<p><br>Dans cette activit\u00e9, le programme de production d&rsquo;un \u00ab\u00a0beep\u00a0\u00bb de l&rsquo;activit\u00e9 pr\u00e9c\u00e9dente va \u00eatre utilis\u00e9 comme alarme de d\u00e9tection de passage.<\/p>\n<p>On utilise pour cela une photor\u00e9sistance \u00e9clair\u00e9e par une DEL rouge (voir <a href=\"https:\/\/www.ardpylab.fr\/?page_id=460\/#anc1\" data-wplink-url-error=\"true\">le principe de fonctionnement d&rsquo;une photor\u00e9sistance<\/a>). La sortie de la photor\u00e9sistance est connect\u00e9e \u00e0 l&rsquo;entr\u00e9e analogique <strong>A0<\/strong> de l&rsquo;Arduino.<\/p>\n<p>La valeur de la broche <strong>A0 <\/strong>est alors proportionnelle \u00e0 l&rsquo;intensit\u00e9 lumineuse re\u00e7ue par la photor\u00e9sistance.<\/p>\n<p>En pr\u00e9sence d&rsquo;un obstacle entre la DEL et la photor\u00e9sistance, la tension mesur\u00e9e au niveau de la broche A0 diminue et quand celle-ci est inf\u00e9rieure \u00e0 un seuil (la sensibilit\u00e9 du capteur d\u00e9finie initialement), l&rsquo;alarme sonore est d\u00e9clench\u00e9e.<br><br><\/p>\n<p>Le code en Python ou en langage Arduino pourra \u00eatre modifi\u00e9 pour voir l\u2019influence des variables (sensibilit\u00e9 du capteur, fr\u00e9quence de l\u2019onde sonore, dur\u00e9e d\u2019\u00e9mission, dur\u00e9e de silence).<\/p>\n<p>&nbsp;<\/p>\n<h4><strong><span style=\"color: #3366ff;\">.&nbsp;<span style=\"text-decoration: underline;\">Le programme<br><br><\/span><\/span><\/strong><\/h4>\n\n\n\n<h4><strong><span style=\"color: #0000ff;\"><span style=\"color: #000000;\"><a id=\"prog1\"><\/a>. <\/span><span style=\"color: #000000;\">Programme en Python<\/span> <span style=\"color: #000000;\">(\u201d<\/span><a href=\"https:\/\/www.ardpylab.fr\/downloads\/projetspython\/projet3\/projet3-activity2.zip\" data-wplink-url-error=\"true\">Projet3\/Activity2\/PY\/Activity2.py<\/a><span style=\"color: #000000;\">\u201d)<br \/><br \/><\/span><\/span><\/strong><\/h4>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/projetspython\/projet3\/Activity2\/PY\/Activity2.py\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"901\" height=\"1025\" class=\"wp-image-3479 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-1.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-1.png 901w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-1-264x300.png 264w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-1-768x874.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><\/a><\/figure>\n<\/div>\n\n\n\n<p><strong><u><br>D\u00e9roulement du programme<\/u><\/strong><strong>&nbsp;:<\/strong><\/p>\n<p>&#8211; <u>Importation des librairies&nbsp;et d\u00e9finition de fonctions<\/u> :<\/p>\n<p style=\"padding-left: 40px;\">. Le module <strong>\u201dConnectToArduino.py\u201d, <\/strong>contenant les fonctions de connexion \u00e0 l\u2019Arduino via le protocole <strong>\u201dFirmata Express\u201d<\/strong>,<\/p>\n<p style=\"padding-left: 40px;\">. Le module <strong>\u201d<\/strong><strong>PymataExpressDef.Py\u201d<\/strong> regroupant toutes les fonctions utiles \u00e0 l\u2019utilisation de <strong>\u201d<\/strong><strong>Pymata<\/strong><strong>-express\u201d<\/strong>&nbsp;(fonction de d\u00e9claration des entr\u00e9es et sorties, de lectures, d\u2019\u00e9critures\u2026) ,<\/p>\n<p style=\"padding-left: 40px;\">. La biblioth\u00e8que <strong>\u201d<\/strong><strong>time\u201d <\/strong>pour la gestion des temps de pause.<br><br><\/p>\n<p>&#8211; <u>D\u00e9claration des constantes et variables<\/u>&nbsp;:<\/p>\n<p style=\"padding-left: 40px;\">. <strong>PinLED = 4<\/strong> (constante correspondant au n\u00b0 de la broche sur laquelle la DEL rouge est connect\u00e9e)<\/p>\n<p style=\"padding-left: 40px;\"><strong>. PinTone = 3<\/strong> (constante correspondant au n\u00b0 de la broche sur laquelle le buzzer est connect\u00e9)<\/p>\n<p style=\"padding-left: 40px;\"><strong>. PinPhotoR = 0 <\/strong>(constante correspondant au n\u00b0 de la broche A0 de la photor\u00e9sistance)<\/p>\n<p style=\"padding-left: 40px;\"><strong>. CapteurSensib = 700 <\/strong>(constante nombre entier entre 0 et 1023 correspondant \u00e0 la valeur de la sensibilit\u00e9 du capteur)<\/p>\n<p style=\"padding-left: 40px;\"><strong>. ValCapteur = 0 <\/strong>(variable pour stocker la valeur de la broche de la photor\u00e9sistance)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>PortComArduino <\/strong>(port COM sur lequel l\u2019Arduino est connect\u00e9)<br><br><\/p>\n<p>&#8211; <u>Connexion \u00e0 l&rsquo;Arduino<\/u> :<\/p>\n<p style=\"padding-left: 40px;\">. D\u00e9tection du port COM, tentative d\u2019ouverture du port COM s\u00e9lectionn\u00e9 et connexion \u00e0 l\u2019Arduino:<\/p>\n<p style=\"padding-left: 80px;\"><strong>PortComArduino = SelectPortCOM()<\/strong><\/p>\n<p style=\"padding-left: 80px;\"><strong>board = OpenPortCom(PortComArduino)<br><br><\/strong><\/p>\n<p style=\"padding-left: 40px;\">. Si la connexion \u00e0 l\u2019Arduino est r\u00e9ussie :<\/p>\n<p style=\"padding-left: 80px;\">&#8211; D\u00e9claration de la broche du buzzer en mode \u201dTone\u201d&nbsp;:<\/p>\n<p style=\"padding-left: 120px;\"><strong>Set_Tone_Pin(board, PinTone)<\/strong><\/p>\n<p style=\"padding-left: 80px;\">&#8211; D\u00e9claration de la broche de la DEL en sortie digitale&nbsp;:<\/p>\n<p style=\"padding-left: 120px;\"><strong>Set_DigitalOutput_Pin(board, PinLED)<br><\/strong><\/p>\n<p style=\"padding-left: 80px;\">&#8211; D\u00e9claration de la broche de la photor\u00e9sistance en entr\u00e9e analogique&nbsp;:<\/p>\n<p style=\"padding-left: 120px;\"><strong>Set_AnalogInput_Pin(board, PinPhotoR)<\/strong><\/p>\n<p style=\"padding-left: 80px;\">&#8211; La DEL rouge est allum\u00e9e&nbsp;:<\/p>\n<p style=\"padding-left: 120px;\"><strong>Digital_Write(board, PinLED, 1)<br><br><\/strong><\/p>\n<p>&#8211; <u>Boucle principale du programme (boucle \u201d<\/u><u>while True\u201d<\/u><u>)<\/u> :<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"1024\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-907x1024.png\" alt=\"\" class=\"wp-image-3511\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-907x1024.png 907w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-266x300.png 266w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-768x867.png 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-1361x1536.png 1361w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-2-1-1815x2048.png 1815w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<h4>\u00a0<\/h4>\n<h4><strong><span style=\"color: #0000ff;\"><span style=\"color: #000000;\"><a id=\"prog2\"><\/a>. Programme en langage Arduino (\u201d<\/span><a href=\"https:\/\/www.ardpylab.fr\/downloads\/projetspython\/projet3\/projet3-activity2.zip\" data-wplink-url-error=\"true\">Projet3\/Activity2\/INO\/Activity2.ino<\/a><span style=\"color: #000000;\">\u201d<\/span><span style=\"color: #000000;\">)<\/span><\/span><\/strong><\/h4>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.ardpylab.fr\/downloads\/projetspython\/projet3\/Activity2\/INO\/Activity2\/Activity2.ino\" data-wplink-url-error=\"true\"><img loading=\"lazy\" decoding=\"async\" width=\"758\" height=\"718\" class=\"wp-image-3482 aligncenter\" style=\"border: 3px solid #eeeeee; padding: 3px; margin: 3px;\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-3.png\" alt=\"\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-3.png 758w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-3-300x284.png 300w\" sizes=\"auto, (max-width: 758px) 100vw, 758px\" \/><\/a><\/figure>\n<\/div>\n<p><strong><u>D\u00e9roulement du programme<\/u><\/strong><strong>\u00a0:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-745x1024.png\" alt=\"\" class=\"wp-image-3509\" width=\"818\" height=\"1124\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-745x1024.png 745w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-218x300.png 218w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-768x1056.png 768w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-1117x1536.png 1117w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1-1489x2048.png 1489w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/projet3-activity2-4-1.png 1541w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/figure>\n\n\n<div  class=\"grids-section grids-is-stretch\" style=\"--_gs-gap-desktop:0px 0px;--_gs-m-desktop:0 0 0 0;--_gs-p-desktop:0 0 0 0;--_gs-bg-desktop:transparent none;--_gs-bg-xp-desktop:0px;--_gs-zi-desktop:auto;--_gs-d-desktop:block;--_gs-mw-desktop:calc(100% - 0 - 0);--_gs-gap-tablet:0px 0px;--_gs-m-tablet:0 0 0 0;--_gs-p-tablet:0 0 0 0;--_gs-bg-tablet:transparent none;--_gs-bg-xp-tablet:0px;--_gs-zi-tablet:auto;--_gs-d-tablet:block;--_gs-mw-tablet:calc(100% - 0 - 0);--_gs-gap-mobile:0px 0px;--_gs-m-mobile:0 0 0 0;--_gs-p-mobile:0 0 0 0;--_gs-bg-mobile:transparent none;--_gs-bg-xp-mobile:0px;--_gs-zi-mobile:auto;--_gs-d-mobile:block;--_gs-mw-mobile:calc(100% - 0 - 0);--_gs-columns:2;--_gs-rows:1\"><div class=\"grids-s-w_i\">\n<div class=\"grids-area\" style=\"--_ga-column:1\/2;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=3434\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/moins.jpg\" alt=\"\" class=\"wp-image-107\"\/><\/a><\/figure><\/div>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:2\/3;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=3492\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/plus.jpg\" alt=\"\" class=\"wp-image-106\"\/><\/a><\/figure><\/div>\n\n<\/div>\n<\/div><\/div>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>\u201dAlarme sonore par d\u00e9tection de passage\u201d &nbsp; &nbsp; .&nbsp;Objectif Dans cette activit\u00e9, le programme de production d&rsquo;un \u00ab\u00a0beep\u00a0\u00bb de l&rsquo;activit\u00e9 pr\u00e9c\u00e9dente va \u00eatre utilis\u00e9 comme alarme de d\u00e9tection de passage. On utilise pour cela une photor\u00e9sistance \u00e9clair\u00e9e par une DEL rouge (voir le principe de fonctionnement d&rsquo;une photor\u00e9sistance). La sortie de la photor\u00e9sistance est connect\u00e9e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3476","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/3476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3476"}],"version-history":[{"count":0,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/3476\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}